usetraceforge 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/express.d.ts CHANGED
@@ -3,4 +3,4 @@ import { Request, Response, NextFunction } from "express";
3
3
  * Express middleware to catch unhandled errors and report them to TraceForge.
4
4
  * Ensure this is added AFTER all your routes and controllers, but BEFORE your custom error handler.
5
5
  */
6
- export declare const TraceForgeErrorHandler: (error: Error, req: Request, res: Response, next: NextFunction) => void;
6
+ export declare const expressErrorHandler: () => (error: Error, req: Request, res: Response, next: NextFunction) => void;
package/dist/express.js CHANGED
@@ -3,25 +3,27 @@ import TraceForge from "./index.js";
3
3
  * Express middleware to catch unhandled errors and report them to TraceForge.
4
4
  * Ensure this is added AFTER all your routes and controllers, but BEFORE your custom error handler.
5
5
  */
6
- export const TraceForgeErrorHandler = (error, req, res, next) => {
7
- TraceForge.captureException(error, {
8
- environment: "node",
9
- tags: {
10
- method: req.method,
11
- url: req.url,
12
- path: req.path,
13
- ip: req.ip || "Unknown"
14
- },
15
- payload: {
16
- query: req.query,
17
- body: req.body,
18
- headers: {
19
- ...req.headers,
20
- authorization: req.headers.authorization ? "[REDACTED]" : undefined,
21
- cookie: req.headers.cookie ? "[REDACTED]" : undefined
6
+ export const expressErrorHandler = () => {
7
+ return (error, req, res, next) => {
8
+ TraceForge.captureException(error, {
9
+ environment: "node",
10
+ tags: {
11
+ method: req.method,
12
+ url: req.url,
13
+ path: req.path,
14
+ ip: req.ip || "Unknown"
15
+ },
16
+ payload: {
17
+ query: req.query,
18
+ body: req.body,
19
+ headers: {
20
+ ...req.headers,
21
+ authorization: req.headers.authorization ? "[REDACTED]" : undefined,
22
+ cookie: req.headers.cookie ? "[REDACTED]" : undefined
23
+ }
22
24
  }
23
- }
24
- }).catch(() => undefined);
25
- // Pass the error to the next error handler
26
- next(error);
25
+ }).catch(() => undefined);
26
+ // Pass the error to the next error handler
27
+ next(error);
28
+ };
27
29
  };
package/dist/index.js CHANGED
@@ -121,6 +121,9 @@ const setupAutoCapture = () => {
121
121
  };
122
122
  const TraceForge = {
123
123
  init: (options) => {
124
+ if (!options.apiKey) {
125
+ throw new Error("TraceForge.init() failed: Missing API Key.");
126
+ }
124
127
  const previousApiKey = config?.apiKey ?? null;
125
128
  const previousEndpoint = config?.endpoint ?? defaultEndpoint;
126
129
  config = {
package/dist/next.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function withTraceForge(handler: Function): (...args: any[]) => Promise<any>;
1
+ export declare function withTraceForgeRoute(handler: Function): (...args: any[]) => Promise<any>;
package/dist/next.js CHANGED
@@ -1,14 +1,26 @@
1
1
  import TraceForge from "./index.js";
2
2
  // A wrapper for Next.js API Routes (App Router or Pages Router)
3
- export function withTraceForge(handler) {
3
+ export function withTraceForgeRoute(handler) {
4
4
  return async function (...args) {
5
+ // Auto-initialize TraceForge in this isolated runtime if it hasn't been initialized
6
+ try {
7
+ if (process.env.NEXT_PUBLIC_TRACEFORGE_API_KEY) {
8
+ TraceForge.init({
9
+ apiKey: process.env.NEXT_PUBLIC_TRACEFORGE_API_KEY,
10
+ endpoint: process.env.NEXT_PUBLIC_TRACEFORGE_INGEST_URL,
11
+ });
12
+ }
13
+ }
14
+ catch (e) {
15
+ // Ignore init errors here, it will fail gracefully during capture if truly unconfigured
16
+ }
5
17
  try {
6
18
  return await handler(...args);
7
19
  }
8
20
  catch (error) {
9
21
  // Catch Next.js serverless API errors
10
22
  await TraceForge.captureException(error, {
11
- environment: "node",
23
+ environment: process.env.NODE_ENV || "node",
12
24
  tags: {
13
25
  runtime: "nextjs-api"
14
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usetraceforge",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "private": false,
5
5
  "description": "TraceForge JavaScript SDK for sending errors to a TraceForge ingest endpoint.",
6
6
  "type": "module",