@fixflow/sdk
v0.1.3
Published
FixFlow SDK for error capture
Readme
FixFlow SDK
Website: tryfixflow.com
Lightweight error capture SDK for Node.js and browser environments.
Install
npm install @fixflow/sdkProject Key
The PROJECT_KEY is a unique identifier that connects your application to your FixFlow project.
Where to find it:
- Sign in to your FixFlow Dashboard.
- Create a project (or select an existing one).
- (Optional) Connect your repository if you want FixFlow to scan your code for issues and security vulnerabilities.
- Your SDK Project Key is displayed in the project header and under the SDK Settings tab in Project Details.
Usage
import fixflow from "@fixflow/sdk";
fixflow.init("PROJECT_KEY");The SDK auto-captures uncaught errors and unhandled promise rejections after initialization.
Usage by environment
API request tracking: In Node.js, outbound HTTP monitoring uses Axios (trackAxios). In the browser you can use trackFetch, Axios, or both.
Browser / frontend
Initialize in your client entry file (for example main.ts or index.tsx) as early as possible so startup errors are captured:
import fixflow from "@fixflow/sdk";
fixflow.init("PROJECT_KEY", {
trackFetch: true, // optional: instruments window.fetch (browser only)
});Use captureError or capture in catch blocks for handled errors (see Capturing errors manually).
trackFetch instruments window.fetch only and does not patch Node’s global fetch. For all options, see init Options below.
React
Prefer calling init from your entry file before createRoot(...).render(...) when the project key is available there.
If the key only exists on the client (for example a NEXT_PUBLIC_* variable), use a once-only useEffect with an empty dependency array. Do not call init in the component render body:
import { useEffect } from "react";
import fixflow from "@fixflow/sdk";
export function FixFlowInit() {
useEffect(() => {
const key = process.env.NEXT_PUBLIC_FIXFLOW_PROJECT_KEY;
if (key) {
fixflow.init(key, { trackFetch: true });
}
}, []);
return null;
}Mount that component once near the root of your tree. Next.js App Router users can wrap it in a small client component used from the root layout.
React Native
Call init at the very top of your entry file (usually App.js or index.js) before your component definition to capture startup errors:
import fixflow from "@fixflow/sdk";
fixflow.init("PROJECT_KEY");Node.js
Call init once at process startup (for example at the top of server.ts, before creating or listening on your HTTP server):
import axios from "axios";
import fixflow from "@fixflow/sdk";
fixflow.init("PROJECT_KEY", {
trackAxios: true,
axios,
slowThreshold: 1000,
});Do not rely on trackFetch for Node in the current SDK; use trackAxios and pass the same axios instance your app uses. See Axios option (important).
init Options
Typical setup combines browser trackFetch with server Axios tracking and passes your app's Axios instance when you use Axios on the server:
import axios from "axios";
import fixflow from "@fixflow/sdk";
fixflow.init("PROJECT_KEY", {
trackFetch: true,
trackAxios: true,
slowThreshold: 1000,
axios,
});| Option | Type | Default | Description |
| --- | --- | --- | --- |
| trackFetch | boolean | false | Enables API tracking for window.fetch (browser). |
| trackAxios | boolean | false | Enables API tracking for Axios via interceptors. |
| slowThreshold | number | 1000 | Request duration threshold in ms used for "slow API" events. Values below 0 are clamped to 0. |
| axios | AxiosStatic | undefined | Axios instance to instrument. Recommended for Node apps when trackAxios is enabled. |
At init, the SDK requests GET …/sdk/config/:projectKey on the same API host as ingest (for the default cloud URL, that is https://api.fixflow.ai/sdk/config/:projectKey). It applies apiTrackingEnabled and trackInDevelopment from the project when the response is valid, and otherwise falls back to your trackFetch / trackAxios flags.
Axios option (important)
In Node/npm projects, @fixflow/sdk can have a different installed Axios copy than your app.
If that happens, interceptors attached by the SDK will not see requests made by your app's Axios import.
Pass your app's Axios instance so API events are tracked from the client your code actually uses:
import axios from "axios";
import fixflow from "@fixflow/sdk";
fixflow.init("PROJECT_KEY", {
trackAxios: true,
axios,
});Capturing errors manually
try {
throw new Error("Something failed");
} catch (err) {
fixflow.captureError(err as Error);
}You can also call the async capture method directly:
import fixflow from "@fixflow/sdk";
await fixflow.capture(new Error("Manual capture"));