5xx-sdk 1.0.0 → 1.1.0
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/{chunk-MOWJJPVU.mjs → chunk-JCBAF7DF.mjs} +44 -1
- package/dist/chunk-JCBAF7DF.mjs.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/node.d.mts +17 -0
- package/dist/node.d.ts +17 -0
- package/dist/node.js +43 -0
- package/dist/node.js.map +1 -1
- package/dist/node.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-MOWJJPVU.mjs.map +0 -1
|
@@ -64,9 +64,52 @@ var FiveXXNode = class extends FiveXX {
|
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Wrap an HTTP route handler to automatically capture errors.
|
|
69
|
+
* Works with Next.js, Express, Fastify, and any framework.
|
|
70
|
+
* Captures the error with request metadata, then re-throws
|
|
71
|
+
* so the framework's own error handling still works.
|
|
72
|
+
*
|
|
73
|
+
* Usage (Next.js):
|
|
74
|
+
* export const GET = fivexx.wrapHandler(async (req) => {
|
|
75
|
+
* return NextResponse.json(data);
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* Usage (Express):
|
|
79
|
+
* app.get('/api', fivexx.wrapHandler(async (req, res) => {
|
|
80
|
+
* res.json(data);
|
|
81
|
+
* }));
|
|
82
|
+
*/
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
84
|
+
wrapHandler(fn) {
|
|
85
|
+
const self = this;
|
|
86
|
+
return (async function(...args) {
|
|
87
|
+
try {
|
|
88
|
+
return await fn(...args);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
const metadata = {
|
|
91
|
+
type: "handlerError",
|
|
92
|
+
nodeVersion: process.version,
|
|
93
|
+
platform: process.platform,
|
|
94
|
+
pid: process.pid
|
|
95
|
+
};
|
|
96
|
+
const req = args[0];
|
|
97
|
+
if (req && typeof req === "object") {
|
|
98
|
+
if ("url" in req) metadata.url = String(req.url);
|
|
99
|
+
if ("method" in req) metadata.method = String(req.method);
|
|
100
|
+
}
|
|
101
|
+
if (error instanceof Error) {
|
|
102
|
+
await self.captureError(error, metadata);
|
|
103
|
+
} else {
|
|
104
|
+
await self.captureMessage(String(error), metadata);
|
|
105
|
+
}
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
67
110
|
};
|
|
68
111
|
|
|
69
112
|
export {
|
|
70
113
|
FiveXXNode
|
|
71
114
|
};
|
|
72
|
-
//# sourceMappingURL=chunk-
|
|
115
|
+
//# sourceMappingURL=chunk-JCBAF7DF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/node.ts"],"sourcesContent":["import { FiveXX } from \"./client\";\nimport type { FiveXXOptions } from \"./types\";\n\ninterface NodeOptions extends FiveXXOptions {\n exitOnFatalError?: boolean;\n}\n\n/**\n * Node.js-specific FiveXX client with automatic error capture\n */\nexport class FiveXXNode extends FiveXX {\n private autoCapture = false;\n private exitOnFatalError: boolean;\n\n constructor(options: NodeOptions) {\n super(options);\n this.exitOnFatalError = options.exitOnFatalError ?? true;\n\n // Auto-detect environment from NODE_ENV\n if (!options.environment && process.env.NODE_ENV) {\n this.setEnvironment(process.env.NODE_ENV);\n }\n }\n\n /**\n * Enable automatic capture of uncaught exceptions and unhandled rejections\n */\n enableAutoCapture(): void {\n if (this.autoCapture) return;\n\n this.autoCapture = true;\n\n // Capture uncaught exceptions\n process.on(\"uncaughtException\", async (error) => {\n console.error(\"5xx: Uncaught exception:\", error);\n await this.captureError(error, {\n type: \"uncaughtException\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n\n if (this.exitOnFatalError) {\n process.exit(1);\n }\n });\n\n // Capture unhandled promise rejections\n process.on(\"unhandledRejection\", async (reason) => {\n console.error(\"5xx: Unhandled rejection:\", reason);\n if (reason instanceof Error) {\n await this.captureError(reason, {\n type: \"unhandledRejection\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n } else {\n await this.captureMessage(String(reason), {\n type: \"unhandledRejection\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n }\n });\n }\n\n /**\n * Wrap an async function to capture errors\n */\n wrapAsync<T extends (...args: unknown[]) => Promise<unknown>>(\n fn: T,\n metadata?: Record<string, unknown>\n ): T {\n return (async (...args: Parameters<T>) => {\n try {\n return await fn(...args);\n } catch (error) {\n if (error instanceof Error) {\n await this.captureError(error, metadata);\n }\n throw error;\n }\n }) as T;\n }\n\n /**\n * Wrap an HTTP route handler to automatically capture errors.\n * Works with Next.js, Express, Fastify, and any framework.\n * Captures the error with request metadata, then re-throws\n * so the framework's own error handling still works.\n *\n * Usage (Next.js):\n * export const GET = fivexx.wrapHandler(async (req) => {\n * return NextResponse.json(data);\n * });\n *\n * Usage (Express):\n * app.get('/api', fivexx.wrapHandler(async (req, res) => {\n * res.json(data);\n * }));\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wrapHandler<T extends (...args: any[]) => Promise<any>>(fn: T): T {\n const self = this;\n return (async function (...args: Parameters<T>) {\n try {\n return await fn(...args);\n } catch (error) {\n const metadata: Record<string, unknown> = {\n type: \"handlerError\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n };\n\n // Extract request info from first argument (works with Next.js Request, Express req, etc.)\n const req = args[0];\n if (req && typeof req === \"object\") {\n if (\"url\" in req) metadata.url = String(req.url);\n if (\"method\" in req) metadata.method = String(req.method);\n }\n\n if (error instanceof Error) {\n await self.captureError(error, metadata);\n } else {\n await self.captureMessage(String(error), metadata);\n }\n throw error;\n }\n }) as T;\n }\n}\n"],"mappings":";;;;;AAUO,IAAM,aAAN,cAAyB,OAAO;AAAA,EAIrC,YAAY,SAAsB;AAChC,UAAM,OAAO;AAJf,SAAQ,cAAc;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AAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,YAAwD,IAAU;AAChE,UAAM,OAAO;AACb,YAAQ,kBAAmB,MAAqB;AAC9C,UAAI;AACF,eAAO,MAAM,GAAG,GAAG,IAAI;AAAA,MACzB,SAAS,OAAO;AACd,cAAM,WAAoC;AAAA,UACxC,MAAM;AAAA,UACN,aAAa,QAAQ;AAAA,UACrB,UAAU,QAAQ;AAAA,UAClB,KAAK,QAAQ;AAAA,QACf;AAGA,cAAM,MAAM,KAAK,CAAC;AAClB,YAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,cAAI,SAAS,IAAK,UAAS,MAAM,OAAO,IAAI,GAAG;AAC/C,cAAI,YAAY,IAAK,UAAS,SAAS,OAAO,IAAI,MAAM;AAAA,QAC1D;AAEA,YAAI,iBAAiB,OAAO;AAC1B,gBAAM,KAAK,aAAa,OAAO,QAAQ;AAAA,QACzC,OAAO;AACL,gBAAM,KAAK,eAAe,OAAO,KAAK,GAAG,QAAQ;AAAA,QACnD;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -239,6 +239,49 @@ var FiveXXNode = class extends FiveXX {
|
|
|
239
239
|
}
|
|
240
240
|
});
|
|
241
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Wrap an HTTP route handler to automatically capture errors.
|
|
244
|
+
* Works with Next.js, Express, Fastify, and any framework.
|
|
245
|
+
* Captures the error with request metadata, then re-throws
|
|
246
|
+
* so the framework's own error handling still works.
|
|
247
|
+
*
|
|
248
|
+
* Usage (Next.js):
|
|
249
|
+
* export const GET = fivexx.wrapHandler(async (req) => {
|
|
250
|
+
* return NextResponse.json(data);
|
|
251
|
+
* });
|
|
252
|
+
*
|
|
253
|
+
* Usage (Express):
|
|
254
|
+
* app.get('/api', fivexx.wrapHandler(async (req, res) => {
|
|
255
|
+
* res.json(data);
|
|
256
|
+
* }));
|
|
257
|
+
*/
|
|
258
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
259
|
+
wrapHandler(fn) {
|
|
260
|
+
const self = this;
|
|
261
|
+
return (async function(...args) {
|
|
262
|
+
try {
|
|
263
|
+
return await fn(...args);
|
|
264
|
+
} catch (error) {
|
|
265
|
+
const metadata = {
|
|
266
|
+
type: "handlerError",
|
|
267
|
+
nodeVersion: process.version,
|
|
268
|
+
platform: process.platform,
|
|
269
|
+
pid: process.pid
|
|
270
|
+
};
|
|
271
|
+
const req = args[0];
|
|
272
|
+
if (req && typeof req === "object") {
|
|
273
|
+
if ("url" in req) metadata.url = String(req.url);
|
|
274
|
+
if ("method" in req) metadata.method = String(req.method);
|
|
275
|
+
}
|
|
276
|
+
if (error instanceof Error) {
|
|
277
|
+
await self.captureError(error, metadata);
|
|
278
|
+
} else {
|
|
279
|
+
await self.captureMessage(String(error), metadata);
|
|
280
|
+
}
|
|
281
|
+
throw error;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
242
285
|
};
|
|
243
286
|
// Annotate the CommonJS export names for ESM import in node:
|
|
244
287
|
0 && (module.exports = {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/browser.ts","../src/node.ts"],"sourcesContent":["export { FiveXX } from \"./client\";\nexport { FiveXXBrowser } from \"./browser\";\nexport { FiveXXNode } from \"./node\";\nexport type { FiveXXOptions, ErrorPayload, User } from \"./types\";\n","import type { FiveXXOptions, ErrorPayload, User } from \"./types\";\n\nexport class FiveXX {\n private apiKey: string;\n private endpoint: string;\n private environment: string;\n private user: User | null = null;\n\n constructor(options: FiveXXOptions) {\n this.apiKey = options.apiKey;\n this.endpoint = options.endpoint.replace(/\\/$/, \"\"); // Remove trailing slash\n this.environment = options.environment || \"production\";\n }\n\n /**\n * Set the environment (e.g., \"production\", \"development\", \"staging\")\n */\n setEnvironment(env: string): void {\n this.environment = env;\n }\n\n /**\n * Set user context for errors\n */\n setUser(user: User | null): void {\n this.user = user;\n }\n\n /**\n * Capture an error and send it to the 5xx server\n */\n async captureError(\n error: Error,\n metadata?: Record<string, unknown>\n ): Promise<string | null> {\n const payload: ErrorPayload = {\n message: error.message || String(error),\n stack: error.stack,\n environment: this.environment,\n metadata: {\n ...metadata,\n ...(this.user && { user: this.user }),\n },\n };\n\n return this.send(payload);\n }\n\n /**\n * Capture a message as an error\n */\n async captureMessage(\n message: string,\n metadata?: Record<string, unknown>\n ): Promise<string | null> {\n const payload: ErrorPayload = {\n message,\n environment: this.environment,\n metadata: {\n ...metadata,\n ...(this.user && { user: this.user }),\n },\n };\n\n return this.send(payload);\n }\n\n /**\n * Send error payload to the server\n */\n private async send(payload: ErrorPayload): Promise<string | null> {\n try {\n const response = await fetch(`${this.endpoint}/api/errors`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": this.apiKey,\n },\n body: JSON.stringify(payload),\n });\n\n if (!response.ok) {\n console.error(`5xx: Failed to send error (${response.status})`);\n return null;\n }\n\n const data = await response.json();\n return data.id;\n } catch (err) {\n console.error(\"5xx: Failed to send error\", err);\n return null;\n }\n }\n}\n","import { FiveXX } from \"./client\";\nimport type { FiveXXOptions } from \"./types\";\n\n/**\n * Browser-specific FiveXX client with automatic error capture\n */\nexport class FiveXXBrowser extends FiveXX {\n private autoCapture = false;\n private originalOnError: OnErrorEventHandler | null = null;\n private originalOnUnhandledRejection: ((event: PromiseRejectionEvent) => void) | null = null;\n\n constructor(options: FiveXXOptions) {\n super(options);\n\n // Auto-detect environment from URL\n if (typeof window !== \"undefined\" && !options.environment) {\n const hostname = window.location.hostname;\n if (hostname === \"localhost\" || hostname === \"127.0.0.1\") {\n this.setEnvironment(\"development\");\n }\n }\n }\n\n /**\n * Enable automatic capture of unhandled errors and promise rejections\n */\n enableAutoCapture(): void {\n if (this.autoCapture || typeof window === \"undefined\") return;\n\n this.autoCapture = true;\n\n // Capture unhandled errors\n this.originalOnError = window.onerror;\n window.onerror = (message, source, lineno, colno, error) => {\n if (error) {\n this.captureError(error, {\n source,\n lineno,\n colno,\n url: window.location.href,\n userAgent: navigator.userAgent,\n });\n } else {\n this.captureMessage(String(message), {\n source,\n lineno,\n colno,\n url: window.location.href,\n userAgent: navigator.userAgent,\n });\n }\n\n // Call original handler if it exists\n if (this.originalOnError) {\n return this.originalOnError(message, source, lineno, colno, error);\n }\n return false;\n };\n\n // Capture unhandled promise rejections\n this.originalOnUnhandledRejection = window.onunhandledrejection;\n window.onunhandledrejection = (event) => {\n const error = event.reason;\n if (error instanceof Error) {\n this.captureError(error, {\n type: \"unhandledRejection\",\n url: window.location.href,\n userAgent: navigator.userAgent,\n });\n } else {\n this.captureMessage(String(error), {\n type: \"unhandledRejection\",\n url: window.location.href,\n userAgent: navigator.userAgent,\n });\n }\n\n if (this.originalOnUnhandledRejection) {\n this.originalOnUnhandledRejection(event);\n }\n };\n }\n\n /**\n * Disable automatic capture\n */\n disableAutoCapture(): void {\n if (!this.autoCapture || typeof window === \"undefined\") return;\n\n this.autoCapture = false;\n window.onerror = this.originalOnError;\n window.onunhandledrejection = this.originalOnUnhandledRejection;\n }\n}\n","import { FiveXX } from \"./client\";\nimport type { FiveXXOptions } from \"./types\";\n\ninterface NodeOptions extends FiveXXOptions {\n exitOnFatalError?: boolean;\n}\n\n/**\n * Node.js-specific FiveXX client with automatic error capture\n */\nexport class FiveXXNode extends FiveXX {\n private autoCapture = false;\n private exitOnFatalError: boolean;\n\n constructor(options: NodeOptions) {\n super(options);\n this.exitOnFatalError = options.exitOnFatalError ?? true;\n\n // Auto-detect environment from NODE_ENV\n if (!options.environment && process.env.NODE_ENV) {\n this.setEnvironment(process.env.NODE_ENV);\n }\n }\n\n /**\n * Enable automatic capture of uncaught exceptions and unhandled rejections\n */\n enableAutoCapture(): void {\n if (this.autoCapture) return;\n\n this.autoCapture = true;\n\n // Capture uncaught exceptions\n process.on(\"uncaughtException\", async (error) => {\n console.error(\"5xx: Uncaught exception:\", error);\n await this.captureError(error, {\n type: \"uncaughtException\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n\n if (this.exitOnFatalError) {\n process.exit(1);\n }\n });\n\n // Capture unhandled promise rejections\n process.on(\"unhandledRejection\", async (reason) => {\n console.error(\"5xx: Unhandled rejection:\", reason);\n if (reason instanceof Error) {\n await this.captureError(reason, {\n type: \"unhandledRejection\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n } else {\n await this.captureMessage(String(reason), {\n type: \"unhandledRejection\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n }\n });\n }\n\n /**\n * Wrap an async function to capture errors\n */\n wrapAsync<T extends (...args: unknown[]) => Promise<unknown>>(\n fn: T,\n metadata?: Record<string, unknown>\n ): T {\n return (async (...args: Parameters<T>) => {\n try {\n return await fn(...args);\n } catch (error) {\n if (error instanceof Error) {\n await this.captureError(error, metadata);\n }\n throw error;\n }\n }) as T;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,SAAN,MAAa;AAAA,EAMlB,YAAY,SAAwB;AAFpC,SAAQ,OAAoB;AAG1B,SAAK,SAAS,QAAQ;AACtB,SAAK,WAAW,QAAQ,SAAS,QAAQ,OAAO,EAAE;AAClD,SAAK,cAAc,QAAQ,eAAe;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,eAAe,KAAmB;AAChC,SAAK,cAAc;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ,MAAyB;AAC/B,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aACJ,OACA,UACwB;AACxB,UAAM,UAAwB;AAAA,MAC5B,SAAS,MAAM,WAAW,OAAO,KAAK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wB;AACxC,UAAI;AACF,eAAO,MAAM,GAAG,GAAG,IAAI;AAAA,MACzB,SAAS,OAAO;AACd,YAAI,iBAAiB,OAAO;AAC1B,gBAAM,KAAK,aAAa,OAAO,QAAQ;AAAA,QACzC;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/browser.ts","../src/node.ts"],"sourcesContent":["export { FiveXX } from \"./client\";\nexport { FiveXXBrowser } from \"./browser\";\nexport { FiveXXNode } from \"./node\";\nexport type { FiveXXOptions, ErrorPayload, User } from \"./types\";\n","import type { FiveXXOptions, ErrorPayload, User } from \"./types\";\n\nexport class FiveXX {\n private apiKey: string;\n private endpoint: string;\n private environment: string;\n private user: User | null = null;\n\n constructor(options: FiveXXOptions) {\n this.apiKey = options.apiKey;\n this.endpoint = options.endpoint.replace(/\\/$/, \"\"); // Remove trailing slash\n this.environment = options.environment || \"production\";\n }\n\n /**\n * Set the environment (e.g., \"production\", \"development\", \"staging\")\n */\n setEnvironment(env: string): void {\n this.environment = env;\n }\n\n /**\n * Set user context for errors\n */\n setUser(user: User | null): void {\n this.user = user;\n }\n\n /**\n * Capture an error and send it to the 5xx server\n */\n async captureError(\n error: Error,\n metadata?: Record<string, unknown>\n ): Promise<string | null> {\n const payload: ErrorPayload = {\n message: error.message || String(error),\n stack: error.stack,\n environment: this.environment,\n metadata: {\n ...metadata,\n ...(this.user && { user: this.user }),\n },\n };\n\n return this.send(payload);\n }\n\n /**\n * Capture a message as an error\n */\n async captureMessage(\n message: string,\n metadata?: Record<string, unknown>\n ): Promise<string | null> {\n const payload: ErrorPayload = {\n message,\n environment: this.environment,\n metadata: {\n ...metadata,\n ...(this.user && { user: this.user }),\n },\n };\n\n return this.send(payload);\n }\n\n /**\n * Send error payload to the server\n */\n private async send(payload: ErrorPayload): Promise<string | null> {\n try {\n const response = await fetch(`${this.endpoint}/api/errors`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": this.apiKey,\n },\n body: JSON.stringify(payload),\n });\n\n if (!response.ok) {\n console.error(`5xx: Failed to send error (${response.status})`);\n return null;\n }\n\n const data = await response.json();\n return data.id;\n } catch (err) {\n console.error(\"5xx: Failed to send error\", err);\n return null;\n }\n }\n}\n","import { FiveXX } from \"./client\";\nimport type { FiveXXOptions } from \"./types\";\n\n/**\n * Browser-specific FiveXX client with automatic error capture\n */\nexport class FiveXXBrowser extends FiveXX {\n private autoCapture = false;\n private originalOnError: OnErrorEventHandler | null = null;\n private originalOnUnhandledRejection: ((event: PromiseRejectionEvent) => void) | null = null;\n\n constructor(options: FiveXXOptions) {\n super(options);\n\n // Auto-detect environment from URL\n if (typeof window !== \"undefined\" && !options.environment) {\n const hostname = window.location.hostname;\n if (hostname === \"localhost\" || hostname === \"127.0.0.1\") {\n this.setEnvironment(\"development\");\n }\n }\n }\n\n /**\n * Enable automatic capture of unhandled errors and promise rejections\n */\n enableAutoCapture(): void {\n if (this.autoCapture || typeof window === \"undefined\") return;\n\n this.autoCapture = true;\n\n // Capture unhandled errors\n this.originalOnError = window.onerror;\n window.onerror = (message, source, lineno, colno, error) => {\n if (error) {\n this.captureError(error, {\n source,\n lineno,\n colno,\n url: window.location.href,\n userAgent: navigator.userAgent,\n });\n } else {\n this.captureMessage(String(message), {\n source,\n lineno,\n colno,\n url: window.location.href,\n userAgent: navigator.userAgent,\n });\n }\n\n // Call original handler if it exists\n if (this.originalOnError) {\n return this.originalOnError(message, source, lineno, colno, error);\n }\n return false;\n };\n\n // Capture unhandled promise rejections\n this.originalOnUnhandledRejection = window.onunhandledrejection;\n window.onunhandledrejection = (event) => {\n const error = event.reason;\n if (error instanceof Error) {\n this.captureError(error, {\n type: \"unhandledRejection\",\n url: window.location.href,\n userAgent: navigator.userAgent,\n });\n } else {\n this.captureMessage(String(error), {\n type: \"unhandledRejection\",\n url: window.location.href,\n userAgent: navigator.userAgent,\n });\n }\n\n if (this.originalOnUnhandledRejection) {\n this.originalOnUnhandledRejection(event);\n }\n };\n }\n\n /**\n * Disable automatic capture\n */\n disableAutoCapture(): void {\n if (!this.autoCapture || typeof window === \"undefined\") return;\n\n this.autoCapture = false;\n window.onerror = this.originalOnError;\n window.onunhandledrejection = this.originalOnUnhandledRejection;\n }\n}\n","import { FiveXX } from \"./client\";\nimport type { FiveXXOptions } from \"./types\";\n\ninterface NodeOptions extends FiveXXOptions {\n exitOnFatalError?: boolean;\n}\n\n/**\n * Node.js-specific FiveXX client with automatic error capture\n */\nexport class FiveXXNode extends FiveXX {\n private autoCapture = false;\n private exitOnFatalError: boolean;\n\n constructor(options: NodeOptions) {\n super(options);\n this.exitOnFatalError = options.exitOnFatalError ?? true;\n\n // Auto-detect environment from NODE_ENV\n if (!options.environment && process.env.NODE_ENV) {\n this.setEnvironment(process.env.NODE_ENV);\n }\n }\n\n /**\n * Enable automatic capture of uncaught exceptions and unhandled rejections\n */\n enableAutoCapture(): void {\n if (this.autoCapture) return;\n\n this.autoCapture = true;\n\n // Capture uncaught exceptions\n process.on(\"uncaughtException\", async (error) => {\n console.error(\"5xx: Uncaught exception:\", error);\n await this.captureError(error, {\n type: \"uncaughtException\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n\n if (this.exitOnFatalError) {\n process.exit(1);\n }\n });\n\n // Capture unhandled promise rejections\n process.on(\"unhandledRejection\", async (reason) => {\n console.error(\"5xx: Unhandled rejection:\", reason);\n if (reason instanceof Error) {\n await this.captureError(reason, {\n type: \"unhandledRejection\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n } else {\n await this.captureMessage(String(reason), {\n type: \"unhandledRejection\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n }\n });\n }\n\n /**\n * Wrap an async function to capture errors\n */\n wrapAsync<T extends (...args: unknown[]) => Promise<unknown>>(\n fn: T,\n metadata?: Record<string, unknown>\n ): T {\n return (async (...args: Parameters<T>) => {\n try {\n return await fn(...args);\n } catch (error) {\n if (error instanceof Error) {\n await this.captureError(error, metadata);\n }\n throw error;\n }\n }) as T;\n }\n\n /**\n * Wrap an HTTP route handler to automatically capture errors.\n * Works with Next.js, Express, Fastify, and any framework.\n * Captures the error with request metadata, then re-throws\n * so the framework's own error handling still works.\n *\n * Usage (Next.js):\n * export const GET = fivexx.wrapHandler(async (req) => {\n * return NextResponse.json(data);\n * });\n *\n * Usage (Express):\n * app.get('/api', fivexx.wrapHandler(async (req, res) => {\n * res.json(data);\n * }));\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wrapHandler<T extends (...args: any[]) => Promise<any>>(fn: T): T {\n const self = this;\n return (async function (...args: Parameters<T>) {\n try {\n return await fn(...args);\n } catch (error) {\n const metadata: Record<string, unknown> = {\n type: \"handlerError\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n };\n\n // Extract request info from first argument (works with Next.js Request, Express req, etc.)\n const req = args[0];\n if (req && typeof req === \"object\") {\n if (\"url\" in req) metadata.url = String(req.url);\n if (\"method\" in req) metadata.method = String(req.method);\n }\n\n if (error instanceof Error) {\n await self.captureError(error, metadata);\n } else {\n await self.captureMessage(String(error), metadata);\n }\n throw error;\n }\n }) as T;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,SAAN,MAAa;AAAA,EAMlB,YAAY,SAAwB;AAFpC,SAAQ,OAAoB;AAG1B,SAAK,SAAS,QAAQ;AACtB,SAAK,WAAW,QAAQ,SAAS,QAAQ,OAAO,EAAE;AAClD,SAAK,cAAc,QAAQ,eAAe;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,eAAe,KAAmB;AAChC,SAAK,cAAc;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ,MAAyB;AAC/B,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,MAA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AC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,UACE,IACA,UACG;AACH,YAAQ,UAAU,SAAwB;AACxC,UAAI;AACF,eAAO,MAAM,GAAG,GAAG,IAAI;AAAA,MACzB,SAAS,OAAO;AACd,YAAI,iBAAiB,OAAO;AAC1B,gBAAM,KAAK,aAAa,OAAO,QAAQ;AAAA,QACzC;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,YAAwD,IAAU;AAChE,UAAM,OAAO;AACb,YAAQ,kBAAmB,MAAqB;AAC9C,UAAI;AACF,eAAO,MAAM,GAAG,GAAG,IAAI;AAAA,MACzB,SAAS,OAAO;AACd,cAAM,WAAoC;AAAA,UACxC,MAAM;AAAA,UACN,aAAa,QAAQ;AAAA,UACrB,UAAU,QAAQ;AAAA,UAClB,KAAK,QAAQ;AAAA,QACf;AAGA,cAAM,MAAM,KAAK,CAAC;AAClB,YAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,cAAI,SAAS,IAAK,UAAS,MAAM,OAAO,IAAI,GAAG;AAC/C,cAAI,YAAY,IAAK,UAAS,SAAS,OAAO,IAAI,MAAM;AAAA,QAC1D;AAEA,YAAI,iBAAiB,OAAO;AAC1B,gBAAM,KAAK,aAAa,OAAO,QAAQ;AAAA,QACzC,OAAO;AACL,gBAAM,KAAK,eAAe,OAAO,KAAK,GAAG,QAAQ;AAAA,QACnD;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
package/dist/node.d.mts
CHANGED
|
@@ -18,6 +18,23 @@ declare class FiveXXNode extends FiveXX {
|
|
|
18
18
|
* Wrap an async function to capture errors
|
|
19
19
|
*/
|
|
20
20
|
wrapAsync<T extends (...args: unknown[]) => Promise<unknown>>(fn: T, metadata?: Record<string, unknown>): T;
|
|
21
|
+
/**
|
|
22
|
+
* Wrap an HTTP route handler to automatically capture errors.
|
|
23
|
+
* Works with Next.js, Express, Fastify, and any framework.
|
|
24
|
+
* Captures the error with request metadata, then re-throws
|
|
25
|
+
* so the framework's own error handling still works.
|
|
26
|
+
*
|
|
27
|
+
* Usage (Next.js):
|
|
28
|
+
* export const GET = fivexx.wrapHandler(async (req) => {
|
|
29
|
+
* return NextResponse.json(data);
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* Usage (Express):
|
|
33
|
+
* app.get('/api', fivexx.wrapHandler(async (req, res) => {
|
|
34
|
+
* res.json(data);
|
|
35
|
+
* }));
|
|
36
|
+
*/
|
|
37
|
+
wrapHandler<T extends (...args: any[]) => Promise<any>>(fn: T): T;
|
|
21
38
|
}
|
|
22
39
|
|
|
23
40
|
export { FiveXXNode };
|
package/dist/node.d.ts
CHANGED
|
@@ -18,6 +18,23 @@ declare class FiveXXNode extends FiveXX {
|
|
|
18
18
|
* Wrap an async function to capture errors
|
|
19
19
|
*/
|
|
20
20
|
wrapAsync<T extends (...args: unknown[]) => Promise<unknown>>(fn: T, metadata?: Record<string, unknown>): T;
|
|
21
|
+
/**
|
|
22
|
+
* Wrap an HTTP route handler to automatically capture errors.
|
|
23
|
+
* Works with Next.js, Express, Fastify, and any framework.
|
|
24
|
+
* Captures the error with request metadata, then re-throws
|
|
25
|
+
* so the framework's own error handling still works.
|
|
26
|
+
*
|
|
27
|
+
* Usage (Next.js):
|
|
28
|
+
* export const GET = fivexx.wrapHandler(async (req) => {
|
|
29
|
+
* return NextResponse.json(data);
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* Usage (Express):
|
|
33
|
+
* app.get('/api', fivexx.wrapHandler(async (req, res) => {
|
|
34
|
+
* res.json(data);
|
|
35
|
+
* }));
|
|
36
|
+
*/
|
|
37
|
+
wrapHandler<T extends (...args: any[]) => Promise<any>>(fn: T): T;
|
|
21
38
|
}
|
|
22
39
|
|
|
23
40
|
export { FiveXXNode };
|
package/dist/node.js
CHANGED
|
@@ -161,6 +161,49 @@ var FiveXXNode = class extends FiveXX {
|
|
|
161
161
|
}
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Wrap an HTTP route handler to automatically capture errors.
|
|
166
|
+
* Works with Next.js, Express, Fastify, and any framework.
|
|
167
|
+
* Captures the error with request metadata, then re-throws
|
|
168
|
+
* so the framework's own error handling still works.
|
|
169
|
+
*
|
|
170
|
+
* Usage (Next.js):
|
|
171
|
+
* export const GET = fivexx.wrapHandler(async (req) => {
|
|
172
|
+
* return NextResponse.json(data);
|
|
173
|
+
* });
|
|
174
|
+
*
|
|
175
|
+
* Usage (Express):
|
|
176
|
+
* app.get('/api', fivexx.wrapHandler(async (req, res) => {
|
|
177
|
+
* res.json(data);
|
|
178
|
+
* }));
|
|
179
|
+
*/
|
|
180
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
181
|
+
wrapHandler(fn) {
|
|
182
|
+
const self = this;
|
|
183
|
+
return (async function(...args) {
|
|
184
|
+
try {
|
|
185
|
+
return await fn(...args);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
const metadata = {
|
|
188
|
+
type: "handlerError",
|
|
189
|
+
nodeVersion: process.version,
|
|
190
|
+
platform: process.platform,
|
|
191
|
+
pid: process.pid
|
|
192
|
+
};
|
|
193
|
+
const req = args[0];
|
|
194
|
+
if (req && typeof req === "object") {
|
|
195
|
+
if ("url" in req) metadata.url = String(req.url);
|
|
196
|
+
if ("method" in req) metadata.method = String(req.method);
|
|
197
|
+
}
|
|
198
|
+
if (error instanceof Error) {
|
|
199
|
+
await self.captureError(error, metadata);
|
|
200
|
+
} else {
|
|
201
|
+
await self.captureMessage(String(error), metadata);
|
|
202
|
+
}
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
164
207
|
};
|
|
165
208
|
// Annotate the CommonJS export names for ESM import in node:
|
|
166
209
|
0 && (module.exports = {
|
package/dist/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/node.ts","../src/client.ts"],"sourcesContent":["import { FiveXX } from \"./client\";\nimport type { FiveXXOptions } from \"./types\";\n\ninterface NodeOptions extends FiveXXOptions {\n exitOnFatalError?: boolean;\n}\n\n/**\n * Node.js-specific FiveXX client with automatic error capture\n */\nexport class FiveXXNode extends FiveXX {\n private autoCapture = false;\n private exitOnFatalError: boolean;\n\n constructor(options: NodeOptions) {\n super(options);\n this.exitOnFatalError = options.exitOnFatalError ?? true;\n\n // Auto-detect environment from NODE_ENV\n if (!options.environment && process.env.NODE_ENV) {\n this.setEnvironment(process.env.NODE_ENV);\n }\n }\n\n /**\n * Enable automatic capture of uncaught exceptions and unhandled rejections\n */\n enableAutoCapture(): void {\n if (this.autoCapture) return;\n\n this.autoCapture = true;\n\n // Capture uncaught exceptions\n process.on(\"uncaughtException\", async (error) => {\n console.error(\"5xx: Uncaught exception:\", error);\n await this.captureError(error, {\n type: \"uncaughtException\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n\n if (this.exitOnFatalError) {\n process.exit(1);\n }\n });\n\n // Capture unhandled promise rejections\n process.on(\"unhandledRejection\", async (reason) => {\n console.error(\"5xx: Unhandled rejection:\", reason);\n if (reason instanceof Error) {\n await this.captureError(reason, {\n type: \"unhandledRejection\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n } else {\n await this.captureMessage(String(reason), {\n type: \"unhandledRejection\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n }\n });\n }\n\n /**\n * Wrap an async function to capture errors\n */\n wrapAsync<T extends (...args: unknown[]) => Promise<unknown>>(\n fn: T,\n metadata?: Record<string, unknown>\n ): T {\n return (async (...args: Parameters<T>) => {\n try {\n return await fn(...args);\n } catch (error) {\n if (error instanceof Error) {\n await this.captureError(error, metadata);\n }\n throw error;\n }\n }) as T;\n }\n}\n","import type { FiveXXOptions, ErrorPayload, User } from \"./types\";\n\nexport class FiveXX {\n private apiKey: string;\n private endpoint: string;\n private environment: string;\n private user: User | null = null;\n\n constructor(options: FiveXXOptions) {\n this.apiKey = options.apiKey;\n this.endpoint = options.endpoint.replace(/\\/$/, \"\"); // Remove trailing slash\n this.environment = options.environment || \"production\";\n }\n\n /**\n * Set the environment (e.g., \"production\", \"development\", \"staging\")\n */\n setEnvironment(env: string): void {\n this.environment = env;\n }\n\n /**\n * Set user context for errors\n */\n setUser(user: User | null): void {\n this.user = user;\n }\n\n /**\n * Capture an error and send it to the 5xx server\n */\n async captureError(\n error: Error,\n metadata?: Record<string, unknown>\n ): Promise<string | null> {\n const payload: ErrorPayload = {\n message: error.message || String(error),\n stack: error.stack,\n environment: this.environment,\n metadata: {\n ...metadata,\n ...(this.user && { user: this.user }),\n },\n };\n\n return this.send(payload);\n }\n\n /**\n * Capture a message as an error\n */\n async captureMessage(\n message: string,\n metadata?: Record<string, unknown>\n ): Promise<string | null> {\n const payload: ErrorPayload = {\n message,\n environment: this.environment,\n metadata: {\n ...metadata,\n ...(this.user && { user: this.user }),\n },\n };\n\n return this.send(payload);\n }\n\n /**\n * Send error payload to the server\n */\n private async send(payload: ErrorPayload): Promise<string | null> {\n try {\n const response = await fetch(`${this.endpoint}/api/errors`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": this.apiKey,\n },\n body: JSON.stringify(payload),\n });\n\n if (!response.ok) {\n console.error(`5xx: Failed to send error (${response.status})`);\n return null;\n }\n\n const data = await response.json();\n return data.id;\n } catch (err) {\n console.error(\"5xx: Failed to send error\", err);\n return null;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,SAAN,MAAa;AAAA,EAMlB,YAAY,SAAwB;AAFpC,SAAQ,OAAoB;AAG1B,SAAK,SAAS,QAAQ;AACtB,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,UAAU,SAAwB;AACxC,UAAI;AACF,eAAO,MAAM,GAAG,GAAG,IAAI;AAAA,MACzB,SAAS,OAAO;AACd,YAAI,iBAAiB,OAAO;AAC1B,gBAAM,KAAK,aAAa,OAAO,QAAQ;AAAA,QACzC;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/node.ts","../src/client.ts"],"sourcesContent":["import { FiveXX } from \"./client\";\nimport type { FiveXXOptions } from \"./types\";\n\ninterface NodeOptions extends FiveXXOptions {\n exitOnFatalError?: boolean;\n}\n\n/**\n * Node.js-specific FiveXX client with automatic error capture\n */\nexport class FiveXXNode extends FiveXX {\n private autoCapture = false;\n private exitOnFatalError: boolean;\n\n constructor(options: NodeOptions) {\n super(options);\n this.exitOnFatalError = options.exitOnFatalError ?? true;\n\n // Auto-detect environment from NODE_ENV\n if (!options.environment && process.env.NODE_ENV) {\n this.setEnvironment(process.env.NODE_ENV);\n }\n }\n\n /**\n * Enable automatic capture of uncaught exceptions and unhandled rejections\n */\n enableAutoCapture(): void {\n if (this.autoCapture) return;\n\n this.autoCapture = true;\n\n // Capture uncaught exceptions\n process.on(\"uncaughtException\", async (error) => {\n console.error(\"5xx: Uncaught exception:\", error);\n await this.captureError(error, {\n type: \"uncaughtException\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n\n if (this.exitOnFatalError) {\n process.exit(1);\n }\n });\n\n // Capture unhandled promise rejections\n process.on(\"unhandledRejection\", async (reason) => {\n console.error(\"5xx: Unhandled rejection:\", reason);\n if (reason instanceof Error) {\n await this.captureError(reason, {\n type: \"unhandledRejection\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n } else {\n await this.captureMessage(String(reason), {\n type: \"unhandledRejection\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n }\n });\n }\n\n /**\n * Wrap an async function to capture errors\n */\n wrapAsync<T extends (...args: unknown[]) => Promise<unknown>>(\n fn: T,\n metadata?: Record<string, unknown>\n ): T {\n return (async (...args: Parameters<T>) => {\n try {\n return await fn(...args);\n } catch (error) {\n if (error instanceof Error) {\n await this.captureError(error, metadata);\n }\n throw error;\n }\n }) as T;\n }\n\n /**\n * Wrap an HTTP route handler to automatically capture errors.\n * Works with Next.js, Express, Fastify, and any framework.\n * Captures the error with request metadata, then re-throws\n * so the framework's own error handling still works.\n *\n * Usage (Next.js):\n * export const GET = fivexx.wrapHandler(async (req) => {\n * return NextResponse.json(data);\n * });\n *\n * Usage (Express):\n * app.get('/api', fivexx.wrapHandler(async (req, res) => {\n * res.json(data);\n * }));\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n wrapHandler<T extends (...args: any[]) => Promise<any>>(fn: T): T {\n const self = this;\n return (async function (...args: Parameters<T>) {\n try {\n return await fn(...args);\n } catch (error) {\n const metadata: Record<string, unknown> = {\n type: \"handlerError\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n };\n\n // Extract request info from first argument (works with Next.js Request, Express req, etc.)\n const req = args[0];\n if (req && typeof req === \"object\") {\n if (\"url\" in req) metadata.url = String(req.url);\n if (\"method\" in req) metadata.method = String(req.method);\n }\n\n if (error instanceof Error) {\n await self.captureError(error, metadata);\n } else {\n await self.captureMessage(String(error), metadata);\n }\n throw error;\n }\n }) as T;\n }\n}\n","import type { FiveXXOptions, ErrorPayload, User } from \"./types\";\n\nexport class FiveXX {\n private apiKey: string;\n private endpoint: string;\n private environment: string;\n private user: User | null = null;\n\n constructor(options: FiveXXOptions) {\n this.apiKey = options.apiKey;\n this.endpoint = options.endpoint.replace(/\\/$/, \"\"); // Remove trailing slash\n this.environment = options.environment || \"production\";\n }\n\n /**\n * Set the environment (e.g., \"production\", \"development\", \"staging\")\n */\n setEnvironment(env: string): void {\n this.environment = env;\n }\n\n /**\n * Set user context for errors\n */\n setUser(user: User | null): void {\n this.user = user;\n }\n\n /**\n * Capture an error and send it to the 5xx server\n */\n async captureError(\n error: Error,\n metadata?: Record<string, unknown>\n ): Promise<string | null> {\n const payload: ErrorPayload = {\n message: error.message || String(error),\n stack: error.stack,\n environment: this.environment,\n metadata: {\n ...metadata,\n ...(this.user && { user: this.user }),\n },\n };\n\n return this.send(payload);\n }\n\n /**\n * Capture a message as an error\n */\n async captureMessage(\n message: string,\n metadata?: Record<string, unknown>\n ): Promise<string | null> {\n const payload: ErrorPayload = {\n message,\n environment: this.environment,\n metadata: {\n ...metadata,\n ...(this.user && { user: this.user }),\n },\n };\n\n return this.send(payload);\n }\n\n /**\n * Send error payload to the server\n */\n private async send(payload: ErrorPayload): Promise<string | null> {\n try {\n const response = await fetch(`${this.endpoint}/api/errors`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": this.apiKey,\n },\n body: JSON.stringify(payload),\n });\n\n if (!response.ok) {\n console.error(`5xx: Failed to send error (${response.status})`);\n return null;\n }\n\n const data = await response.json();\n return data.id;\n } catch (err) {\n console.error(\"5xx: Failed to send error\", err);\n return null;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,SAAN,MAAa;AAAA,EAMlB,YAAY,SAAwB;AAFpC,SAAQ,OAAoB;AAG1B,SAAK,SAAS,QAAQ;AACtB,SAAK,WAAW,QAAQ,SAAS,QAAQ,OAAO,EAAE;AAClD,SAAK,cAAc,QAAQ,eAAe;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,eAAe,KAAmB;AAChC,SAAK,cAAc;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ,MAAyB;AAC/B,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aACJ,OACA,UACwB;AACxB,UAAM,UAAwB;AAAA,MAC5B,SAAS,MAAM,WAAW,OAAO,KAAK;AAAA,MACtC,OAAO,MAAM;AAAA,MACb,aAAa,KAAK;A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AAO,MAAM,GAAG,GAAG,IAAI;AAAA,MACzB,SAAS,OAAO;AACd,cAAM,WAAoC;AAAA,UACxC,MAAM;AAAA,UACN,aAAa,QAAQ;AAAA,UACrB,UAAU,QAAQ;AAAA,UAClB,KAAK,QAAQ;AAAA,QACf;AAGA,cAAM,MAAM,KAAK,CAAC;AAClB,YAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,cAAI,SAAS,IAAK,UAAS,MAAM,OAAO,IAAI,GAAG;AAC/C,cAAI,YAAY,IAAK,UAAS,SAAS,OAAO,IAAI,MAAM;AAAA,QAC1D;AAEA,YAAI,iBAAiB,OAAO;AAC1B,gBAAM,KAAK,aAAa,OAAO,QAAQ;AAAA,QACzC,OAAO;AACL,gBAAM,KAAK,eAAe,OAAO,KAAK,GAAG,QAAQ;AAAA,QACnD;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/node.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/node.ts"],"sourcesContent":["import { FiveXX } from \"./client\";\nimport type { FiveXXOptions } from \"./types\";\n\ninterface NodeOptions extends FiveXXOptions {\n exitOnFatalError?: boolean;\n}\n\n/**\n * Node.js-specific FiveXX client with automatic error capture\n */\nexport class FiveXXNode extends FiveXX {\n private autoCapture = false;\n private exitOnFatalError: boolean;\n\n constructor(options: NodeOptions) {\n super(options);\n this.exitOnFatalError = options.exitOnFatalError ?? true;\n\n // Auto-detect environment from NODE_ENV\n if (!options.environment && process.env.NODE_ENV) {\n this.setEnvironment(process.env.NODE_ENV);\n }\n }\n\n /**\n * Enable automatic capture of uncaught exceptions and unhandled rejections\n */\n enableAutoCapture(): void {\n if (this.autoCapture) return;\n\n this.autoCapture = true;\n\n // Capture uncaught exceptions\n process.on(\"uncaughtException\", async (error) => {\n console.error(\"5xx: Uncaught exception:\", error);\n await this.captureError(error, {\n type: \"uncaughtException\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n\n if (this.exitOnFatalError) {\n process.exit(1);\n }\n });\n\n // Capture unhandled promise rejections\n process.on(\"unhandledRejection\", async (reason) => {\n console.error(\"5xx: Unhandled rejection:\", reason);\n if (reason instanceof Error) {\n await this.captureError(reason, {\n type: \"unhandledRejection\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n } else {\n await this.captureMessage(String(reason), {\n type: \"unhandledRejection\",\n nodeVersion: process.version,\n platform: process.platform,\n pid: process.pid,\n });\n }\n });\n }\n\n /**\n * Wrap an async function to capture errors\n */\n wrapAsync<T extends (...args: unknown[]) => Promise<unknown>>(\n fn: T,\n metadata?: Record<string, unknown>\n ): T {\n return (async (...args: Parameters<T>) => {\n try {\n return await fn(...args);\n } catch (error) {\n if (error instanceof Error) {\n await this.captureError(error, metadata);\n }\n throw error;\n }\n }) as T;\n }\n}\n"],"mappings":";;;;;AAUO,IAAM,aAAN,cAAyB,OAAO;AAAA,EAIrC,YAAY,SAAsB;AAChC,UAAM,OAAO;AAJf,SAAQ,cAAc;AAKpB,SAAK,mBAAmB,QAAQ,oBAAoB;AAGpD,QAAI,CAAC,QAAQ,eAAe,QAAQ,IAAI,UAAU;AAChD,WAAK,eAAe,QAAQ,IAAI,QAAQ;AAAA,IAC1C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,oBAA0B;AACxB,QAAI,KAAK,YAAa;AAEtB,SAAK,cAAc;AAGnB,YAAQ,GAAG,qBAAqB,OAAO,UAAU;AAC/C,cAAQ,MAAM,4BAA4B,KAAK;AAC/C,YAAM,KAAK,aAAa,OAAO;AAAA,QAC7B,MAAM;AAAA,QACN,aAAa,QAAQ;AAAA,QACrB,UAAU,QAAQ;AAAA,QAClB,KAAK,QAAQ;AAAA,MACf,CAAC;AAED,UAAI,KAAK,kBAAkB;AACzB,gBAAQ,KAAK,CAAC;AAAA,MAChB;AAAA,IACF,CAAC;AAGD,YAAQ,GAAG,sBAAsB,OAA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