@uncaughtdev/core 0.1.1 → 0.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/README.md +44 -3
- package/dist/chunk-2YXXFGBV.js +2 -0
- package/dist/chunk-2YXXFGBV.js.map +1 -0
- package/dist/chunk-3FCDO7OR.mjs +23 -0
- package/dist/chunk-3FCDO7OR.mjs.map +1 -0
- package/dist/chunk-A6GKDPT3.mjs +2 -0
- package/dist/chunk-A6GKDPT3.mjs.map +1 -0
- package/dist/chunk-BXMN7NW4.mjs +2 -0
- package/dist/chunk-BXMN7NW4.mjs.map +1 -0
- package/dist/chunk-HANXURHX.mjs +59 -0
- package/dist/chunk-HANXURHX.mjs.map +1 -0
- package/dist/chunk-MSUAXLMV.js +2 -0
- package/dist/chunk-MSUAXLMV.js.map +1 -0
- package/dist/chunk-VQXSHR3C.js +59 -0
- package/dist/chunk-VQXSHR3C.js.map +1 -0
- package/dist/chunk-WZBG5VLB.js +23 -0
- package/dist/chunk-WZBG5VLB.js.map +1 -0
- package/dist/index.d.mts +64 -3
- package/dist/index.d.ts +64 -3
- package/dist/index.js +7 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -26
- package/dist/index.mjs.map +1 -1
- package/dist/local-api-handler-pages.js +1 -1
- package/dist/local-api-handler-pages.js.map +1 -1
- package/dist/local-api-handler-pages.mjs +1 -1
- package/dist/local-api-handler-pages.mjs.map +1 -1
- package/dist/local-api-handler.d.mts +1 -1
- package/dist/local-api-handler.d.ts +1 -1
- package/dist/local-api-handler.js +1 -1
- package/dist/local-api-handler.mjs +1 -1
- package/dist/local-viewer.js +432 -46
- package/dist/local-viewer.js.map +1 -1
- package/dist/local-viewer.mjs +432 -46
- package/dist/local-viewer.mjs.map +1 -1
- package/dist/mcp-server.d.mts +1 -0
- package/dist/mcp-server.d.ts +1 -0
- package/dist/mcp-server.js +22 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/mcp-server.mjs +22 -0
- package/dist/mcp-server.mjs.map +1 -0
- package/dist/sqlite-store-4FTNST7O.js +2 -0
- package/dist/sqlite-store-4FTNST7O.js.map +1 -0
- package/dist/sqlite-store-TEXDAAOM.mjs +2 -0
- package/dist/sqlite-store-TEXDAAOM.mjs.map +1 -0
- package/dist/{types-CjgYXVc_.d.mts → types-D1Fw4k-D.d.mts} +12 -1
- package/dist/{types-CjgYXVc_.d.ts → types-D1Fw4k-D.d.ts} +12 -1
- package/package.json +9 -2
- package/dist/chunk-FFHQ452Q.js +0 -2
- package/dist/chunk-FFHQ452Q.js.map +0 -1
- package/dist/chunk-JALIO2BZ.mjs +0 -2
- package/dist/chunk-JALIO2BZ.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as UncaughtConfig, R as RequestInfo, O as OperationInfo, S as SeverityLevel, B as Breadcrumb, b as UserInfo, c as BreadcrumbStore, U as UncaughtEvent, E as EnvironmentInfo, T as Transport } from './types-
|
|
2
|
-
export { d as BreadcrumbType, e as ErrorInfo, I as IssueEntry, f as IssueStatus, g as SdkInfo, h as TransportMode, i as TransportOptions } from './types-
|
|
1
|
+
import { a as UncaughtConfig, R as RequestInfo, O as OperationInfo, S as SeverityLevel, B as Breadcrumb, b as UserInfo, c as BreadcrumbStore, U as UncaughtEvent, E as EnvironmentInfo, T as Transport } from './types-D1Fw4k-D.mjs';
|
|
2
|
+
export { d as BreadcrumbType, e as ErrorInfo, I as IssueEntry, f as IssueStatus, g as SdkInfo, h as TransportMode, i as TransportOptions } from './types-D1Fw4k-D.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Initialise the Uncaught SDK. Calling this more than once replaces the
|
|
@@ -17,8 +17,13 @@ declare class UncaughtClient {
|
|
|
17
17
|
private readonly transport;
|
|
18
18
|
private readonly rateLimiter;
|
|
19
19
|
private readonly sessionId;
|
|
20
|
+
private readonly seenFingerprints;
|
|
20
21
|
private user;
|
|
21
22
|
constructor(config: UncaughtConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Return the current SDK configuration.
|
|
25
|
+
*/
|
|
26
|
+
getConfig(): UncaughtConfig;
|
|
22
27
|
/**
|
|
23
28
|
* Capture an error and send it through the transport pipeline.
|
|
24
29
|
*
|
|
@@ -42,11 +47,21 @@ declare class UncaughtClient {
|
|
|
42
47
|
* Set user context that will be attached to subsequent events.
|
|
43
48
|
*/
|
|
44
49
|
setUser(user: UserInfo | undefined): void;
|
|
50
|
+
/**
|
|
51
|
+
* Attach user feedback to a previously captured event.
|
|
52
|
+
* Re-sends the event with feedback attached so it persists.
|
|
53
|
+
*/
|
|
54
|
+
submitFeedback(eventId: string, feedback: string): void;
|
|
45
55
|
/**
|
|
46
56
|
* Flush all queued events to the transport.
|
|
47
57
|
*/
|
|
48
58
|
flush(): Promise<void>;
|
|
49
59
|
private shouldIgnore;
|
|
60
|
+
/**
|
|
61
|
+
* POST a notification to the configured webhook URL for new error fingerprints.
|
|
62
|
+
* Fire-and-forget — never blocks the error pipeline.
|
|
63
|
+
*/
|
|
64
|
+
private sendWebhook;
|
|
50
65
|
private debugLog;
|
|
51
66
|
}
|
|
52
67
|
|
|
@@ -152,4 +167,50 @@ declare function isoTimestamp(): string;
|
|
|
152
167
|
*/
|
|
153
168
|
declare function truncate(str: string, maxLen?: number): string;
|
|
154
169
|
|
|
155
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Set up Node.js process-level error handlers.
|
|
172
|
+
*
|
|
173
|
+
* - `uncaughtException` — captures the error, flushes, then re-throws
|
|
174
|
+
* - `unhandledRejection` — captures with 'fatal' level
|
|
175
|
+
*
|
|
176
|
+
* @returns Cleanup function to remove the handlers.
|
|
177
|
+
*/
|
|
178
|
+
declare function setupNodeHandlers(client: UncaughtClient): () => void;
|
|
179
|
+
/**
|
|
180
|
+
* Express error-handling middleware.
|
|
181
|
+
*
|
|
182
|
+
* Usage:
|
|
183
|
+
* ```js
|
|
184
|
+
* const { expressErrorHandler } = require('@uncaughtdev/core');
|
|
185
|
+
* app.use(expressErrorHandler(client));
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* Must be registered AFTER all routes (Express processes error middleware last).
|
|
189
|
+
*/
|
|
190
|
+
declare function expressErrorHandler(client: UncaughtClient): (err: Error, req: unknown, res: unknown, next: (err?: unknown) => void) => void;
|
|
191
|
+
/**
|
|
192
|
+
* Fastify error handler plugin.
|
|
193
|
+
*
|
|
194
|
+
* Usage:
|
|
195
|
+
* ```js
|
|
196
|
+
* const { fastifyErrorPlugin } = require('@uncaughtdev/core');
|
|
197
|
+
* fastify.register(fastifyErrorPlugin(client));
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
declare function fastifyErrorPlugin(client: UncaughtClient): (fastify: unknown, opts: unknown, done: () => void) => void;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Resolve a minified/bundled stack trace to original source locations
|
|
204
|
+
* using source maps found in common build output directories.
|
|
205
|
+
*
|
|
206
|
+
* @param stack - The raw stack trace string
|
|
207
|
+
* @param searchDirs - Directories to search for .map files (defaults to common build dirs)
|
|
208
|
+
* @returns The resolved stack trace with original file paths and line numbers
|
|
209
|
+
*/
|
|
210
|
+
declare function resolveStackTrace(stack: string, searchDirs?: string[]): Promise<string>;
|
|
211
|
+
/**
|
|
212
|
+
* Clean up cached source map consumers to free memory.
|
|
213
|
+
*/
|
|
214
|
+
declare function clearSourceMapCache(): void;
|
|
215
|
+
|
|
216
|
+
export { Breadcrumb, BreadcrumbStore, EnvironmentInfo, OperationInfo, RequestInfo, SeverityLevel, Transport, UncaughtClient, UncaughtConfig, UncaughtEvent, UserInfo, buildFixPrompt, clearSourceMapCache, createBreadcrumbStore, createRateLimiter, createTransport, detectEnvironment, expressErrorHandler, fastifyErrorPlugin, generateFingerprint, generateUUID, getClient, initUncaught, isoTimestamp, resolveStackTrace, safeStringify, sanitize, setupNodeHandlers, truncate };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as UncaughtConfig, R as RequestInfo, O as OperationInfo, S as SeverityLevel, B as Breadcrumb, b as UserInfo, c as BreadcrumbStore, U as UncaughtEvent, E as EnvironmentInfo, T as Transport } from './types-
|
|
2
|
-
export { d as BreadcrumbType, e as ErrorInfo, I as IssueEntry, f as IssueStatus, g as SdkInfo, h as TransportMode, i as TransportOptions } from './types-
|
|
1
|
+
import { a as UncaughtConfig, R as RequestInfo, O as OperationInfo, S as SeverityLevel, B as Breadcrumb, b as UserInfo, c as BreadcrumbStore, U as UncaughtEvent, E as EnvironmentInfo, T as Transport } from './types-D1Fw4k-D.js';
|
|
2
|
+
export { d as BreadcrumbType, e as ErrorInfo, I as IssueEntry, f as IssueStatus, g as SdkInfo, h as TransportMode, i as TransportOptions } from './types-D1Fw4k-D.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Initialise the Uncaught SDK. Calling this more than once replaces the
|
|
@@ -17,8 +17,13 @@ declare class UncaughtClient {
|
|
|
17
17
|
private readonly transport;
|
|
18
18
|
private readonly rateLimiter;
|
|
19
19
|
private readonly sessionId;
|
|
20
|
+
private readonly seenFingerprints;
|
|
20
21
|
private user;
|
|
21
22
|
constructor(config: UncaughtConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Return the current SDK configuration.
|
|
25
|
+
*/
|
|
26
|
+
getConfig(): UncaughtConfig;
|
|
22
27
|
/**
|
|
23
28
|
* Capture an error and send it through the transport pipeline.
|
|
24
29
|
*
|
|
@@ -42,11 +47,21 @@ declare class UncaughtClient {
|
|
|
42
47
|
* Set user context that will be attached to subsequent events.
|
|
43
48
|
*/
|
|
44
49
|
setUser(user: UserInfo | undefined): void;
|
|
50
|
+
/**
|
|
51
|
+
* Attach user feedback to a previously captured event.
|
|
52
|
+
* Re-sends the event with feedback attached so it persists.
|
|
53
|
+
*/
|
|
54
|
+
submitFeedback(eventId: string, feedback: string): void;
|
|
45
55
|
/**
|
|
46
56
|
* Flush all queued events to the transport.
|
|
47
57
|
*/
|
|
48
58
|
flush(): Promise<void>;
|
|
49
59
|
private shouldIgnore;
|
|
60
|
+
/**
|
|
61
|
+
* POST a notification to the configured webhook URL for new error fingerprints.
|
|
62
|
+
* Fire-and-forget — never blocks the error pipeline.
|
|
63
|
+
*/
|
|
64
|
+
private sendWebhook;
|
|
50
65
|
private debugLog;
|
|
51
66
|
}
|
|
52
67
|
|
|
@@ -152,4 +167,50 @@ declare function isoTimestamp(): string;
|
|
|
152
167
|
*/
|
|
153
168
|
declare function truncate(str: string, maxLen?: number): string;
|
|
154
169
|
|
|
155
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Set up Node.js process-level error handlers.
|
|
172
|
+
*
|
|
173
|
+
* - `uncaughtException` — captures the error, flushes, then re-throws
|
|
174
|
+
* - `unhandledRejection` — captures with 'fatal' level
|
|
175
|
+
*
|
|
176
|
+
* @returns Cleanup function to remove the handlers.
|
|
177
|
+
*/
|
|
178
|
+
declare function setupNodeHandlers(client: UncaughtClient): () => void;
|
|
179
|
+
/**
|
|
180
|
+
* Express error-handling middleware.
|
|
181
|
+
*
|
|
182
|
+
* Usage:
|
|
183
|
+
* ```js
|
|
184
|
+
* const { expressErrorHandler } = require('@uncaughtdev/core');
|
|
185
|
+
* app.use(expressErrorHandler(client));
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* Must be registered AFTER all routes (Express processes error middleware last).
|
|
189
|
+
*/
|
|
190
|
+
declare function expressErrorHandler(client: UncaughtClient): (err: Error, req: unknown, res: unknown, next: (err?: unknown) => void) => void;
|
|
191
|
+
/**
|
|
192
|
+
* Fastify error handler plugin.
|
|
193
|
+
*
|
|
194
|
+
* Usage:
|
|
195
|
+
* ```js
|
|
196
|
+
* const { fastifyErrorPlugin } = require('@uncaughtdev/core');
|
|
197
|
+
* fastify.register(fastifyErrorPlugin(client));
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
declare function fastifyErrorPlugin(client: UncaughtClient): (fastify: unknown, opts: unknown, done: () => void) => void;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Resolve a minified/bundled stack trace to original source locations
|
|
204
|
+
* using source maps found in common build output directories.
|
|
205
|
+
*
|
|
206
|
+
* @param stack - The raw stack trace string
|
|
207
|
+
* @param searchDirs - Directories to search for .map files (defaults to common build dirs)
|
|
208
|
+
* @returns The resolved stack trace with original file paths and line numbers
|
|
209
|
+
*/
|
|
210
|
+
declare function resolveStackTrace(stack: string, searchDirs?: string[]): Promise<string>;
|
|
211
|
+
/**
|
|
212
|
+
* Clean up cached source map consumers to free memory.
|
|
213
|
+
*/
|
|
214
|
+
declare function clearSourceMapCache(): void;
|
|
215
|
+
|
|
216
|
+
export { Breadcrumb, BreadcrumbStore, EnvironmentInfo, OperationInfo, RequestInfo, SeverityLevel, Transport, UncaughtClient, UncaughtConfig, UncaughtEvent, UserInfo, buildFixPrompt, clearSourceMapCache, createBreadcrumbStore, createRateLimiter, createTransport, detectEnvironment, expressErrorHandler, fastifyErrorPlugin, generateFingerprint, generateUUID, getClient, initUncaught, isoTimestamp, resolveStackTrace, safeStringify, sanitize, setupNodeHandlers, truncate };
|
package/dist/index.js
CHANGED
|
@@ -1,29 +1,10 @@
|
|
|
1
|
-
'use strict';var chunkE76GW6KF_js=require('./chunk-E76GW6KF.js');function
|
|
2
|
-
`);return
|
|
3
|
-
`),n=[];for(let
|
|
4
|
-
|
|
5
|
-
`));}if(e.error?.stack){let r=e.error.stack.split(`
|
|
6
|
-
`).slice(0,15).map(n=>n.trimEnd()).join(`
|
|
7
|
-
`);t.push(`## Stack Trace
|
|
8
|
-
|
|
9
|
-
\`\`\`
|
|
10
|
-
${r}
|
|
11
|
-
\`\`\``);}return e.operation&&t.push(H(e.operation)),e.request&&t.push(Y(e.request)),e.breadcrumbs&&e.breadcrumbs.length>0&&t.push(Z(e.breadcrumbs)),e.environment&&t.push(ee(e.environment)),e.error?.componentStack&&t.push(`## React Component Stack
|
|
12
|
-
|
|
13
|
-
\`\`\`
|
|
14
|
-
${e.error.componentStack.trim()}
|
|
15
|
-
\`\`\``),t.push(["## What I need","","1. **Root cause analysis** \u2014 explain why this error is occurring.","2. **A fix** \u2014 provide the corrected code with an explanation of the changes.","3. **Prevention** \u2014 suggest any guards or tests to prevent this from happening again."].join(`
|
|
16
|
-
`)),t.join(`
|
|
17
|
-
|
|
18
|
-
`)+`
|
|
19
|
-
`}function J(e){if(e)for(let t of e.split(`
|
|
20
|
-
`)){let r=t.trim(),n=r.match(/at\s+(?:.+?\s+\()?(.+?:\d+:\d+)\)?/);if(n)return n[1];let a=r.match(/@(.+?:\d+:\d+)/);if(a)return a[1]}}function H(e){let t=["## Failed Operation",""];return t.push(`- **Provider:** ${e.provider}`),t.push(`- **Type:** ${e.type}`),t.push(`- **Method:** ${e.method}`),e.params&&(t.push("- **Params:**"),t.push("```json"),t.push(JSON.stringify(e.params,null,2)),t.push("```")),e.errorCode&&t.push(`- **Error Code:** ${e.errorCode}`),e.errorDetails&&t.push(`- **Error Details:** ${e.errorDetails}`),t.join(`
|
|
21
|
-
`)}function Y(e){let t=["## HTTP Request Context",""];return e.method&&t.push(`- **Method:** ${e.method}`),e.url&&t.push(`- **URL:** ${e.url}`),e.body&&(t.push("- **Body:**"),t.push("```json"),t.push(typeof e.body=="string"?e.body:JSON.stringify(e.body,null,2)),t.push("```")),t.join(`
|
|
22
|
-
`)}function Z(e){let t=e.slice(-5),r=["## User Session",""];for(let n of t){let a=Q(n.timestamp);r.push(`- \`${a}\` **[${n.type}]** ${n.message}`);}return r.join(`
|
|
23
|
-
`)}function Q(e){try{let t=new Date(e),r=String(t.getHours()).padStart(2,"0"),n=String(t.getMinutes()).padStart(2,"0"),a=String(t.getSeconds()).padStart(2,"0");return `${r}:${n}:${a}`}catch{return e}}function ee(e){let t=["## Environment",""],r=[["Framework",e.framework],["Framework Version",e.frameworkVersion],["Runtime",e.runtime],["Runtime Version",e.runtimeVersion],["Platform",e.platform],["Browser",e.browser?`${e.browser} ${e.browserVersion??""}`.trim():void 0],["OS",e.os],["Device",e.deviceType],["Locale",e.locale],["Timezone",e.timezone],["URL",e.url]];for(let[n,a]of r)a&&t.push(`- **${n}:** ${a}`);return t.join(`
|
|
24
|
-
`)}function _(e){switch(e.transport??"local"){case "console":return F();case "remote":return ie(e);default:return te(e)}}function F(e){return {send(t){try{let r=`[uncaught] ${t.error.type}: ${t.error.message}`;typeof console.group=="function"?console.group(r):console.log(`--- ${r} ---`),console.error("Error:",t.error.message),t.error.stack&&console.log("Stack:",t.error.stack),console.log("Event ID:",t.eventId),console.log("Fingerprint:",t.fingerprint),console.log("Breadcrumbs:",t.breadcrumbs),t.fixPrompt&&console.log(`Fix Prompt:
|
|
25
|
-
`,t.fixPrompt),typeof console.groupEnd=="function"&&console.groupEnd();}catch{}},async flush(){}}}function te(e){return typeof process<"u"&&process.versions?.node!=null?ne(e):oe()}function ne(e){let t,r,n="",a=false;async function o(){if(a)return;let i=await import('fs/promises'),s=await import('path');t=i,r=s,n=e.localOutputDir??r.resolve(process.cwd(),".uncaught"),await t.mkdir(r.join(n,"events"),{recursive:true}),await t.mkdir(r.join(n,"fix-prompts"),{recursive:true}),await c(t,r),a=true;}async function c(i,s){try{let u=s.resolve(process.cwd(),".gitignore"),d="";try{d=await i.readFile(u,"utf-8");}catch{}d.includes(".uncaught")||await i.appendFile(u,`
|
|
1
|
+
'use strict';var chunkE76GW6KF_js=require('./chunk-E76GW6KF.js'),chunkWZBG5VLB_js=require('./chunk-WZBG5VLB.js');require('./chunk-2YXXFGBV.js');var sourceMap=require('source-map');function k(e=20){let t=new Array(e),r=0,n=0;return {add(o){let a={...o,timestamp:chunkE76GW6KF_js.c()};t[r]=a,r=(r+1)%e,n<e&&n++;},getAll(){if(n===0)return [];let o=[],a=(r-n+e)%e;for(let i=0;i<n;i++){let s=(a+i)%e,u=t[s];u&&o.push({...u});}return o},getLast(o){if(o<=0||n===0)return [];let a=Math.min(o,n),i=[];for(let s=0;s<a;s++){let u=(r-1-s+e)%e,d=t[u];d&&i.unshift({...d});}return i},clear(){t.fill(void 0),r=0,n=0;}}}var V=["password","passwd","secret","token","apikey","api_key","authorization","credit_card","creditcard","card_number","cvv","ssn","social_security","private_key","access_token","refresh_token","session_id","cookie"],z=new Set(["authorization","cookie","set-cookie"]),M="[REDACTED]",O=2048;function H(e=[]){let r=[...V,...e].map(n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"));return new RegExp(r.join("|"),"i")}function x(e,t){let r=H(t),n=new WeakSet;function c(o,a){if(a&&r.test(a))return M;if(o==null)return o;if(typeof o=="string")return o.length>O?o.slice(0,O)+"...[truncated]":o;if(typeof o=="number"||typeof o=="boolean")return o;if(typeof o=="bigint")return o.toString();if(!(typeof o=="function"||typeof o=="symbol")){if(o instanceof Date)return o.toISOString();if(Array.isArray(o)){if(n.has(o))return "[Circular]";n.add(o);let i=o.map(s=>c(s));return n.delete(o),i}if(typeof o=="object"){if(n.has(o))return "[Circular]";n.add(o);let i={};for(let s of Object.keys(o)){if(z.has(s.toLowerCase())){i[s]=M;continue}i[s]=c(o[s],s);}return n.delete(o),i}return o}}return c(e)}function P(e){let t=X(e.message??""),r=G(e.stack??"",3),n=[e.type??"Error",t,...r].join(`
|
|
2
|
+
`);return J(n)}function X(e){return e.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,"<UUID>").replace(/\b[0-9a-f]{8,}\b/gi,"<HEX>").replace(/\b\d{4,}\b/g,"<NUM>").replace(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[.\d]*Z?/g,"<TIMESTAMP>").replace(/([/\\])[a-zA-Z0-9_-]+[-.]([a-f0-9]{6,})\.(js|ts|mjs|cjs|jsx|tsx)/g,"$1<FILE>.$3").trim()}function G(e,t){if(!e)return [];let r=e.split(`
|
|
3
|
+
`),n=[];for(let c of r){if(n.length>=t)break;let o=c.trim(),a=o.match(/at\s+(?:(.+?)\s+\()?(?:(.+?):\d+:\d+)\)?/);if(a){let s=a[1]||"<anonymous>",u=A(a[2]||"<unknown>");n.push(`${u}:${s}`);continue}let i=o.match(/^(.+?)@(.+?):\d+:\d+/);if(i){let s=i[1]||"<anonymous>",u=A(i[2]||"<unknown>");n.push(`${u}:${s}`);continue}}return n}function A(e){return e.replace(/[?#].*$/,"").replace(/^.*\/node_modules\//,"node_modules/").replace(/^(https?:\/\/[^/]+)/,"").replace(/^.*[/\\]/,"")}function J(e){let t=5381;for(let r=0;r<e.length;r++)t=(t<<5)+t+e.charCodeAt(r)|0;return (t>>>0).toString(16).padStart(8,"0")}function I(e=30,t=5){let r=new Map,n=[];function c(o,a){let i=a-6e4,s=0;for(;s<o.length&&o[s]<=i;)s++;return s>0&&o.splice(0,s),o}return {shouldAllow(o){let a=Date.now();if(n=c(n,a),n.length>=e)return false;let i=r.get(o);if(i||(i=[],r.set(o,i)),c(i,a),i.length>=t)return false;if(n.push(a),i.push(a),r.size>1e3)for(let[s,u]of r)u.length===0&&r.delete(s);return true}}}var U;function T(){if(U)return U;let e={};try{let t=typeof window<"u"&&typeof document<"u";if(typeof process<"u"&&process.versions!=null&&process.versions.node!=null)e.runtime="node",e.runtimeVersion=process.versions.node,e.platform=process.platform,e.os=Y();else if(t){e.runtime="browser",e.platform="web";let n=navigator?.userAgent??"",c=Z(n);e.browser=c.name,e.browserVersion=c.version,e.os=Q(n),e.deviceType=ee(),e.url=location?.href,e.locale=navigator?.language,e.timezone=Intl?.DateTimeFormat?.()?.resolvedOptions?.()?.timeZone;}te(e);}catch{}return U=e,e}function Y(){try{let e=process.platform;return {darwin:"macOS",win32:"Windows",linux:"Linux",freebsd:"FreeBSD",sunos:"SunOS"}[e]??e}catch{return}}function Z(e){let t=[{name:"Edge",regex:/Edg(?:e|A|iOS)?\/(\d+[\d.]*)/},{name:"Opera",regex:/(?:OPR|Opera)\/(\d+[\d.]*)/},{name:"Samsung Internet",regex:/SamsungBrowser\/(\d+[\d.]*)/},{name:"UC Browser",regex:/UCBrowser\/(\d+[\d.]*)/},{name:"Firefox",regex:/Firefox\/(\d+[\d.]*)/},{name:"Chrome",regex:/Chrome\/(\d+[\d.]*)/},{name:"Safari",regex:/Version\/(\d+[\d.]*).*Safari/}];for(let{name:r,regex:n}of t){let c=e.match(n);if(c)return {name:r,version:c[1]}}return {}}function Q(e){if(/Windows/i.test(e))return "Windows";if(/Mac OS X|macOS/i.test(e))return "macOS";if(/Android/i.test(e))return "Android";if(/iPhone|iPad|iPod/i.test(e))return "iOS";if(/Linux/i.test(e))return "Linux";if(/CrOS/i.test(e))return "ChromeOS"}function ee(){try{if(typeof window>"u")return;let e=window.screen?.width??window.innerWidth;return e<=480?"mobile":e<=1024?"tablet":"desktop"}catch{return}}function te(e){try{typeof window<"u"&&(window.__NEXT_DATA__?(e.framework="next",e.frameworkVersion=window.__NEXT_DATA__?.buildId??void 0):window.__remixContext?e.framework="remix":window.__NUXT__&&(e.framework="nuxt")),typeof process<"u"&&process.env!=null&&(e.framework||(process.env.__NEXT_PRIVATE_ORIGIN!==void 0||process.env.NEXT_RUNTIME?e.framework="next":process.env.REMIX_DEV_ORIGIN!==void 0&&(e.framework="remix")),process.env.VERCEL?e.platform=e.platform??"vercel":process.env.RAILWAY_PROJECT_ID?e.platform=e.platform??"railway":process.env.FLY_APP_NAME?e.platform=e.platform??"fly":process.env.AWS_LAMBDA_FUNCTION_NAME?e.platform=e.platform??"aws-lambda":process.env.GOOGLE_CLOUD_PROJECT&&(e.platform=e.platform??"gcp"));try{typeof undefined?.VITE_USER_NODE_ENV<"u"&&(e.framework||(e.framework="vite"));}catch{}}catch{}}function F(e){switch(e.transport??"local"){case "console":return B();case "remote":return se(e);default:return ne(e)}}function B(e){return {send(t){try{let r=`[uncaught] ${t.error.type}: ${t.error.message}`;typeof console.group=="function"?console.group(r):console.log(`--- ${r} ---`),console.error("Error:",t.error.message),t.error.stack&&console.log("Stack:",t.error.stack),console.log("Event ID:",t.eventId),console.log("Fingerprint:",t.fingerprint),console.log("Breadcrumbs:",t.breadcrumbs),t.fixPrompt&&console.log(`Fix Prompt:
|
|
4
|
+
`,t.fixPrompt),typeof console.groupEnd=="function"&&console.groupEnd();}catch{}},async flush(){}}}function ne(e){return typeof process<"u"&&process.versions?.node!=null?re(e):ie()}function re(e){let t,r,n="",c=false;async function o(){if(c)return;let i=await import('fs/promises'),s=await import('path');t=i,r=s,n=e.localOutputDir??r.resolve(process.cwd(),".uncaught"),await t.mkdir(r.join(n,"events"),{recursive:true}),await t.mkdir(r.join(n,"fix-prompts"),{recursive:true}),await a(t,r),c=true;}async function a(i,s){try{let u=s.resolve(process.cwd(),".gitignore"),d="";try{d=await i.readFile(u,"utf-8");}catch{}d.includes(".uncaught")||await i.appendFile(u,`
|
|
26
5
|
# Uncaught local error store
|
|
27
6
|
.uncaught/
|
|
28
|
-
`);}catch{}}return {async send(i){try{if(await o(),!t||!r)return;let s=i.fingerprint,u=r.join(n,"events",s);await t.mkdir(u,{recursive:!0});let
|
|
7
|
+
`);}catch{}}return {async send(i){try{if(await o(),!t||!r)return;let s=i.fingerprint,u=r.join(n,"events",s);await t.mkdir(u,{recursive:!0});let p=`event-${i.timestamp.replace(/[:.]/g,"-")}.json`,w=r.join(u,p),f=w+".tmp";await t.writeFile(f,chunkE76GW6KF_js.b(i),"utf-8"),await t.rename(f,w);let l=r.join(u,"latest.json"),g=l+".tmp";await t.writeFile(g,chunkE76GW6KF_js.b(i),"utf-8"),await t.rename(g,l);let b=`${s}.md`,R=r.join(n,"fix-prompts",b),L=R+".tmp";await t.writeFile(L,i.fixPrompt,"utf-8"),await t.rename(L,R),await oe(t,r,n,i,p,b);try{let{openStore:q}=await import('./sqlite-store-4FTNST7O.js'),W=r.join(n,"uncaught.db"),j=q(W);j.insertEvent(i),j.close();}catch{}}catch{}},async flush(){}}}async function oe(e,t,r,n,c,o){let a=t.join(r,"issues.json"),i=[];try{let p=await e.readFile(a,"utf-8");i=JSON.parse(p);}catch{}let s=i.find(p=>p.fingerprint===n.fingerprint),u=n.user?.id??n.user?.email??"anonymous";s?(s.count+=1,s.lastSeen=n.timestamp,s.latestEventFile=c,s.fixPromptFile=o,s.affectedUsers.includes(u)||s.affectedUsers.push(u),s.status==="resolved"&&(s.status="open")):i.push({fingerprint:n.fingerprint,title:n.error.message,errorType:n.error.type,count:1,affectedUsers:[u],firstSeen:n.timestamp,lastSeen:n.timestamp,status:"open",fixPromptFile:o,latestEventFile:c,release:n.release,environment:n.environment?.deploy});let d=a+".tmp";await e.writeFile(d,JSON.stringify(i,null,2),"utf-8"),await e.rename(d,a);}function ie(e){let t=[],r=B();async function n(c){try{let o=await fetch("/api/uncaught/local",{method:"POST",headers:{"Content-Type":"application/json"},body:chunkE76GW6KF_js.b({events:c})});return o.ok||o.status===202}catch{return false}}return {send(c){t.push(c),n([c]).then(o=>{o||r.send(c);}).catch(()=>{r.send(c);});},async flush(){if(t.length===0)return;let c=t.splice(0,t.length);if(!await n(c))for(let a of c)r.send(a);}}}function se(e){let t=e.endpoint??"",r=e.projectKey??"",n=3,c=10,o=5e3,a=[],i,s=false,u=[1e3,2e3,4e3];async function d(f){if(!(f.length===0||s))for(let l=0;l<=n;l++)try{let g=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",...r?{"X-Project-Key":r}:{}},body:chunkE76GW6KF_js.b({events:f})});if(g.ok||g.status===202)return;if(g.status===401){s=!0,i&&clearInterval(i);return}if(g.status===429){let b=parseInt(g.headers?.get?.("Retry-After")??"10",10);await _(b*1e3);continue}l<n&&await _(u[l]??4e3);}catch{l<n&&await _(u[l]??4e3);}}function p(){i||(i=setInterval(()=>{if(a.length>0){let f=a.splice(0,c);d(f).catch(()=>{});}},o),typeof i=="object"&&"unref"in i&&i.unref());}function w(){try{typeof window<"u"&&typeof navigator?.sendBeacon=="function"&&(window.addEventListener("visibilitychange",()=>{if(document.visibilityState==="hidden"&&a.length>0){let f=chunkE76GW6KF_js.b({events:a.splice(0,a.length)});navigator.sendBeacon(t,f);}}),window.addEventListener("pagehide",()=>{if(a.length>0){let f=chunkE76GW6KF_js.b({events:a.splice(0,a.length)});navigator.sendBeacon(t,f);}}));}catch{}}return p(),w(),{send(f){if(!s&&(a.push(f),a.length>=c)){let l=a.splice(0,c);d(l).catch(()=>{});}},async flush(){for(i&&(clearInterval(i),i=void 0);a.length>0;){let f=a.splice(0,c);await d(f);}}}}function _(e){return new Promise(t=>setTimeout(t,e))}var N="@uncaughtdev/core",D="0.1.0",C;function ae(e){return C=new v(e),C}function ce(){return C}var v=class{constructor(t){this.seenFingerprints=new Set;this.config={enabled:true,debug:false,maxBreadcrumbs:20,maxEventsPerMinute:30,...t},this.breadcrumbs=k(this.config.maxBreadcrumbs),this.transport=F(this.config),this.rateLimiter=I(this.config.maxEventsPerMinute),this.sessionId=chunkE76GW6KF_js.a();}getConfig(){return this.config}captureError(t,r){try{if(!this.config.enabled)return;let n=ue(t);if(r?.componentStack&&(n.componentStack=r.componentStack),this.shouldIgnore(n.message)){this.debugLog("Event ignored by ignoreErrors filter");return}let c=P(n);if(!this.rateLimiter.shouldAllow(c)){this.debugLog(`Rate-limited: ${c}`);return}let o=this.breadcrumbs.getAll(),a=T();this.config.environment&&(a.deploy=this.config.environment);let i=chunkE76GW6KF_js.a(),s={eventId:i,timestamp:chunkE76GW6KF_js.c(),projectKey:this.config.projectKey,level:r?.level??"error",fingerprint:c,release:this.config.release,error:n,breadcrumbs:o,request:r?.request,operation:r?.operation,environment:a,user:this.user?{...this.user,sessionId:this.sessionId}:{sessionId:this.sessionId},fixPrompt:"",sdk:{name:N,version:D}};if(s=x(s,this.config.sanitizeKeys),s.fixPrompt=chunkWZBG5VLB_js.a(s),this.config.beforeSend){let u=this.config.beforeSend(s);if(u===null){this.debugLog("Event dropped by beforeSend");return}s=u;}return this.transport.send(s),this.debugLog(`Captured event: ${i} (${c})`),this.config.webhookUrl&&!this.seenFingerprints.has(c)?(this.seenFingerprints.add(c),this.sendWebhook(s)):this.seenFingerprints.add(c),i}catch(n){this.debugLog("captureError failed:",n);return}}captureMessage(t,r="info"){try{return this.captureError(new Error(t),{level:r})}catch(n){this.debugLog("captureMessage failed:",n);return}}addBreadcrumb(t){try{if(!this.config.enabled)return;this.breadcrumbs.add(t);}catch(r){this.debugLog("addBreadcrumb failed:",r);}}setUser(t){try{this.user=t?{...t}:void 0;}catch(r){this.debugLog("setUser failed:",r);}}submitFeedback(t,r){try{if(!this.config.enabled||!r.trim())return;let n={eventId:chunkE76GW6KF_js.a(),timestamp:chunkE76GW6KF_js.c(),projectKey:this.config.projectKey,level:"info",fingerprint:`feedback-${t}`,release:this.config.release,error:{message:`User feedback for ${t}`,type:"UserFeedback"},breadcrumbs:[],userFeedback:r,fixPrompt:"",sdk:{name:N,version:D}};this.transport.send(n),this.debugLog(`Submitted feedback for event: ${t}`);}catch(n){this.debugLog("submitFeedback failed:",n);}}async flush(){try{await this.transport.flush();}catch(t){this.debugLog("flush failed:",t);}}shouldIgnore(t){let r=this.config.ignoreErrors;if(!r||r.length===0)return false;for(let n of r)if(typeof n=="string"){if(t.includes(n))return true}else if(n instanceof RegExp&&n.test(t))return true;return false}sendWebhook(t){try{let r={title:t.error.message,errorType:t.error.type,fingerprint:t.fingerprint,level:t.level,timestamp:t.timestamp,release:t.release,environment:t.environment?.deploy,fixPrompt:t.fixPrompt},n=chunkE76GW6KF_js.b(r),c=this.config.webhookUrl;typeof fetch=="function"&&fetch(c,{method:"POST",headers:{"Content-Type":"application/json"},body:n}).catch(()=>{});}catch{}}debugLog(...t){if(this.config.debug)try{console.debug("[uncaught]",...t);}catch{}}};function ue(e){if(e instanceof Error)return {message:e.message||String(e),type:e.constructor?.name||e.name||"Error",stack:e.stack,raw:e};if(typeof e=="string")return {message:e,type:"StringError",stack:new Error(e).stack,raw:e};if(e!==null&&typeof e=="object"){let t=e;return {message:String(t.message??t.reason??JSON.stringify(e)),type:String(t.name??t.type??"ObjectError"),stack:typeof t.stack=="string"?t.stack:void 0,raw:e}}return {message:String(e),type:"UnknownError",raw:e}}function fe(e){if(typeof process>"u"||!process.on)return ()=>{};let t=n=>{try{e.captureError(n,{level:"fatal"}),e.flush().catch(()=>{});}catch{}throw n},r=n=>{try{e.captureError(n,{level:"fatal"});}catch{}};return process.on("uncaughtException",t),process.on("unhandledRejection",r),()=>{process.removeListener("uncaughtException",t),process.removeListener("unhandledRejection",r);}}function de(e){return (t,r,n,c)=>{try{let o=r;e.captureError(t,{request:{method:o.method,url:o.originalUrl??o.url,headers:o.headers}});}catch{}c(t);}}function pe(e){return (t,r,n)=>{t.setErrorHandler((o,a,i)=>{try{let u=a;e.captureError(o,{request:{method:u.method,url:u.url,headers:u.headers}});}catch{}i.status(500).send({error:"Internal Server Error"});}),n();}}var me=[".next/static",".next/server","dist","build","out",".output"];function ge(e){let t=e.trim(),r=t.match(/^at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)$/);if(r)return {raw:t,fn:r[1],file:r[2],line:parseInt(r[3],10),column:parseInt(r[4],10)};let n=t.match(/^at\s+(.+?):(\d+):(\d+)$/);return n?{raw:t,file:n[1],line:parseInt(n[2],10),column:parseInt(n[3],10)}:{raw:t}}async function he(e,t){try{let r=await import('fs'),n=await import('path'),o=n.basename(e)+".map";for(let i of t){let s=n.resolve(i);if(!r.existsSync(s))continue;let u=$(r,n,s,o,3);if(u)return u}let a=e+".map";return r.existsSync(a)?a:null}catch{return null}}function $(e,t,r,n,c){if(c<=0)return null;try{let o=e.readdirSync(r,{withFileTypes:!0});for(let a of o){let i=t.join(r,a.name);if(a.isFile()&&a.name===n)return i;if(a.isDirectory()&&!a.name.startsWith(".")&&a.name!=="node_modules"){let s=$(e,t,i,n,c-1);if(s)return s}}}catch{}return null}var E=new Map;async function ye(e,t){if(!e)return e;let r=t??me,n=e.split(`
|
|
8
|
+
`),c=[];for(let o of n){let a=ge(o);if(!a.file||!a.line||!a.column){c.push(o);continue}try{let i=E.get(a.file);if(!i){let u=await he(a.file,r);if(!u){c.push(o);continue}let p=(await import('fs')).readFileSync(u,"utf-8");i=await new sourceMap.SourceMapConsumer(JSON.parse(p)),E.set(a.file,i);}let s=i.originalPositionFor({line:a.line,column:a.column-1});if(s.source&&s.line){let u=s.name||a.fn||"<anonymous>";c.push(` at ${u} (${s.source}:${s.line}:${(s.column??0)+1})`);}else c.push(o);}catch{c.push(o);}}return c.join(`
|
|
9
|
+
`)}function we(){for(let e of E.values())try{e.destroy();}catch{}E.clear();}Object.defineProperty(exports,"generateUUID",{enumerable:true,get:function(){return chunkE76GW6KF_js.a}});Object.defineProperty(exports,"isoTimestamp",{enumerable:true,get:function(){return chunkE76GW6KF_js.c}});Object.defineProperty(exports,"safeStringify",{enumerable:true,get:function(){return chunkE76GW6KF_js.b}});Object.defineProperty(exports,"truncate",{enumerable:true,get:function(){return chunkE76GW6KF_js.d}});Object.defineProperty(exports,"buildFixPrompt",{enumerable:true,get:function(){return chunkWZBG5VLB_js.a}});exports.UncaughtClient=v;exports.clearSourceMapCache=we;exports.createBreadcrumbStore=k;exports.createRateLimiter=I;exports.createTransport=F;exports.detectEnvironment=T;exports.expressErrorHandler=de;exports.fastifyErrorPlugin=pe;exports.generateFingerprint=P;exports.getClient=ce;exports.initUncaught=ae;exports.resolveStackTrace=ye;exports.sanitize=x;exports.setupNodeHandlers=fe;//# sourceMappingURL=index.js.map
|
|
29
10
|
//# sourceMappingURL=index.js.map
|