5xx-sdk 1.0.0 → 1.2.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/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  FiveXXBrowser
3
- } from "./chunk-LD3XNYST.mjs";
3
+ } from "./chunk-IAF5CKNL.mjs";
4
4
  import {
5
5
  FiveXXNode
6
- } from "./chunk-MOWJJPVU.mjs";
6
+ } from "./chunk-762E5RVI.mjs";
7
7
  import {
8
8
  FiveXX
9
- } from "./chunk-5YY5E33R.mjs";
9
+ } from "./chunk-G4LKAXG5.mjs";
10
10
  export {
11
11
  FiveXX,
12
12
  FiveXXBrowser,
package/dist/node.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { F as FiveXX, a as FiveXXOptions } from './client-BhKj28Zi.mjs';
1
+ import { F as FiveXX, b as FiveXXOptions } from './client-t5SsLKrz.mjs';
2
2
 
3
3
  interface NodeOptions extends FiveXXOptions {
4
4
  exitOnFatalError?: boolean;
@@ -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
@@ -1,4 +1,4 @@
1
- import { F as FiveXX, a as FiveXXOptions } from './client-BhKj28Zi.js';
1
+ import { F as FiveXX, b as FiveXXOptions } from './client-t5SsLKrz.js';
2
2
 
3
3
  interface NodeOptions extends FiveXXOptions {
4
4
  exitOnFatalError?: boolean;
@@ -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
@@ -32,6 +32,14 @@ var FiveXX = class {
32
32
  this.endpoint = options.endpoint.replace(/\/$/, "");
33
33
  this.environment = options.environment || "production";
34
34
  }
35
+ /** @internal */
36
+ getApiKey() {
37
+ return this.apiKey;
38
+ }
39
+ /** @internal */
40
+ getEndpoint() {
41
+ return this.endpoint;
42
+ }
35
43
  /**
36
44
  * Set the environment (e.g., "production", "development", "staging")
37
45
  */
@@ -161,6 +169,49 @@ var FiveXXNode = class extends FiveXX {
161
169
  }
162
170
  });
163
171
  }
172
+ /**
173
+ * Wrap an HTTP route handler to automatically capture errors.
174
+ * Works with Next.js, Express, Fastify, and any framework.
175
+ * Captures the error with request metadata, then re-throws
176
+ * so the framework's own error handling still works.
177
+ *
178
+ * Usage (Next.js):
179
+ * export const GET = fivexx.wrapHandler(async (req) => {
180
+ * return NextResponse.json(data);
181
+ * });
182
+ *
183
+ * Usage (Express):
184
+ * app.get('/api', fivexx.wrapHandler(async (req, res) => {
185
+ * res.json(data);
186
+ * }));
187
+ */
188
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
189
+ wrapHandler(fn) {
190
+ const self = this;
191
+ return (async function(...args) {
192
+ try {
193
+ return await fn(...args);
194
+ } catch (error) {
195
+ const metadata = {
196
+ type: "handlerError",
197
+ nodeVersion: process.version,
198
+ platform: process.platform,
199
+ pid: process.pid
200
+ };
201
+ const req = args[0];
202
+ if (req && typeof req === "object") {
203
+ if ("url" in req) metadata.url = String(req.url);
204
+ if ("method" in req) metadata.method = String(req.method);
205
+ }
206
+ if (error instanceof Error) {
207
+ await self.captureError(error, metadata);
208
+ } else {
209
+ await self.captureMessage(String(error), metadata);
210
+ }
211
+ throw error;
212
+ }
213
+ });
214
+ }
164
215
  };
165
216
  // Annotate the CommonJS export names for ESM import in node:
166
217
  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,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;AAAA,MAClB,UAAU;AAAA,QACR,GAAG;AAAA,QACH,GAAI,KAAK,QAAQ,EAAE,MAAM,KAAK,KAAK;AAAA,MACrC;AAAA,IACF;AAEA,WAAO,KAAK,KAAK,OAAO;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,eACJ,SACA,UACwB;AACxB,UAAM,UAAwB;AAAA,MAC5B;AAAA,MACA,aAAa,KAAK;AAAA,MAClB,UAAU;AAAA,QACR,GAAG;AAAA,QAC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MAChB;AAAA,IACF,CAAC;AAGD,YAAQ,GAAG,sBAAsB,OAAO,WAAW;AACjD,cAAQ,MAAM,6BAA6B,MAAM;AACjD,UAAI,kBAAkB,OAAO;AAC3B,cAAM,KAAK,aAAa,QAAQ;AAAA,UAC9B,MAAM;AAAA,UACN,aAAa,QAAQ;AAAA,UACrB,UAAU,QAAQ;AAAA,UAClB,KAAK,QAAQ;AAAA,QACf,CAAC;AAAA,MACH,OAAO;AACL,cAAM,KAAK,eAAe,OAAO,MAAM,GAAG;AAAA,UACxC,MAAM;AAAA,UACN,aAAa,QAAQ;AAAA,UACrB,UAAU,QAAQ;AAAA,UAClB,KAAK,QAAQ;AAAA,QACf,CAAC;AAAA,MACH;AAAA,IACF,CAAC;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;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 /** @internal */\n protected getApiKey(): string {\n return this.apiKey;\n }\n\n /** @internal */\n protected getEndpoint(): string {\n return this.endpoint;\n }\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(\"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,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
package/dist/node.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  FiveXXNode
3
- } from "./chunk-MOWJJPVU.mjs";
4
- import "./chunk-5YY5E33R.mjs";
3
+ } from "./chunk-762E5RVI.mjs";
4
+ import "./chunk-G4LKAXG5.mjs";
5
5
  export {
6
6
  FiveXXNode
7
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "5xx-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Lightweight error tracking SDK for JavaScript/TypeScript applications",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/client.ts"],"sourcesContent":["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":";AAEO,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;AAAA,MAClB,UAAU;AAAA,QACR,GAAG;AAAA,QACH,GAAI,KAAK,QAAQ,EAAE,MAAM,KAAK,KAAK;AAAA,MACrC;AAAA,IACF;AAEA,WAAO,KAAK,KAAK,OAAO;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,eACJ,SACA,UACwB;AACxB,UAAM,UAAwB;AAAA,MAC5B;AAAA,MACA,aAAa,KAAK;AAAA,MAClB,UAAU;AAAA,QACR,GAAG;AAAA,QACH,GAAI,KAAK,QAAQ,EAAE,MAAM,KAAK,KAAK;AAAA,MACrC;AAAA,IACF;AAEA,WAAO,KAAK,KAAK,OAAO;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAc,KAAK,SAA+C;AAChE,QAAI;AACF,YAAM,WAAW,MAAM,MAAM,GAAG,KAAK,QAAQ,eAAe;AAAA,QAC1D,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,gBAAgB;AAAA,UAChB,aAAa,KAAK;AAAA,QACpB;AAAA,QACA,MAAM,KAAK,UAAU,OAAO;AAAA,MAC9B,CAAC;AAED,UAAI,CAAC,SAAS,IAAI;AAChB,gBAAQ,MAAM,8BAA8B,SAAS,MAAM,GAAG;AAC9D,eAAO;AAAA,MACT;AAEA,YAAM,OAAO,MAAM,SAAS,KAAK;AACjC,aAAO,KAAK;AAAA,IACd,SAAS,KAAK;AACZ,cAAQ,MAAM,6BAA6B,GAAG;AAC9C,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
@@ -1,84 +0,0 @@
1
- import {
2
- FiveXX
3
- } from "./chunk-5YY5E33R.mjs";
4
-
5
- // src/browser.ts
6
- var FiveXXBrowser = class extends FiveXX {
7
- constructor(options) {
8
- super(options);
9
- this.autoCapture = false;
10
- this.originalOnError = null;
11
- this.originalOnUnhandledRejection = null;
12
- if (typeof window !== "undefined" && !options.environment) {
13
- const hostname = window.location.hostname;
14
- if (hostname === "localhost" || hostname === "127.0.0.1") {
15
- this.setEnvironment("development");
16
- }
17
- }
18
- }
19
- /**
20
- * Enable automatic capture of unhandled errors and promise rejections
21
- */
22
- enableAutoCapture() {
23
- if (this.autoCapture || typeof window === "undefined") return;
24
- this.autoCapture = true;
25
- this.originalOnError = window.onerror;
26
- window.onerror = (message, source, lineno, colno, error) => {
27
- if (error) {
28
- this.captureError(error, {
29
- source,
30
- lineno,
31
- colno,
32
- url: window.location.href,
33
- userAgent: navigator.userAgent
34
- });
35
- } else {
36
- this.captureMessage(String(message), {
37
- source,
38
- lineno,
39
- colno,
40
- url: window.location.href,
41
- userAgent: navigator.userAgent
42
- });
43
- }
44
- if (this.originalOnError) {
45
- return this.originalOnError(message, source, lineno, colno, error);
46
- }
47
- return false;
48
- };
49
- this.originalOnUnhandledRejection = window.onunhandledrejection;
50
- window.onunhandledrejection = (event) => {
51
- const error = event.reason;
52
- if (error instanceof Error) {
53
- this.captureError(error, {
54
- type: "unhandledRejection",
55
- url: window.location.href,
56
- userAgent: navigator.userAgent
57
- });
58
- } else {
59
- this.captureMessage(String(error), {
60
- type: "unhandledRejection",
61
- url: window.location.href,
62
- userAgent: navigator.userAgent
63
- });
64
- }
65
- if (this.originalOnUnhandledRejection) {
66
- this.originalOnUnhandledRejection(event);
67
- }
68
- };
69
- }
70
- /**
71
- * Disable automatic capture
72
- */
73
- disableAutoCapture() {
74
- if (!this.autoCapture || typeof window === "undefined") return;
75
- this.autoCapture = false;
76
- window.onerror = this.originalOnError;
77
- window.onunhandledrejection = this.originalOnUnhandledRejection;
78
- }
79
- };
80
-
81
- export {
82
- FiveXXBrowser
83
- };
84
- //# sourceMappingURL=chunk-LD3XNYST.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/browser.ts"],"sourcesContent":["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"],"mappings":";;;;;AAMO,IAAM,gBAAN,cAA4B,OAAO;AAAA,EAKxC,YAAY,SAAwB;AAClC,UAAM,OAAO;AALf,SAAQ,cAAc;AACtB,SAAQ,kBAA8C;AACtD,SAAQ,+BAAgF;AAMtF,QAAI,OAAO,WAAW,eAAe,CAAC,QAAQ,aAAa;AACzD,YAAM,WAAW,OAAO,SAAS;AACjC,UAAI,aAAa,eAAe,aAAa,aAAa;AACxD,aAAK,eAAe,aAAa;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,oBAA0B;AACxB,QAAI,KAAK,eAAe,OAAO,WAAW,YAAa;AAEvD,SAAK,cAAc;AAGnB,SAAK,kBAAkB,OAAO;AAC9B,WAAO,UAAU,CAAC,SAAS,QAAQ,QAAQ,OAAO,UAAU;AAC1D,UAAI,OAAO;AACT,aAAK,aAAa,OAAO;AAAA,UACvB;AAAA,UACA;AAAA,UACA;AAAA,UACA,KAAK,OAAO,SAAS;AAAA,UACrB,WAAW,UAAU;AAAA,QACvB,CAAC;AAAA,MACH,OAAO;AACL,aAAK,eAAe,OAAO,OAAO,GAAG;AAAA,UACnC;AAAA,UACA;AAAA,UACA;AAAA,UACA,KAAK,OAAO,SAAS;AAAA,UACrB,WAAW,UAAU;AAAA,QACvB,CAAC;AAAA,MACH;AAGA,UAAI,KAAK,iBAAiB;AACxB,eAAO,KAAK,gBAAgB,SAAS,QAAQ,QAAQ,OAAO,KAAK;AAAA,MACnE;AACA,aAAO;AAAA,IACT;AAGA,SAAK,+BAA+B,OAAO;AAC3C,WAAO,uBAAuB,CAAC,UAAU;AACvC,YAAM,QAAQ,MAAM;AACpB,UAAI,iBAAiB,OAAO;AAC1B,aAAK,aAAa,OAAO;AAAA,UACvB,MAAM;AAAA,UACN,KAAK,OAAO,SAAS;AAAA,UACrB,WAAW,UAAU;AAAA,QACvB,CAAC;AAAA,MACH,OAAO;AACL,aAAK,eAAe,OAAO,KAAK,GAAG;AAAA,UACjC,MAAM;AAAA,UACN,KAAK,OAAO,SAAS;AAAA,UACrB,WAAW,UAAU;AAAA,QACvB,CAAC;AAAA,MACH;AAEA,UAAI,KAAK,8BAA8B;AACrC,aAAK,6BAA6B,KAAK;AAAA,MACzC;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,qBAA2B;AACzB,QAAI,CAAC,KAAK,eAAe,OAAO,WAAW,YAAa;AAExD,SAAK,cAAc;AACnB,WAAO,UAAU,KAAK;AACtB,WAAO,uBAAuB,KAAK;AAAA,EACrC;AACF;","names":[]}
@@ -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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