@cognicatch/react 1.1.1 → 1.1.2
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 +76 -129
- package/dist/cognicatch-react.css +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +15 -7
- package/dist/index.js +359 -241
- package/package.json +9 -4
package/dist/index.js
CHANGED
|
@@ -1,27 +1,63 @@
|
|
|
1
1
|
import { jsx as r, jsxs as u } from "react/jsx-runtime";
|
|
2
|
-
import { useState as
|
|
3
|
-
import { AlertCircle as y, AlertTriangle as C, AlertOctagon as
|
|
4
|
-
import { clsx as
|
|
5
|
-
import { twMerge as
|
|
6
|
-
import * as
|
|
7
|
-
import {
|
|
8
|
-
const
|
|
9
|
-
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
import { useState as P, useEffect as T, createContext as M, useCallback as I, useMemo as F, useContext as L, Component as j } from "react";
|
|
3
|
+
import { AlertCircle as y, AlertTriangle as C, AlertOctagon as U, RefreshCcw as B, ExternalLink as O, CheckCircle2 as $, Info as Z } from "lucide-react";
|
|
4
|
+
import { clsx as J } from "clsx";
|
|
5
|
+
import { twMerge as K } from "tailwind-merge";
|
|
6
|
+
import * as g from "@radix-ui/react-dialog";
|
|
7
|
+
import { toast as h, Toaster as W } from "sonner";
|
|
8
|
+
const Y = [
|
|
9
|
+
{
|
|
10
|
+
name: "email",
|
|
11
|
+
pattern: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,
|
|
12
|
+
replacement: "[EMAIL_REDACTED]"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "bearer_token",
|
|
16
|
+
pattern: /Bearer\s+[A-Za-z0-9\-._~+/]+=*/gi,
|
|
17
|
+
replacement: "Bearer [TOKEN_REDACTED]"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "jwt",
|
|
21
|
+
pattern: /eyJ[A-Za-z0-9\-_]+\.eyJ[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+/g,
|
|
22
|
+
replacement: "[JWT_REDACTED]"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "api_key",
|
|
26
|
+
pattern: /\b(?:sk|pk|key|api|sec)_[a-zA-Z0-9]{20,}\b|\b[A-Za-z0-9]{32,48}\b/g,
|
|
27
|
+
replacement: "[KEY_REDACTED]"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "phone",
|
|
31
|
+
pattern: /(?:\+?\d{1,3}[-.\s]?)?\(?\d{2,4}\)?[-.\s]?\d{3,5}[-.\s]?\d{4}\b/g,
|
|
32
|
+
replacement: "[PHONE_REDACTED]"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "ipv4",
|
|
36
|
+
pattern: /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/g,
|
|
37
|
+
replacement: "[IP_REDACTED]"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "url_query_params",
|
|
41
|
+
pattern: /([?&](?:token|key|secret|auth|email|user|access_token|refresh_token|api_key|apikey|password|passwd|pwd)=[^&\s]+)/gi,
|
|
42
|
+
replacement: "[PARAM_REDACTED]"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "ssn",
|
|
46
|
+
pattern: /\b\d{3}[-\s]?\d{2}[-\s]?\d{4}\b/g,
|
|
47
|
+
replacement: "[SSN_REDACTED]"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "credit_card",
|
|
51
|
+
pattern: /\b(?:\d[ -]?){12,18}\d\b/g,
|
|
52
|
+
replacement: "[CC_REDACTED]"
|
|
53
|
+
}
|
|
18
54
|
];
|
|
19
|
-
function
|
|
55
|
+
function A(t, e = 1e3) {
|
|
20
56
|
if (!t) return "";
|
|
21
57
|
let o = String(t);
|
|
22
|
-
return o.length > e && (o = o.slice(0, e)
|
|
58
|
+
return o.length > e && (o = `${o.slice(0, e)}... [TRUNCATED]`), Y.reduce((a, { pattern: i, replacement: n }) => a.replace(i, n), o);
|
|
23
59
|
}
|
|
24
|
-
function
|
|
60
|
+
function R(t) {
|
|
25
61
|
let e;
|
|
26
62
|
if (t.url)
|
|
27
63
|
try {
|
|
@@ -36,26 +72,26 @@ function _(t) {
|
|
|
36
72
|
o = /at (\w+)/.exec(a)?.[1];
|
|
37
73
|
}
|
|
38
74
|
return {
|
|
39
|
-
message:
|
|
75
|
+
message: A(t.message, 500),
|
|
40
76
|
httpStatus: t.httpStatus,
|
|
41
|
-
errorCode: t.errorCode ?
|
|
77
|
+
errorCode: t.errorCode ? A(t.errorCode, 100) : void 0,
|
|
42
78
|
routePath: e,
|
|
43
79
|
componentName: o
|
|
44
80
|
};
|
|
45
81
|
}
|
|
46
82
|
function f(...t) {
|
|
47
|
-
return
|
|
83
|
+
return K(J(t));
|
|
48
84
|
}
|
|
49
|
-
function
|
|
85
|
+
function N({
|
|
50
86
|
title: t,
|
|
51
87
|
description: e,
|
|
52
88
|
severity: o = "medium",
|
|
53
89
|
primaryAction: a,
|
|
54
|
-
secondaryAction:
|
|
90
|
+
secondaryAction: i,
|
|
55
91
|
theme: n,
|
|
56
|
-
className:
|
|
92
|
+
className: s
|
|
57
93
|
}) {
|
|
58
|
-
const
|
|
94
|
+
const l = o === "high";
|
|
59
95
|
return /* @__PURE__ */ r(
|
|
60
96
|
"div",
|
|
61
97
|
{
|
|
@@ -65,7 +101,7 @@ function A({
|
|
|
65
101
|
"rounded-xl border p-4 transition-all shadow-sm",
|
|
66
102
|
!n?.backgroundColor && "bg-amber-50 border-amber-200/60 dark:bg-amber-950/20 dark:border-amber-900/40",
|
|
67
103
|
n?.fontFamily,
|
|
68
|
-
|
|
104
|
+
s
|
|
69
105
|
),
|
|
70
106
|
style: {
|
|
71
107
|
backgroundColor: n?.backgroundColor,
|
|
@@ -73,7 +109,7 @@ function A({
|
|
|
73
109
|
borderColor: n?.primaryColor ? `${n.primaryColor}40` : void 0
|
|
74
110
|
},
|
|
75
111
|
children: /* @__PURE__ */ u("div", { className: "flex gap-3", children: [
|
|
76
|
-
/* @__PURE__ */ r("div", { className: "shrink-0 mt-0.5", children:
|
|
112
|
+
/* @__PURE__ */ r("div", { className: "shrink-0 mt-0.5", children: l ? /* @__PURE__ */ r(y, { className: "h-5 w-5 text-red-500" }) : /* @__PURE__ */ r(C, { className: "h-5 w-5 text-amber-500" }) }),
|
|
77
113
|
/* @__PURE__ */ u("div", { className: "flex-1 min-w-0", children: [
|
|
78
114
|
/* @__PURE__ */ r(
|
|
79
115
|
"h3",
|
|
@@ -91,11 +127,12 @@ function A({
|
|
|
91
127
|
children: e
|
|
92
128
|
}
|
|
93
129
|
),
|
|
94
|
-
(a ||
|
|
130
|
+
(a || i) && /* @__PURE__ */ u("div", { className: "mt-4 flex flex-wrap items-center gap-3", children: [
|
|
95
131
|
a && /* @__PURE__ */ r(
|
|
96
132
|
"button",
|
|
97
133
|
{
|
|
98
134
|
onClick: a.onClick,
|
|
135
|
+
type: "button",
|
|
99
136
|
style: n?.primaryColor ? { backgroundColor: n.primaryColor, color: "#fff" } : {},
|
|
100
137
|
className: f(
|
|
101
138
|
"text-xs font-medium px-3 py-1.5 rounded-lg transition-all active:scale-95",
|
|
@@ -105,13 +142,14 @@ function A({
|
|
|
105
142
|
children: a.label
|
|
106
143
|
}
|
|
107
144
|
),
|
|
108
|
-
|
|
145
|
+
i && /* @__PURE__ */ r(
|
|
109
146
|
"button",
|
|
110
147
|
{
|
|
111
|
-
|
|
148
|
+
type: "button",
|
|
149
|
+
onClick: i.onClick,
|
|
112
150
|
className: "text-xs font-medium opacity-70 hover:opacity-100 transition-opacity underline-offset-4 hover:underline",
|
|
113
151
|
style: { color: n?.textColor },
|
|
114
|
-
children:
|
|
152
|
+
children: i.label
|
|
115
153
|
}
|
|
116
154
|
)
|
|
117
155
|
] })
|
|
@@ -120,92 +158,177 @@ function A({
|
|
|
120
158
|
}
|
|
121
159
|
);
|
|
122
160
|
}
|
|
123
|
-
function
|
|
161
|
+
function E({
|
|
124
162
|
title: t,
|
|
125
163
|
description: e,
|
|
126
164
|
statusUrl: o,
|
|
127
165
|
showRefresh: a = !0,
|
|
128
|
-
isOpen:
|
|
166
|
+
isOpen: i,
|
|
129
167
|
onOpenChange: n,
|
|
130
|
-
theme:
|
|
131
|
-
onPrimaryAction:
|
|
132
|
-
primaryActionLabel:
|
|
168
|
+
theme: s,
|
|
169
|
+
onPrimaryAction: l,
|
|
170
|
+
primaryActionLabel: m = "Refresh the page"
|
|
133
171
|
}) {
|
|
134
|
-
const [
|
|
135
|
-
|
|
136
|
-
|
|
172
|
+
const [d, p] = P(!1);
|
|
173
|
+
T(() => {
|
|
174
|
+
p(!0);
|
|
137
175
|
}, []);
|
|
138
|
-
const b =
|
|
139
|
-
return
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
{
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
"md:max-w-md md:rounded-2xl md:border md:border-zinc-200 md:dark:border-zinc-800"
|
|
156
|
-
),
|
|
157
|
-
style: { boxSizing: "border-box" },
|
|
158
|
-
children: [
|
|
159
|
-
/* @__PURE__ */ r("div", { className: "mx-auto w-12 h-1.5 rounded-full bg-zinc-200 dark:bg-zinc-800 mb-6 md:hidden" }),
|
|
160
|
-
/* @__PURE__ */ r("div", { className: "w-16 h-16 rounded-full flex items-center justify-center mb-6 border bg-red-50 border-red-100 dark:bg-red-500/10 dark:border-red-500/20", children: /* @__PURE__ */ r(F, { className: "w-8 h-8 text-red-600 dark:text-red-500" }) }),
|
|
161
|
-
/* @__PURE__ */ r(k.Title, { className: "text-xl font-semibold text-zinc-900 dark:text-zinc-50 mb-3 tracking-tight", children: t }),
|
|
162
|
-
/* @__PURE__ */ r(k.Description, { className: "text-sm leading-relaxed mb-8 max-w-[280px] md:max-w-none text-zinc-600 dark:text-zinc-400", children: e }),
|
|
163
|
-
/* @__PURE__ */ u("div", { className: "flex flex-col w-full gap-3", children: [
|
|
164
|
-
a && /* @__PURE__ */ u(
|
|
165
|
-
"button",
|
|
166
|
-
{
|
|
167
|
-
onClick: () => d ? d() : window.location.reload(),
|
|
168
|
-
style: p ? { backgroundColor: p, borderColor: p } : {},
|
|
169
|
-
className: f(
|
|
170
|
-
"flex items-center justify-center gap-2 w-full py-3 px-4 rounded-xl font-medium transition-all shadow-sm",
|
|
171
|
-
p ? "text-white hover:opacity-90 hover:scale-[1.02] active:scale-95" : "bg-zinc-900 text-white hover:bg-zinc-800 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white hover:scale-[1.02] active:scale-95"
|
|
172
|
-
),
|
|
173
|
-
children: [
|
|
174
|
-
/* @__PURE__ */ r(L, { className: "w-4 h-4" }),
|
|
175
|
-
c
|
|
176
|
-
]
|
|
177
|
-
}
|
|
176
|
+
const b = s === "dark" || typeof s == "object" && s?.backgroundColor === "dark", c = typeof s == "object" ? s.primaryColor : void 0, v = typeof s == "object" ? s.fontFamily : void 0;
|
|
177
|
+
return d ? /* @__PURE__ */ r(g.Root, { open: i, onOpenChange: n, children: /* @__PURE__ */ r(g.Portal, { children: /* @__PURE__ */ u(
|
|
178
|
+
"div",
|
|
179
|
+
{
|
|
180
|
+
className: `cognicatch-ui-wrapper ${b ? "dark" : ""} ${v || ""}`,
|
|
181
|
+
children: [
|
|
182
|
+
/* @__PURE__ */ r(g.Overlay, { className: "radix-overlay fixed inset-0 z-[99999] bg-zinc-900/20 dark:bg-black/80 backdrop-blur-sm" }),
|
|
183
|
+
/* @__PURE__ */ r("div", { className: "fixed inset-0 z-[999999] flex items-end md:items-center justify-center pointer-events-none md:p-4", children: /* @__PURE__ */ u(
|
|
184
|
+
g.Content,
|
|
185
|
+
{
|
|
186
|
+
onInteractOutside: (k) => k.preventDefault(),
|
|
187
|
+
onEscapeKeyDown: (k) => k.preventDefault(),
|
|
188
|
+
className: f(
|
|
189
|
+
"pointer-events-auto w-full flex flex-col items-center text-center shadow-2xl transition-all",
|
|
190
|
+
"bg-white dark:bg-zinc-950",
|
|
191
|
+
"rounded-t-3xl border-t border-zinc-200 dark:border-zinc-800 p-8 pb-10",
|
|
192
|
+
"md:max-w-md md:rounded-2xl md:border md:border-zinc-200 md:dark:border-zinc-800"
|
|
178
193
|
),
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
{
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
"
|
|
194
|
+
style: { boxSizing: "border-box" },
|
|
195
|
+
children: [
|
|
196
|
+
/* @__PURE__ */ r("div", { className: "mx-auto w-12 h-1.5 rounded-full bg-zinc-200 dark:bg-zinc-800 mb-6 md:hidden" }),
|
|
197
|
+
/* @__PURE__ */ r("div", { className: "w-16 h-16 rounded-full flex items-center justify-center mb-6 border bg-red-50 border-red-100 dark:bg-red-500/10 dark:border-red-500/20", children: /* @__PURE__ */ r(U, { className: "w-8 h-8 text-red-600 dark:text-red-500" }) }),
|
|
198
|
+
/* @__PURE__ */ r(g.Title, { className: "text-xl font-semibold text-zinc-900 dark:text-zinc-50 mb-3 tracking-tight", children: t }),
|
|
199
|
+
/* @__PURE__ */ r(g.Description, { className: "text-sm leading-relaxed mb-8 max-w-[280px] md:max-w-none text-zinc-600 dark:text-zinc-400", children: e }),
|
|
200
|
+
/* @__PURE__ */ u("div", { className: "flex flex-col w-full gap-3", children: [
|
|
201
|
+
a && /* @__PURE__ */ u(
|
|
202
|
+
"button",
|
|
203
|
+
{
|
|
204
|
+
onClick: () => l ? l() : window.location.reload(),
|
|
205
|
+
type: "button",
|
|
206
|
+
style: c ? {
|
|
207
|
+
backgroundColor: c,
|
|
208
|
+
borderColor: c
|
|
209
|
+
} : {},
|
|
210
|
+
className: f(
|
|
211
|
+
"flex items-center justify-center gap-2 w-full py-3 px-4 rounded-xl font-medium transition-all shadow-sm",
|
|
212
|
+
c ? "text-white hover:opacity-90 hover:scale-[1.02] active:scale-95" : "bg-zinc-900 text-white hover:bg-zinc-800 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white hover:scale-[1.02] active:scale-95"
|
|
213
|
+
),
|
|
214
|
+
children: [
|
|
215
|
+
/* @__PURE__ */ r(B, { className: "w-4 h-4" }),
|
|
216
|
+
m
|
|
217
|
+
]
|
|
218
|
+
}
|
|
188
219
|
),
|
|
189
|
-
|
|
190
|
-
"
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
220
|
+
o && /* @__PURE__ */ u(
|
|
221
|
+
"a",
|
|
222
|
+
{
|
|
223
|
+
href: o,
|
|
224
|
+
target: "_blank",
|
|
225
|
+
rel: "noopener noreferrer",
|
|
226
|
+
className: f(
|
|
227
|
+
"flex items-center justify-center gap-2 w-full py-3 px-4 rounded-xl font-medium transition-colors border border-transparent",
|
|
228
|
+
"text-zinc-500 hover:text-zinc-900 hover:bg-zinc-100 dark:text-zinc-400 dark:hover:text-zinc-200 dark:hover:bg-zinc-900 dark:hover:border-zinc-800"
|
|
229
|
+
),
|
|
230
|
+
children: [
|
|
231
|
+
"Check system status",
|
|
232
|
+
/* @__PURE__ */ r(O, { className: "w-4 h-4 opacity-70" })
|
|
233
|
+
]
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
] })
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
) })
|
|
240
|
+
]
|
|
241
|
+
}
|
|
242
|
+
) }) }) : null;
|
|
243
|
+
}
|
|
244
|
+
const w = M(
|
|
245
|
+
void 0
|
|
246
|
+
);
|
|
247
|
+
function re({
|
|
248
|
+
apiKey: t,
|
|
249
|
+
apiUrl: e,
|
|
250
|
+
language: o,
|
|
251
|
+
handleUserBilling: a = !1,
|
|
252
|
+
children: i
|
|
253
|
+
}) {
|
|
254
|
+
const n = I(
|
|
255
|
+
async (l, m) => {
|
|
256
|
+
const d = l instanceof Error ? l : new Error(String(l)), p = h.loading("Analyzing error context...", {
|
|
257
|
+
description: "Applying AI recovery heuristics..."
|
|
258
|
+
});
|
|
259
|
+
if (t === "sk_test_mock") {
|
|
260
|
+
setTimeout(() => {
|
|
261
|
+
h.info("Mock Mode Analysis", {
|
|
262
|
+
id: p,
|
|
263
|
+
description: "This is a mocked async recovery because sk_test_mock was used."
|
|
264
|
+
});
|
|
265
|
+
}, 1500);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
const b = {
|
|
270
|
+
message: d.message,
|
|
271
|
+
componentStack: d.stack,
|
|
272
|
+
url: typeof window < "u" ? window.location.href : void 0
|
|
273
|
+
}, c = R(b), v = e || "https://api.cognicatch.dev/v1/analyze-error", k = typeof navigator < "u" ? navigator.language : "en-US", D = o || k, S = m?.handleUserBilling !== void 0 ? m.handleUserBilling : a, z = await fetch(v, {
|
|
274
|
+
method: "POST",
|
|
275
|
+
headers: {
|
|
276
|
+
Authorization: `Bearer ${t}`,
|
|
277
|
+
"Content-Type": "application/json"
|
|
278
|
+
},
|
|
279
|
+
body: JSON.stringify({
|
|
280
|
+
error: c.message,
|
|
281
|
+
stack: c.componentName ? `Component: ${c.componentName}` : c.errorCode || "Async Error",
|
|
282
|
+
routePath: c.routePath,
|
|
283
|
+
language: D,
|
|
284
|
+
handleUserBilling: S
|
|
285
|
+
})
|
|
286
|
+
});
|
|
287
|
+
if (!z.ok) throw new Error("SaaS API Error");
|
|
288
|
+
const x = await z.json();
|
|
289
|
+
x && ((x.severity || x.level) === "low" ? h.info(x.title, {
|
|
290
|
+
id: p,
|
|
291
|
+
description: x.description
|
|
292
|
+
}) : h.error(x.title, {
|
|
293
|
+
id: p,
|
|
294
|
+
description: x.description
|
|
295
|
+
}));
|
|
296
|
+
} catch (b) {
|
|
297
|
+
console.error("AdaptiveUI API Request failed:", b), h.error("Analysis Failed", {
|
|
298
|
+
id: p,
|
|
299
|
+
description: "We couldn't reach the AI servers. Please try again later."
|
|
300
|
+
});
|
|
197
301
|
}
|
|
198
|
-
|
|
199
|
-
|
|
302
|
+
},
|
|
303
|
+
[t, e, o, a]
|
|
304
|
+
), s = F(
|
|
305
|
+
() => ({
|
|
306
|
+
apiKey: t,
|
|
307
|
+
apiUrl: e,
|
|
308
|
+
language: o,
|
|
309
|
+
handleUserBilling: a,
|
|
310
|
+
captureAsyncError: n
|
|
311
|
+
}),
|
|
312
|
+
[t, e, o, a, n]
|
|
313
|
+
);
|
|
314
|
+
return /* @__PURE__ */ r(w.Provider, { value: s, children: i });
|
|
315
|
+
}
|
|
316
|
+
function oe() {
|
|
317
|
+
const t = L(w);
|
|
318
|
+
if (!t)
|
|
319
|
+
throw new Error(
|
|
320
|
+
"❌ AdaptiveUI Developer Error: You tried to use the 'useAdaptive' hook outside of an <AdaptiveProvider>. Please wrap the root of your application (e.g., App.tsx or layout.tsx) with <AdaptiveProvider apiKey='YOUR_KEY'>"
|
|
321
|
+
);
|
|
322
|
+
return t;
|
|
200
323
|
}
|
|
201
|
-
function
|
|
324
|
+
function ae({
|
|
202
325
|
customTheme: t,
|
|
203
326
|
toastOptions: e,
|
|
204
327
|
position: o = "top-right",
|
|
205
328
|
...a
|
|
206
329
|
}) {
|
|
207
330
|
return /* @__PURE__ */ r(
|
|
208
|
-
|
|
331
|
+
W,
|
|
209
332
|
{
|
|
210
333
|
position: o,
|
|
211
334
|
containerAriaLabel: "Notifications",
|
|
@@ -220,8 +343,14 @@ function X({
|
|
|
220
343
|
t?.fontFamily,
|
|
221
344
|
e?.classNames?.toast
|
|
222
345
|
),
|
|
223
|
-
title: f(
|
|
224
|
-
|
|
346
|
+
title: f(
|
|
347
|
+
"font-medium text-sm text-zinc-900 dark:text-zinc-50",
|
|
348
|
+
e?.classNames?.title
|
|
349
|
+
),
|
|
350
|
+
description: f(
|
|
351
|
+
"mt-0.5 text-xs text-zinc-500 dark:text-zinc-400 line-clamp-2",
|
|
352
|
+
e?.classNames?.description
|
|
353
|
+
),
|
|
225
354
|
actionButton: f(
|
|
226
355
|
"font-medium rounded-lg transition-all px-3 py-1.5 border text-xs",
|
|
227
356
|
"bg-zinc-900 text-white border-transparent hover:scale-[1.02] active:scale-95",
|
|
@@ -240,25 +369,25 @@ function X({
|
|
|
240
369
|
}
|
|
241
370
|
);
|
|
242
371
|
}
|
|
243
|
-
function
|
|
372
|
+
function _(t, e, o, a, i = "medium") {
|
|
244
373
|
return h(t, {
|
|
245
374
|
description: e,
|
|
246
375
|
icon: {
|
|
247
|
-
low: /* @__PURE__ */ r(
|
|
376
|
+
low: /* @__PURE__ */ r(Z, { className: "w-5 h-5 text-blue-500" }),
|
|
248
377
|
medium: /* @__PURE__ */ r(C, { className: "w-5 h-5 text-amber-500" }),
|
|
249
378
|
high: /* @__PURE__ */ r(y, { className: "w-5 h-5 text-red-500" })
|
|
250
|
-
}[
|
|
251
|
-
duration:
|
|
379
|
+
}[i],
|
|
380
|
+
duration: i === "high" ? 8e3 : 5e3,
|
|
252
381
|
action: o ? {
|
|
253
382
|
label: o,
|
|
254
383
|
onClick: () => a?.()
|
|
255
384
|
} : void 0
|
|
256
385
|
});
|
|
257
386
|
}
|
|
258
|
-
const
|
|
387
|
+
const ne = {
|
|
259
388
|
success: (t, e) => h(t, {
|
|
260
389
|
description: e,
|
|
261
|
-
icon: /* @__PURE__ */ r(
|
|
390
|
+
icon: /* @__PURE__ */ r($, { className: "w-5 h-5 text-emerald-500" })
|
|
262
391
|
}),
|
|
263
392
|
error: (t, e) => h(t, {
|
|
264
393
|
description: e,
|
|
@@ -270,7 +399,7 @@ const ee = {
|
|
|
270
399
|
}),
|
|
271
400
|
loading: (t, e) => h.loading(t, { description: e }),
|
|
272
401
|
custom: (t, e, o) => {
|
|
273
|
-
h.custom((
|
|
402
|
+
h.custom(() => /* @__PURE__ */ r(
|
|
274
403
|
"div",
|
|
275
404
|
{
|
|
276
405
|
className: f("flex gap-3 p-4 shadow-2xl border", o.fontFamily),
|
|
@@ -287,88 +416,51 @@ const ee = {
|
|
|
287
416
|
}
|
|
288
417
|
));
|
|
289
418
|
}
|
|
290
|
-
},
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
}, [t, e, o]), n = T(() => ({
|
|
338
|
-
apiKey: t,
|
|
339
|
-
apiUrl: e,
|
|
340
|
-
language: o,
|
|
341
|
-
captureAsyncError: s
|
|
342
|
-
}), [t, e, o, s]);
|
|
343
|
-
return /* @__PURE__ */ r(w.Provider, { value: n, children: a });
|
|
344
|
-
}
|
|
345
|
-
function re() {
|
|
346
|
-
const t = M(w);
|
|
347
|
-
if (!t)
|
|
348
|
-
throw new Error(
|
|
349
|
-
"❌ AdaptiveUI Developer Error: You tried to use the 'useAdaptive' hook outside of an <AdaptiveProvider>. Please wrap the root of your application (e.g., App.tsx or layout.tsx) with <AdaptiveProvider apiKey='YOUR_KEY'>"
|
|
350
|
-
);
|
|
351
|
-
return t;
|
|
352
|
-
}
|
|
353
|
-
const K = ({ onRecover: t, theme: e }) => /* @__PURE__ */ r("div", { className: `p-6 rounded-xl border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 shadow-sm ${e === "dark" ? "dark" : ""}`, children: /* @__PURE__ */ u("div", { className: "flex flex-col items-center text-center gap-4", children: [
|
|
354
|
-
/* @__PURE__ */ r("div", { className: "p-3 rounded-full bg-red-50 dark:bg-red-900/20", children: /* @__PURE__ */ r("svg", { className: "w-6 h-6 text-red-600 dark:text-red-400", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ r("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) }) }),
|
|
355
|
-
/* @__PURE__ */ u("div", { children: [
|
|
356
|
-
/* @__PURE__ */ r("h3", { className: "text-sm font-semibold text-zinc-900 dark:text-zinc-100", children: "Component Unavailable" }),
|
|
357
|
-
/* @__PURE__ */ r("p", { className: "text-xs text-zinc-500 dark:text-zinc-400 mt-1", children: "An unexpected error occurred in the interface." })
|
|
358
|
-
] }),
|
|
359
|
-
/* @__PURE__ */ r(
|
|
360
|
-
"button",
|
|
361
|
-
{
|
|
362
|
-
onClick: t,
|
|
363
|
-
style: {
|
|
364
|
-
backgroundColor: e?.primaryColor || void 0
|
|
365
|
-
},
|
|
366
|
-
className: "px-4 py-2 text-xs font-medium bg-zinc-900 dark:bg-zinc-100 text-white dark:text-zinc-900 rounded-lg hover:opacity-90 transition-opacity",
|
|
367
|
-
children: "Try Reloading"
|
|
368
|
-
}
|
|
369
|
-
)
|
|
370
|
-
] }) });
|
|
371
|
-
class oe extends I {
|
|
419
|
+
}, q = ({ onRecover: t, theme: e }) => /* @__PURE__ */ r(
|
|
420
|
+
"div",
|
|
421
|
+
{
|
|
422
|
+
className: `p-6 rounded-xl border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 shadow-sm ${e === "dark" ? "dark" : ""}`,
|
|
423
|
+
children: /* @__PURE__ */ u("div", { className: "flex flex-col items-center text-center gap-4", children: [
|
|
424
|
+
/* @__PURE__ */ r("div", { className: "p-3 rounded-full bg-red-50 dark:bg-red-900/20", children: /* @__PURE__ */ r(
|
|
425
|
+
"svg",
|
|
426
|
+
{
|
|
427
|
+
className: "w-6 h-6 text-red-600 dark:text-red-400",
|
|
428
|
+
fill: "none",
|
|
429
|
+
viewBox: "0 0 24 24",
|
|
430
|
+
stroke: "currentColor",
|
|
431
|
+
role: "img",
|
|
432
|
+
"aria-label": "error icon",
|
|
433
|
+
children: /* @__PURE__ */ r(
|
|
434
|
+
"path",
|
|
435
|
+
{
|
|
436
|
+
strokeLinecap: "round",
|
|
437
|
+
strokeLinejoin: "round",
|
|
438
|
+
strokeWidth: 2,
|
|
439
|
+
d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
|
|
440
|
+
}
|
|
441
|
+
)
|
|
442
|
+
}
|
|
443
|
+
) }),
|
|
444
|
+
/* @__PURE__ */ u("div", { children: [
|
|
445
|
+
/* @__PURE__ */ r("h3", { className: "text-sm font-semibold text-zinc-900 dark:text-zinc-100", children: "Component Unavailable" }),
|
|
446
|
+
/* @__PURE__ */ r("p", { className: "text-xs text-zinc-500 dark:text-zinc-400 mt-1", children: "An unexpected error occurred in the interface." })
|
|
447
|
+
] }),
|
|
448
|
+
/* @__PURE__ */ r(
|
|
449
|
+
"button",
|
|
450
|
+
{
|
|
451
|
+
onClick: t,
|
|
452
|
+
type: "button",
|
|
453
|
+
style: {
|
|
454
|
+
backgroundColor: e?.primaryColor || void 0
|
|
455
|
+
},
|
|
456
|
+
className: "px-4 py-2 text-xs font-medium bg-zinc-900 dark:bg-zinc-100 text-white dark:text-zinc-900 rounded-lg hover:opacity-90 transition-opacity",
|
|
457
|
+
children: "Try Reloading"
|
|
458
|
+
}
|
|
459
|
+
)
|
|
460
|
+
] })
|
|
461
|
+
}
|
|
462
|
+
);
|
|
463
|
+
class ie extends j {
|
|
372
464
|
static contextType = w;
|
|
373
465
|
_isMounted = !1;
|
|
374
466
|
constructor(e) {
|
|
@@ -392,7 +484,7 @@ class oe extends I {
|
|
|
392
484
|
componentDidCatch(e, o) {
|
|
393
485
|
if (this.state.hasCrashedFallback) return;
|
|
394
486
|
const { mode: a } = this.props;
|
|
395
|
-
a === "manual" && this.props.severity === "low" &&
|
|
487
|
+
a === "manual" && this.props.severity === "low" && _(
|
|
396
488
|
this.props.title,
|
|
397
489
|
this.props.description,
|
|
398
490
|
this.props.actionLabel ?? void 0,
|
|
@@ -400,12 +492,14 @@ class oe extends I {
|
|
|
400
492
|
), a === "auto" && this._isMounted && (this.setState({ isProcessingAuto: !0 }), this.processAutoMode(e, o));
|
|
401
493
|
}
|
|
402
494
|
processAutoMode = async (e, o) => {
|
|
403
|
-
const a = this.props,
|
|
404
|
-
if (!
|
|
405
|
-
console.error(
|
|
495
|
+
const a = this.props, i = a.apiKey || this.context?.apiKey, n = a.apiUrl || this.context?.apiUrl, s = typeof navigator < "u" ? navigator.language : "en-US", l = a.language || this.context?.language || s;
|
|
496
|
+
if (!i) {
|
|
497
|
+
console.error(
|
|
498
|
+
"AdaptiveUI: Missing API Key for auto mode. Provide it via props or <AdaptiveProvider>."
|
|
499
|
+
), this._isMounted && this.setState({ isProcessingAuto: !1 });
|
|
406
500
|
return;
|
|
407
501
|
}
|
|
408
|
-
if (
|
|
502
|
+
if (i === "sk_test_mock") {
|
|
409
503
|
setTimeout(() => {
|
|
410
504
|
this._isMounted && this.setState({
|
|
411
505
|
isProcessingAuto: !1,
|
|
@@ -420,34 +514,34 @@ class oe extends I {
|
|
|
420
514
|
return;
|
|
421
515
|
}
|
|
422
516
|
try {
|
|
423
|
-
const
|
|
517
|
+
const m = {
|
|
424
518
|
message: e.message,
|
|
425
519
|
componentStack: o.componentStack || void 0,
|
|
426
520
|
url: typeof window < "u" ? window.location.href : void 0
|
|
427
|
-
},
|
|
521
|
+
}, d = R(m), b = await fetch(n || "https://api.cognicatch.dev/v1/analyze-error", {
|
|
428
522
|
method: "POST",
|
|
429
523
|
headers: {
|
|
430
|
-
Authorization: `Bearer ${
|
|
524
|
+
Authorization: `Bearer ${i}`,
|
|
431
525
|
"Content-Type": "application/json"
|
|
432
526
|
},
|
|
433
527
|
body: JSON.stringify({
|
|
434
|
-
error:
|
|
435
|
-
stack:
|
|
436
|
-
routePath:
|
|
437
|
-
language:
|
|
528
|
+
error: d.message,
|
|
529
|
+
stack: d.componentName ? `Component: ${d.componentName}` : "No stack",
|
|
530
|
+
routePath: d.routePath,
|
|
531
|
+
language: l
|
|
438
532
|
})
|
|
439
533
|
});
|
|
440
534
|
if (!b.ok)
|
|
441
535
|
throw new Error(`SaaS API returned ${b.status}`);
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
536
|
+
const c = await b.json();
|
|
537
|
+
c && this._isMounted && (c.severity === "low" ? (_(
|
|
538
|
+
c.title,
|
|
539
|
+
c.description,
|
|
540
|
+
c.actionLabel ?? void 0,
|
|
447
541
|
this.handleRecover
|
|
448
|
-
), this.setState({ isProcessingAuto: !1, aiData:
|
|
449
|
-
} catch (
|
|
450
|
-
console.error("AdaptiveUI AI Request failed:",
|
|
542
|
+
), this.setState({ isProcessingAuto: !1, aiData: c })) : this.setState({ isProcessingAuto: !1, aiData: c }));
|
|
543
|
+
} catch (m) {
|
|
544
|
+
console.error("AdaptiveUI AI Request failed:", m), this._isMounted && this.setState({
|
|
451
545
|
isProcessingAuto: !1,
|
|
452
546
|
aiData: {
|
|
453
547
|
severity: "medium",
|
|
@@ -459,12 +553,17 @@ class oe extends I {
|
|
|
459
553
|
}
|
|
460
554
|
};
|
|
461
555
|
handleRecover = () => {
|
|
462
|
-
this._isMounted && this.setState({
|
|
556
|
+
this._isMounted && this.setState({
|
|
557
|
+
hasError: !1,
|
|
558
|
+
error: null,
|
|
559
|
+
aiData: null,
|
|
560
|
+
hasCrashedFallback: !1
|
|
561
|
+
}), this.props.onRecover && this.props.onRecover();
|
|
463
562
|
};
|
|
464
563
|
render() {
|
|
465
564
|
if (this.state.hasCrashedFallback)
|
|
466
565
|
return /* @__PURE__ */ r(
|
|
467
|
-
|
|
566
|
+
q,
|
|
468
567
|
{
|
|
469
568
|
onRecover: this.handleRecover,
|
|
470
569
|
theme: this.props.theme
|
|
@@ -472,27 +571,37 @@ class oe extends I {
|
|
|
472
571
|
);
|
|
473
572
|
if (!this.state.hasError)
|
|
474
573
|
return this.props.children;
|
|
475
|
-
const { mode: e, theme: o, className: a, showRefresh:
|
|
574
|
+
const { mode: e, theme: o, className: a, showRefresh: i, statusUrl: n } = this.props;
|
|
476
575
|
if (e === "manual") {
|
|
477
|
-
const { severity:
|
|
576
|
+
const { severity: s, title: l, description: m, actionLabel: d } = this.props;
|
|
478
577
|
try {
|
|
479
|
-
if (
|
|
578
|
+
if (s === "high")
|
|
480
579
|
return /* @__PURE__ */ r(
|
|
481
|
-
|
|
580
|
+
E,
|
|
482
581
|
{
|
|
483
582
|
isOpen: !0,
|
|
484
|
-
onOpenChange: (
|
|
485
|
-
|
|
583
|
+
onOpenChange: (p) => {
|
|
584
|
+
p || this.handleRecover();
|
|
486
585
|
},
|
|
487
|
-
title:
|
|
488
|
-
description:
|
|
586
|
+
title: l,
|
|
587
|
+
description: m,
|
|
489
588
|
theme: o,
|
|
490
|
-
showRefresh:
|
|
589
|
+
showRefresh: i,
|
|
491
590
|
statusUrl: n
|
|
492
591
|
}
|
|
493
592
|
);
|
|
494
|
-
if (
|
|
495
|
-
|
|
593
|
+
if (s === "medium")
|
|
594
|
+
return /* @__PURE__ */ r(
|
|
595
|
+
N,
|
|
596
|
+
{
|
|
597
|
+
title: l,
|
|
598
|
+
description: m,
|
|
599
|
+
primaryAction: d ? { label: d, onClick: this.handleRecover } : void 0,
|
|
600
|
+
theme: o,
|
|
601
|
+
className: a
|
|
602
|
+
}
|
|
603
|
+
);
|
|
604
|
+
if (s === "low") return null;
|
|
496
605
|
} catch {
|
|
497
606
|
return this.setState({ hasCrashedFallback: !0 }), null;
|
|
498
607
|
}
|
|
@@ -504,26 +613,35 @@ class oe extends I {
|
|
|
504
613
|
/* @__PURE__ */ r("p", { className: "text-xs font-medium text-zinc-500 dark:text-zinc-400", children: "Analyzing error context..." })
|
|
505
614
|
] });
|
|
506
615
|
if (this.state.aiData) {
|
|
507
|
-
const { severity:
|
|
616
|
+
const { severity: s, title: l, description: m, actionLabel: d } = this.state.aiData;
|
|
508
617
|
try {
|
|
509
|
-
if (
|
|
618
|
+
if (s === "high")
|
|
510
619
|
return /* @__PURE__ */ r(
|
|
511
|
-
|
|
620
|
+
E,
|
|
512
621
|
{
|
|
513
622
|
isOpen: !0,
|
|
514
|
-
onOpenChange: (
|
|
515
|
-
|
|
623
|
+
onOpenChange: (p) => {
|
|
624
|
+
p || this.handleRecover();
|
|
516
625
|
},
|
|
517
|
-
title:
|
|
518
|
-
description:
|
|
626
|
+
title: l,
|
|
627
|
+
description: m,
|
|
519
628
|
theme: o,
|
|
520
|
-
showRefresh:
|
|
629
|
+
showRefresh: i,
|
|
521
630
|
statusUrl: n
|
|
522
631
|
}
|
|
523
632
|
);
|
|
524
|
-
if (
|
|
525
|
-
return /* @__PURE__ */ r(
|
|
526
|
-
|
|
633
|
+
if (s === "medium")
|
|
634
|
+
return /* @__PURE__ */ r(
|
|
635
|
+
N,
|
|
636
|
+
{
|
|
637
|
+
title: l,
|
|
638
|
+
description: m,
|
|
639
|
+
primaryAction: d ? { label: d, onClick: this.handleRecover } : void 0,
|
|
640
|
+
theme: o,
|
|
641
|
+
className: a
|
|
642
|
+
}
|
|
643
|
+
);
|
|
644
|
+
if (s === "low")
|
|
527
645
|
return null;
|
|
528
646
|
} catch {
|
|
529
647
|
return this.setState({ hasCrashedFallback: !0 }), null;
|
|
@@ -534,9 +652,9 @@ class oe extends I {
|
|
|
534
652
|
}
|
|
535
653
|
}
|
|
536
654
|
export {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
655
|
+
ie as AdaptiveErrorBoundary,
|
|
656
|
+
re as AdaptiveProvider,
|
|
657
|
+
ae as AdaptiveToastProvider,
|
|
658
|
+
ne as adaptiveToast,
|
|
659
|
+
oe as useAdaptive
|
|
542
660
|
};
|