5xx-sdk 1.0.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.
@@ -0,0 +1,46 @@
1
+ interface FiveXXOptions {
2
+ apiKey: string;
3
+ endpoint: string;
4
+ environment?: string;
5
+ }
6
+ interface ErrorPayload {
7
+ message: string;
8
+ stack?: string;
9
+ environment?: string;
10
+ metadata?: Record<string, unknown>;
11
+ }
12
+ interface User {
13
+ id?: string;
14
+ email?: string;
15
+ name?: string;
16
+ }
17
+
18
+ declare class FiveXX {
19
+ private apiKey;
20
+ private endpoint;
21
+ private environment;
22
+ private user;
23
+ constructor(options: FiveXXOptions);
24
+ /**
25
+ * Set the environment (e.g., "production", "development", "staging")
26
+ */
27
+ setEnvironment(env: string): void;
28
+ /**
29
+ * Set user context for errors
30
+ */
31
+ setUser(user: User | null): void;
32
+ /**
33
+ * Capture an error and send it to the 5xx server
34
+ */
35
+ captureError(error: Error, metadata?: Record<string, unknown>): Promise<string | null>;
36
+ /**
37
+ * Capture a message as an error
38
+ */
39
+ captureMessage(message: string, metadata?: Record<string, unknown>): Promise<string | null>;
40
+ /**
41
+ * Send error payload to the server
42
+ */
43
+ private send;
44
+ }
45
+
46
+ export { type ErrorPayload as E, FiveXX as F, type User as U, type FiveXXOptions as a };
@@ -0,0 +1,46 @@
1
+ interface FiveXXOptions {
2
+ apiKey: string;
3
+ endpoint: string;
4
+ environment?: string;
5
+ }
6
+ interface ErrorPayload {
7
+ message: string;
8
+ stack?: string;
9
+ environment?: string;
10
+ metadata?: Record<string, unknown>;
11
+ }
12
+ interface User {
13
+ id?: string;
14
+ email?: string;
15
+ name?: string;
16
+ }
17
+
18
+ declare class FiveXX {
19
+ private apiKey;
20
+ private endpoint;
21
+ private environment;
22
+ private user;
23
+ constructor(options: FiveXXOptions);
24
+ /**
25
+ * Set the environment (e.g., "production", "development", "staging")
26
+ */
27
+ setEnvironment(env: string): void;
28
+ /**
29
+ * Set user context for errors
30
+ */
31
+ setUser(user: User | null): void;
32
+ /**
33
+ * Capture an error and send it to the 5xx server
34
+ */
35
+ captureError(error: Error, metadata?: Record<string, unknown>): Promise<string | null>;
36
+ /**
37
+ * Capture a message as an error
38
+ */
39
+ captureMessage(message: string, metadata?: Record<string, unknown>): Promise<string | null>;
40
+ /**
41
+ * Send error payload to the server
42
+ */
43
+ private send;
44
+ }
45
+
46
+ export { type ErrorPayload as E, FiveXX as F, type User as U, type FiveXXOptions as a };
@@ -0,0 +1,3 @@
1
+ export { E as ErrorPayload, F as FiveXX, a as FiveXXOptions, U as User } from './client-BhKj28Zi.mjs';
2
+ export { FiveXXBrowser } from './browser.mjs';
3
+ export { FiveXXNode } from './node.mjs';
@@ -0,0 +1,3 @@
1
+ export { E as ErrorPayload, F as FiveXX, a as FiveXXOptions, U as User } from './client-BhKj28Zi.js';
2
+ export { FiveXXBrowser } from './browser.js';
3
+ export { FiveXXNode } from './node.js';
package/dist/index.js ADDED
@@ -0,0 +1,249 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ FiveXX: () => FiveXX,
24
+ FiveXXBrowser: () => FiveXXBrowser,
25
+ FiveXXNode: () => FiveXXNode
26
+ });
27
+ module.exports = __toCommonJS(src_exports);
28
+
29
+ // src/client.ts
30
+ var FiveXX = class {
31
+ constructor(options) {
32
+ this.user = null;
33
+ this.apiKey = options.apiKey;
34
+ this.endpoint = options.endpoint.replace(/\/$/, "");
35
+ this.environment = options.environment || "production";
36
+ }
37
+ /**
38
+ * Set the environment (e.g., "production", "development", "staging")
39
+ */
40
+ setEnvironment(env) {
41
+ this.environment = env;
42
+ }
43
+ /**
44
+ * Set user context for errors
45
+ */
46
+ setUser(user) {
47
+ this.user = user;
48
+ }
49
+ /**
50
+ * Capture an error and send it to the 5xx server
51
+ */
52
+ async captureError(error, metadata) {
53
+ const payload = {
54
+ message: error.message || String(error),
55
+ stack: error.stack,
56
+ environment: this.environment,
57
+ metadata: {
58
+ ...metadata,
59
+ ...this.user && { user: this.user }
60
+ }
61
+ };
62
+ return this.send(payload);
63
+ }
64
+ /**
65
+ * Capture a message as an error
66
+ */
67
+ async captureMessage(message, metadata) {
68
+ const payload = {
69
+ message,
70
+ environment: this.environment,
71
+ metadata: {
72
+ ...metadata,
73
+ ...this.user && { user: this.user }
74
+ }
75
+ };
76
+ return this.send(payload);
77
+ }
78
+ /**
79
+ * Send error payload to the server
80
+ */
81
+ async send(payload) {
82
+ try {
83
+ const response = await fetch(`${this.endpoint}/api/errors`, {
84
+ method: "POST",
85
+ headers: {
86
+ "Content-Type": "application/json",
87
+ "X-API-Key": this.apiKey
88
+ },
89
+ body: JSON.stringify(payload)
90
+ });
91
+ if (!response.ok) {
92
+ console.error(`5xx: Failed to send error (${response.status})`);
93
+ return null;
94
+ }
95
+ const data = await response.json();
96
+ return data.id;
97
+ } catch (err) {
98
+ console.error("5xx: Failed to send error", err);
99
+ return null;
100
+ }
101
+ }
102
+ };
103
+
104
+ // src/browser.ts
105
+ var FiveXXBrowser = class extends FiveXX {
106
+ constructor(options) {
107
+ super(options);
108
+ this.autoCapture = false;
109
+ this.originalOnError = null;
110
+ this.originalOnUnhandledRejection = null;
111
+ if (typeof window !== "undefined" && !options.environment) {
112
+ const hostname = window.location.hostname;
113
+ if (hostname === "localhost" || hostname === "127.0.0.1") {
114
+ this.setEnvironment("development");
115
+ }
116
+ }
117
+ }
118
+ /**
119
+ * Enable automatic capture of unhandled errors and promise rejections
120
+ */
121
+ enableAutoCapture() {
122
+ if (this.autoCapture || typeof window === "undefined") return;
123
+ this.autoCapture = true;
124
+ this.originalOnError = window.onerror;
125
+ window.onerror = (message, source, lineno, colno, error) => {
126
+ if (error) {
127
+ this.captureError(error, {
128
+ source,
129
+ lineno,
130
+ colno,
131
+ url: window.location.href,
132
+ userAgent: navigator.userAgent
133
+ });
134
+ } else {
135
+ this.captureMessage(String(message), {
136
+ source,
137
+ lineno,
138
+ colno,
139
+ url: window.location.href,
140
+ userAgent: navigator.userAgent
141
+ });
142
+ }
143
+ if (this.originalOnError) {
144
+ return this.originalOnError(message, source, lineno, colno, error);
145
+ }
146
+ return false;
147
+ };
148
+ this.originalOnUnhandledRejection = window.onunhandledrejection;
149
+ window.onunhandledrejection = (event) => {
150
+ const error = event.reason;
151
+ if (error instanceof Error) {
152
+ this.captureError(error, {
153
+ type: "unhandledRejection",
154
+ url: window.location.href,
155
+ userAgent: navigator.userAgent
156
+ });
157
+ } else {
158
+ this.captureMessage(String(error), {
159
+ type: "unhandledRejection",
160
+ url: window.location.href,
161
+ userAgent: navigator.userAgent
162
+ });
163
+ }
164
+ if (this.originalOnUnhandledRejection) {
165
+ this.originalOnUnhandledRejection(event);
166
+ }
167
+ };
168
+ }
169
+ /**
170
+ * Disable automatic capture
171
+ */
172
+ disableAutoCapture() {
173
+ if (!this.autoCapture || typeof window === "undefined") return;
174
+ this.autoCapture = false;
175
+ window.onerror = this.originalOnError;
176
+ window.onunhandledrejection = this.originalOnUnhandledRejection;
177
+ }
178
+ };
179
+
180
+ // src/node.ts
181
+ var FiveXXNode = class extends FiveXX {
182
+ constructor(options) {
183
+ super(options);
184
+ this.autoCapture = false;
185
+ this.exitOnFatalError = options.exitOnFatalError ?? true;
186
+ if (!options.environment && process.env.NODE_ENV) {
187
+ this.setEnvironment(process.env.NODE_ENV);
188
+ }
189
+ }
190
+ /**
191
+ * Enable automatic capture of uncaught exceptions and unhandled rejections
192
+ */
193
+ enableAutoCapture() {
194
+ if (this.autoCapture) return;
195
+ this.autoCapture = true;
196
+ process.on("uncaughtException", async (error) => {
197
+ console.error("5xx: Uncaught exception:", error);
198
+ await this.captureError(error, {
199
+ type: "uncaughtException",
200
+ nodeVersion: process.version,
201
+ platform: process.platform,
202
+ pid: process.pid
203
+ });
204
+ if (this.exitOnFatalError) {
205
+ process.exit(1);
206
+ }
207
+ });
208
+ process.on("unhandledRejection", async (reason) => {
209
+ console.error("5xx: Unhandled rejection:", reason);
210
+ if (reason instanceof Error) {
211
+ await this.captureError(reason, {
212
+ type: "unhandledRejection",
213
+ nodeVersion: process.version,
214
+ platform: process.platform,
215
+ pid: process.pid
216
+ });
217
+ } else {
218
+ await this.captureMessage(String(reason), {
219
+ type: "unhandledRejection",
220
+ nodeVersion: process.version,
221
+ platform: process.platform,
222
+ pid: process.pid
223
+ });
224
+ }
225
+ });
226
+ }
227
+ /**
228
+ * Wrap an async function to capture errors
229
+ */
230
+ wrapAsync(fn, metadata) {
231
+ return (async (...args) => {
232
+ try {
233
+ return await fn(...args);
234
+ } catch (error) {
235
+ if (error instanceof Error) {
236
+ await this.captureError(error, metadata);
237
+ }
238
+ throw error;
239
+ }
240
+ });
241
+ }
242
+ };
243
+ // Annotate the CommonJS export names for ESM import in node:
244
+ 0 && (module.exports = {
245
+ FiveXX,
246
+ FiveXXBrowser,
247
+ FiveXXNode
248
+ });
249
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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;AA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AM,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":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,15 @@
1
+ import {
2
+ FiveXXBrowser
3
+ } from "./chunk-LD3XNYST.mjs";
4
+ import {
5
+ FiveXXNode
6
+ } from "./chunk-MOWJJPVU.mjs";
7
+ import {
8
+ FiveXX
9
+ } from "./chunk-5YY5E33R.mjs";
10
+ export {
11
+ FiveXX,
12
+ FiveXXBrowser,
13
+ FiveXXNode
14
+ };
15
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,23 @@
1
+ import { F as FiveXX, a as FiveXXOptions } from './client-BhKj28Zi.mjs';
2
+
3
+ interface NodeOptions extends FiveXXOptions {
4
+ exitOnFatalError?: boolean;
5
+ }
6
+ /**
7
+ * Node.js-specific FiveXX client with automatic error capture
8
+ */
9
+ declare class FiveXXNode extends FiveXX {
10
+ private autoCapture;
11
+ private exitOnFatalError;
12
+ constructor(options: NodeOptions);
13
+ /**
14
+ * Enable automatic capture of uncaught exceptions and unhandled rejections
15
+ */
16
+ enableAutoCapture(): void;
17
+ /**
18
+ * Wrap an async function to capture errors
19
+ */
20
+ wrapAsync<T extends (...args: unknown[]) => Promise<unknown>>(fn: T, metadata?: Record<string, unknown>): T;
21
+ }
22
+
23
+ export { FiveXXNode };
package/dist/node.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { F as FiveXX, a as FiveXXOptions } from './client-BhKj28Zi.js';
2
+
3
+ interface NodeOptions extends FiveXXOptions {
4
+ exitOnFatalError?: boolean;
5
+ }
6
+ /**
7
+ * Node.js-specific FiveXX client with automatic error capture
8
+ */
9
+ declare class FiveXXNode extends FiveXX {
10
+ private autoCapture;
11
+ private exitOnFatalError;
12
+ constructor(options: NodeOptions);
13
+ /**
14
+ * Enable automatic capture of uncaught exceptions and unhandled rejections
15
+ */
16
+ enableAutoCapture(): void;
17
+ /**
18
+ * Wrap an async function to capture errors
19
+ */
20
+ wrapAsync<T extends (...args: unknown[]) => Promise<unknown>>(fn: T, metadata?: Record<string, unknown>): T;
21
+ }
22
+
23
+ export { FiveXXNode };
package/dist/node.js ADDED
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/node.ts
21
+ var node_exports = {};
22
+ __export(node_exports, {
23
+ FiveXXNode: () => FiveXXNode
24
+ });
25
+ module.exports = __toCommonJS(node_exports);
26
+
27
+ // src/client.ts
28
+ var FiveXX = class {
29
+ constructor(options) {
30
+ this.user = null;
31
+ this.apiKey = options.apiKey;
32
+ this.endpoint = options.endpoint.replace(/\/$/, "");
33
+ this.environment = options.environment || "production";
34
+ }
35
+ /**
36
+ * Set the environment (e.g., "production", "development", "staging")
37
+ */
38
+ setEnvironment(env) {
39
+ this.environment = env;
40
+ }
41
+ /**
42
+ * Set user context for errors
43
+ */
44
+ setUser(user) {
45
+ this.user = user;
46
+ }
47
+ /**
48
+ * Capture an error and send it to the 5xx server
49
+ */
50
+ async captureError(error, metadata) {
51
+ const payload = {
52
+ message: error.message || String(error),
53
+ stack: error.stack,
54
+ environment: this.environment,
55
+ metadata: {
56
+ ...metadata,
57
+ ...this.user && { user: this.user }
58
+ }
59
+ };
60
+ return this.send(payload);
61
+ }
62
+ /**
63
+ * Capture a message as an error
64
+ */
65
+ async captureMessage(message, metadata) {
66
+ const payload = {
67
+ message,
68
+ environment: this.environment,
69
+ metadata: {
70
+ ...metadata,
71
+ ...this.user && { user: this.user }
72
+ }
73
+ };
74
+ return this.send(payload);
75
+ }
76
+ /**
77
+ * Send error payload to the server
78
+ */
79
+ async send(payload) {
80
+ try {
81
+ const response = await fetch(`${this.endpoint}/api/errors`, {
82
+ method: "POST",
83
+ headers: {
84
+ "Content-Type": "application/json",
85
+ "X-API-Key": this.apiKey
86
+ },
87
+ body: JSON.stringify(payload)
88
+ });
89
+ if (!response.ok) {
90
+ console.error(`5xx: Failed to send error (${response.status})`);
91
+ return null;
92
+ }
93
+ const data = await response.json();
94
+ return data.id;
95
+ } catch (err) {
96
+ console.error("5xx: Failed to send error", err);
97
+ return null;
98
+ }
99
+ }
100
+ };
101
+
102
+ // src/node.ts
103
+ var FiveXXNode = class extends FiveXX {
104
+ constructor(options) {
105
+ super(options);
106
+ this.autoCapture = false;
107
+ this.exitOnFatalError = options.exitOnFatalError ?? true;
108
+ if (!options.environment && process.env.NODE_ENV) {
109
+ this.setEnvironment(process.env.NODE_ENV);
110
+ }
111
+ }
112
+ /**
113
+ * Enable automatic capture of uncaught exceptions and unhandled rejections
114
+ */
115
+ enableAutoCapture() {
116
+ if (this.autoCapture) return;
117
+ this.autoCapture = true;
118
+ process.on("uncaughtException", async (error) => {
119
+ console.error("5xx: Uncaught exception:", error);
120
+ await this.captureError(error, {
121
+ type: "uncaughtException",
122
+ nodeVersion: process.version,
123
+ platform: process.platform,
124
+ pid: process.pid
125
+ });
126
+ if (this.exitOnFatalError) {
127
+ process.exit(1);
128
+ }
129
+ });
130
+ process.on("unhandledRejection", async (reason) => {
131
+ console.error("5xx: Unhandled rejection:", reason);
132
+ if (reason instanceof Error) {
133
+ await this.captureError(reason, {
134
+ type: "unhandledRejection",
135
+ nodeVersion: process.version,
136
+ platform: process.platform,
137
+ pid: process.pid
138
+ });
139
+ } else {
140
+ await this.captureMessage(String(reason), {
141
+ type: "unhandledRejection",
142
+ nodeVersion: process.version,
143
+ platform: process.platform,
144
+ pid: process.pid
145
+ });
146
+ }
147
+ });
148
+ }
149
+ /**
150
+ * Wrap an async function to capture errors
151
+ */
152
+ wrapAsync(fn, metadata) {
153
+ return (async (...args) => {
154
+ try {
155
+ return await fn(...args);
156
+ } catch (error) {
157
+ if (error instanceof Error) {
158
+ await this.captureError(error, metadata);
159
+ }
160
+ throw error;
161
+ }
162
+ });
163
+ }
164
+ };
165
+ // Annotate the CommonJS export names for ESM import in node:
166
+ 0 && (module.exports = {
167
+ FiveXXNode
168
+ });
169
+ //# sourceMappingURL=node.js.map
@@ -0,0 +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,M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 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}