@cognicatch/react 1.1.0 → 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 +17 -7
- package/dist/index.js +390 -253
- package/package.json +9 -4
package/dist/index.js
CHANGED
|
@@ -1,28 +1,63 @@
|
|
|
1
|
-
import { jsx as r, jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { AlertCircle as y, AlertTriangle as C, AlertOctagon as
|
|
4
|
-
import { clsx as
|
|
5
|
-
import { twMerge as
|
|
6
|
-
import { createPortal as $ } from "react-dom";
|
|
1
|
+
import { jsx as r, jsxs as u } from "react/jsx-runtime";
|
|
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";
|
|
7
6
|
import * as g from "@radix-ui/react-dialog";
|
|
8
|
-
import {
|
|
9
|
-
const
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
}
|
|
19
54
|
];
|
|
20
|
-
function
|
|
55
|
+
function A(t, e = 1e3) {
|
|
21
56
|
if (!t) return "";
|
|
22
57
|
let o = String(t);
|
|
23
|
-
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);
|
|
24
59
|
}
|
|
25
|
-
function
|
|
60
|
+
function R(t) {
|
|
26
61
|
let e;
|
|
27
62
|
if (t.url)
|
|
28
63
|
try {
|
|
@@ -37,23 +72,23 @@ function _(t) {
|
|
|
37
72
|
o = /at (\w+)/.exec(a)?.[1];
|
|
38
73
|
}
|
|
39
74
|
return {
|
|
40
|
-
message:
|
|
75
|
+
message: A(t.message, 500),
|
|
41
76
|
httpStatus: t.httpStatus,
|
|
42
|
-
errorCode: t.errorCode ?
|
|
77
|
+
errorCode: t.errorCode ? A(t.errorCode, 100) : void 0,
|
|
43
78
|
routePath: e,
|
|
44
79
|
componentName: o
|
|
45
80
|
};
|
|
46
81
|
}
|
|
47
82
|
function f(...t) {
|
|
48
|
-
return
|
|
83
|
+
return K(J(t));
|
|
49
84
|
}
|
|
50
|
-
function
|
|
85
|
+
function N({
|
|
51
86
|
title: t,
|
|
52
87
|
description: e,
|
|
53
88
|
severity: o = "medium",
|
|
54
89
|
primaryAction: a,
|
|
55
|
-
secondaryAction:
|
|
56
|
-
theme:
|
|
90
|
+
secondaryAction: i,
|
|
91
|
+
theme: n,
|
|
57
92
|
className: s
|
|
58
93
|
}) {
|
|
59
94
|
const l = o === "high";
|
|
@@ -64,23 +99,23 @@ function A({
|
|
|
64
99
|
"aria-live": "polite",
|
|
65
100
|
className: f(
|
|
66
101
|
"rounded-xl border p-4 transition-all shadow-sm",
|
|
67
|
-
!
|
|
68
|
-
|
|
102
|
+
!n?.backgroundColor && "bg-amber-50 border-amber-200/60 dark:bg-amber-950/20 dark:border-amber-900/40",
|
|
103
|
+
n?.fontFamily,
|
|
69
104
|
s
|
|
70
105
|
),
|
|
71
106
|
style: {
|
|
72
|
-
backgroundColor:
|
|
73
|
-
color:
|
|
74
|
-
borderColor:
|
|
107
|
+
backgroundColor: n?.backgroundColor,
|
|
108
|
+
color: n?.textColor,
|
|
109
|
+
borderColor: n?.primaryColor ? `${n.primaryColor}40` : void 0
|
|
75
110
|
},
|
|
76
|
-
children: /* @__PURE__ */
|
|
111
|
+
children: /* @__PURE__ */ u("div", { className: "flex gap-3", children: [
|
|
77
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" }) }),
|
|
78
|
-
/* @__PURE__ */
|
|
113
|
+
/* @__PURE__ */ u("div", { className: "flex-1 min-w-0", children: [
|
|
79
114
|
/* @__PURE__ */ r(
|
|
80
115
|
"h3",
|
|
81
116
|
{
|
|
82
117
|
className: "text-sm font-medium leading-none text-amber-900 dark:text-amber-100",
|
|
83
|
-
style: { color:
|
|
118
|
+
style: { color: n?.textColor },
|
|
84
119
|
children: t
|
|
85
120
|
}
|
|
86
121
|
),
|
|
@@ -88,16 +123,17 @@ function A({
|
|
|
88
123
|
"p",
|
|
89
124
|
{
|
|
90
125
|
className: "mt-2 text-sm leading-relaxed opacity-90",
|
|
91
|
-
style: { color:
|
|
126
|
+
style: { color: n?.textColor },
|
|
92
127
|
children: e
|
|
93
128
|
}
|
|
94
129
|
),
|
|
95
|
-
(a ||
|
|
130
|
+
(a || i) && /* @__PURE__ */ u("div", { className: "mt-4 flex flex-wrap items-center gap-3", children: [
|
|
96
131
|
a && /* @__PURE__ */ r(
|
|
97
132
|
"button",
|
|
98
133
|
{
|
|
99
134
|
onClick: a.onClick,
|
|
100
|
-
|
|
135
|
+
type: "button",
|
|
136
|
+
style: n?.primaryColor ? { backgroundColor: n.primaryColor, color: "#fff" } : {},
|
|
101
137
|
className: f(
|
|
102
138
|
"text-xs font-medium px-3 py-1.5 rounded-lg transition-all active:scale-95",
|
|
103
139
|
"bg-amber-100 border border-amber-200 text-amber-900 hover:bg-amber-200",
|
|
@@ -106,13 +142,14 @@ function A({
|
|
|
106
142
|
children: a.label
|
|
107
143
|
}
|
|
108
144
|
),
|
|
109
|
-
|
|
145
|
+
i && /* @__PURE__ */ r(
|
|
110
146
|
"button",
|
|
111
147
|
{
|
|
112
|
-
|
|
148
|
+
type: "button",
|
|
149
|
+
onClick: i.onClick,
|
|
113
150
|
className: "text-xs font-medium opacity-70 hover:opacity-100 transition-opacity underline-offset-4 hover:underline",
|
|
114
|
-
style: { color:
|
|
115
|
-
children:
|
|
151
|
+
style: { color: n?.textColor },
|
|
152
|
+
children: i.label
|
|
116
153
|
}
|
|
117
154
|
)
|
|
118
155
|
] })
|
|
@@ -121,94 +158,177 @@ function A({
|
|
|
121
158
|
}
|
|
122
159
|
);
|
|
123
160
|
}
|
|
124
|
-
function
|
|
161
|
+
function E({
|
|
125
162
|
title: t,
|
|
126
163
|
description: e,
|
|
127
164
|
statusUrl: o,
|
|
128
165
|
showRefresh: a = !0,
|
|
129
|
-
isOpen:
|
|
130
|
-
onOpenChange:
|
|
166
|
+
isOpen: i,
|
|
167
|
+
onOpenChange: n,
|
|
131
168
|
theme: s,
|
|
132
169
|
onPrimaryAction: l,
|
|
133
|
-
primaryActionLabel:
|
|
170
|
+
primaryActionLabel: m = "Refresh the page"
|
|
134
171
|
}) {
|
|
135
|
-
const [
|
|
136
|
-
|
|
137
|
-
|
|
172
|
+
const [d, p] = P(!1);
|
|
173
|
+
T(() => {
|
|
174
|
+
p(!0);
|
|
138
175
|
}, []);
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
className: "radix-overlay fixed inset-0 z-[99999] bg-zinc-900/20 dark:bg-black/80 backdrop-blur-sm"
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
"bottom-0 left-0 right-0 border-t rounded-t-3xl p-8 pb-10",
|
|
157
|
-
"sm:bottom-auto sm:top-1/2 sm:left-1/2 sm:-translate-x-1/2 sm:-translate-y-1/2 sm:w-full sm:max-w-md sm:rounded-2xl sm:border"
|
|
158
|
-
),
|
|
159
|
-
style: { boxSizing: "border-box" },
|
|
160
|
-
children: [
|
|
161
|
-
/* @__PURE__ */ r("div", { className: "mx-auto w-12 h-1.5 rounded-full bg-zinc-200 dark:bg-zinc-800 mb-6 sm:hidden" }),
|
|
162
|
-
/* @__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" }) }),
|
|
163
|
-
/* @__PURE__ */ r(g.Title, { className: "text-xl font-semibold text-zinc-900 dark:text-zinc-50 mb-3 tracking-tight", children: t }),
|
|
164
|
-
/* @__PURE__ */ r(g.Description, { className: "text-sm leading-relaxed mb-8 max-w-[280px] sm:max-w-none text-zinc-600 dark:text-zinc-400", children: e }),
|
|
165
|
-
/* @__PURE__ */ m("div", { className: "flex flex-col w-full gap-3", children: [
|
|
166
|
-
a && /* @__PURE__ */ m(
|
|
167
|
-
"button",
|
|
168
|
-
{
|
|
169
|
-
onClick: () => l ? l() : window.location.reload(),
|
|
170
|
-
style: d ? { backgroundColor: d, borderColor: d } : {},
|
|
171
|
-
className: f(
|
|
172
|
-
"flex items-center justify-center gap-2 w-full py-3 px-4 rounded-xl font-medium transition-all shadow-sm",
|
|
173
|
-
d ? "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"
|
|
174
|
-
),
|
|
175
|
-
children: [
|
|
176
|
-
/* @__PURE__ */ r(L, { className: "w-4 h-4" }),
|
|
177
|
-
c
|
|
178
|
-
]
|
|
179
|
-
}
|
|
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"
|
|
180
193
|
),
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
{
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
"
|
|
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
|
+
}
|
|
190
219
|
),
|
|
191
|
-
|
|
192
|
-
"
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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;
|
|
199
267
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
+
});
|
|
301
|
+
}
|
|
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;
|
|
203
323
|
}
|
|
204
|
-
function
|
|
324
|
+
function ae({
|
|
205
325
|
customTheme: t,
|
|
206
326
|
toastOptions: e,
|
|
207
327
|
position: o = "top-right",
|
|
208
328
|
...a
|
|
209
329
|
}) {
|
|
210
330
|
return /* @__PURE__ */ r(
|
|
211
|
-
|
|
331
|
+
W,
|
|
212
332
|
{
|
|
213
333
|
position: o,
|
|
214
334
|
containerAriaLabel: "Notifications",
|
|
@@ -223,8 +343,14 @@ function te({
|
|
|
223
343
|
t?.fontFamily,
|
|
224
344
|
e?.classNames?.toast
|
|
225
345
|
),
|
|
226
|
-
title: f(
|
|
227
|
-
|
|
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
|
+
),
|
|
228
354
|
actionButton: f(
|
|
229
355
|
"font-medium rounded-lg transition-all px-3 py-1.5 border text-xs",
|
|
230
356
|
"bg-zinc-900 text-white border-transparent hover:scale-[1.02] active:scale-95",
|
|
@@ -243,37 +369,37 @@ function te({
|
|
|
243
369
|
}
|
|
244
370
|
);
|
|
245
371
|
}
|
|
246
|
-
function
|
|
247
|
-
return
|
|
372
|
+
function _(t, e, o, a, i = "medium") {
|
|
373
|
+
return h(t, {
|
|
248
374
|
description: e,
|
|
249
375
|
icon: {
|
|
250
|
-
low: /* @__PURE__ */ r(
|
|
376
|
+
low: /* @__PURE__ */ r(Z, { className: "w-5 h-5 text-blue-500" }),
|
|
251
377
|
medium: /* @__PURE__ */ r(C, { className: "w-5 h-5 text-amber-500" }),
|
|
252
378
|
high: /* @__PURE__ */ r(y, { className: "w-5 h-5 text-red-500" })
|
|
253
|
-
}[
|
|
254
|
-
duration:
|
|
379
|
+
}[i],
|
|
380
|
+
duration: i === "high" ? 8e3 : 5e3,
|
|
255
381
|
action: o ? {
|
|
256
382
|
label: o,
|
|
257
383
|
onClick: () => a?.()
|
|
258
384
|
} : void 0
|
|
259
385
|
});
|
|
260
386
|
}
|
|
261
|
-
const
|
|
262
|
-
success: (t, e) =>
|
|
387
|
+
const ne = {
|
|
388
|
+
success: (t, e) => h(t, {
|
|
263
389
|
description: e,
|
|
264
|
-
icon: /* @__PURE__ */ r(
|
|
390
|
+
icon: /* @__PURE__ */ r($, { className: "w-5 h-5 text-emerald-500" })
|
|
265
391
|
}),
|
|
266
|
-
error: (t, e) =>
|
|
392
|
+
error: (t, e) => h(t, {
|
|
267
393
|
description: e,
|
|
268
394
|
icon: /* @__PURE__ */ r(y, { className: "w-5 h-5 text-red-500" })
|
|
269
395
|
}),
|
|
270
|
-
warning: (t, e) =>
|
|
396
|
+
warning: (t, e) => h(t, {
|
|
271
397
|
description: e,
|
|
272
398
|
icon: /* @__PURE__ */ r(C, { className: "w-5 h-5 text-amber-500 dark:text-amber-400" })
|
|
273
399
|
}),
|
|
274
|
-
loading: (t, e) =>
|
|
400
|
+
loading: (t, e) => h.loading(t, { description: e }),
|
|
275
401
|
custom: (t, e, o) => {
|
|
276
|
-
|
|
402
|
+
h.custom(() => /* @__PURE__ */ r(
|
|
277
403
|
"div",
|
|
278
404
|
{
|
|
279
405
|
className: f("flex gap-3 p-4 shadow-2xl border", o.fontFamily),
|
|
@@ -283,96 +409,58 @@ const re = {
|
|
|
283
409
|
borderColor: o.primaryColor || "#e4e4e7",
|
|
284
410
|
borderRadius: o.borderRadius || "12px"
|
|
285
411
|
},
|
|
286
|
-
children: /* @__PURE__ */
|
|
412
|
+
children: /* @__PURE__ */ u("div", { className: "flex flex-col gap-1", children: [
|
|
287
413
|
/* @__PURE__ */ r("span", { className: "font-semibold text-sm", children: t }),
|
|
288
414
|
/* @__PURE__ */ r("span", { className: "text-xs opacity-70", children: e })
|
|
289
415
|
] })
|
|
290
416
|
}
|
|
291
417
|
));
|
|
292
418
|
}
|
|
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
|
-
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
}, [t, e, o]), i = T(() => ({
|
|
341
|
-
apiKey: t,
|
|
342
|
-
apiUrl: e,
|
|
343
|
-
language: o,
|
|
344
|
-
captureAsyncError: n
|
|
345
|
-
}), [t, e, o, n]);
|
|
346
|
-
return /* @__PURE__ */ r(w.Provider, { value: i, children: a });
|
|
347
|
-
}
|
|
348
|
-
function ae() {
|
|
349
|
-
const t = M(w);
|
|
350
|
-
if (!t)
|
|
351
|
-
throw new Error(
|
|
352
|
-
"❌ 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'>"
|
|
353
|
-
);
|
|
354
|
-
return t;
|
|
355
|
-
}
|
|
356
|
-
const W = ({ 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__ */ m("div", { className: "flex flex-col items-center text-center gap-4", children: [
|
|
357
|
-
/* @__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" }) }) }),
|
|
358
|
-
/* @__PURE__ */ m("div", { children: [
|
|
359
|
-
/* @__PURE__ */ r("h3", { className: "text-sm font-semibold text-zinc-900 dark:text-zinc-100", children: "Component Unavailable" }),
|
|
360
|
-
/* @__PURE__ */ r("p", { className: "text-xs text-zinc-500 dark:text-zinc-400 mt-1", children: "An unexpected error occurred in the interface." })
|
|
361
|
-
] }),
|
|
362
|
-
/* @__PURE__ */ r(
|
|
363
|
-
"button",
|
|
364
|
-
{
|
|
365
|
-
onClick: t,
|
|
366
|
-
style: {
|
|
367
|
-
// Se o usuário definiu uma cor primária no objeto ThemeOptions, usamos aqui!
|
|
368
|
-
backgroundColor: e?.primaryColor || void 0
|
|
369
|
-
},
|
|
370
|
-
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",
|
|
371
|
-
children: "Try Reloading"
|
|
372
|
-
}
|
|
373
|
-
)
|
|
374
|
-
] }) });
|
|
375
|
-
class ne 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 {
|
|
376
464
|
static contextType = w;
|
|
377
465
|
_isMounted = !1;
|
|
378
466
|
constructor(e) {
|
|
@@ -396,7 +484,7 @@ class ne extends I {
|
|
|
396
484
|
componentDidCatch(e, o) {
|
|
397
485
|
if (this.state.hasCrashedFallback) return;
|
|
398
486
|
const { mode: a } = this.props;
|
|
399
|
-
a === "manual" && this.props.severity === "low" &&
|
|
487
|
+
a === "manual" && this.props.severity === "low" && _(
|
|
400
488
|
this.props.title,
|
|
401
489
|
this.props.description,
|
|
402
490
|
this.props.actionLabel ?? void 0,
|
|
@@ -404,12 +492,14 @@ class ne extends I {
|
|
|
404
492
|
), a === "auto" && this._isMounted && (this.setState({ isProcessingAuto: !0 }), this.processAutoMode(e, o));
|
|
405
493
|
}
|
|
406
494
|
processAutoMode = async (e, o) => {
|
|
407
|
-
const a = this.props,
|
|
408
|
-
if (!
|
|
409
|
-
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 });
|
|
410
500
|
return;
|
|
411
501
|
}
|
|
412
|
-
if (
|
|
502
|
+
if (i === "sk_test_mock") {
|
|
413
503
|
setTimeout(() => {
|
|
414
504
|
this._isMounted && this.setState({
|
|
415
505
|
isProcessingAuto: !1,
|
|
@@ -424,34 +514,34 @@ class ne extends I {
|
|
|
424
514
|
return;
|
|
425
515
|
}
|
|
426
516
|
try {
|
|
427
|
-
const
|
|
517
|
+
const m = {
|
|
428
518
|
message: e.message,
|
|
429
519
|
componentStack: o.componentStack || void 0,
|
|
430
520
|
url: typeof window < "u" ? window.location.href : void 0
|
|
431
|
-
},
|
|
521
|
+
}, d = R(m), b = await fetch(n || "https://api.cognicatch.dev/v1/analyze-error", {
|
|
432
522
|
method: "POST",
|
|
433
523
|
headers: {
|
|
434
|
-
Authorization: `Bearer ${
|
|
524
|
+
Authorization: `Bearer ${i}`,
|
|
435
525
|
"Content-Type": "application/json"
|
|
436
526
|
},
|
|
437
527
|
body: JSON.stringify({
|
|
438
|
-
error:
|
|
439
|
-
stack:
|
|
440
|
-
routePath:
|
|
528
|
+
error: d.message,
|
|
529
|
+
stack: d.componentName ? `Component: ${d.componentName}` : "No stack",
|
|
530
|
+
routePath: d.routePath,
|
|
441
531
|
language: l
|
|
442
532
|
})
|
|
443
533
|
});
|
|
444
|
-
if (!
|
|
445
|
-
throw new Error(`SaaS API returned ${
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
534
|
+
if (!b.ok)
|
|
535
|
+
throw new Error(`SaaS API returned ${b.status}`);
|
|
536
|
+
const c = await b.json();
|
|
537
|
+
c && this._isMounted && (c.severity === "low" ? (_(
|
|
538
|
+
c.title,
|
|
539
|
+
c.description,
|
|
540
|
+
c.actionLabel ?? void 0,
|
|
451
541
|
this.handleRecover
|
|
452
|
-
), this.setState({ isProcessingAuto: !1, aiData:
|
|
453
|
-
} catch (
|
|
454
|
-
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({
|
|
455
545
|
isProcessingAuto: !1,
|
|
456
546
|
aiData: {
|
|
457
547
|
severity: "medium",
|
|
@@ -463,12 +553,17 @@ class ne extends I {
|
|
|
463
553
|
}
|
|
464
554
|
};
|
|
465
555
|
handleRecover = () => {
|
|
466
|
-
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();
|
|
467
562
|
};
|
|
468
563
|
render() {
|
|
469
564
|
if (this.state.hasCrashedFallback)
|
|
470
565
|
return /* @__PURE__ */ r(
|
|
471
|
-
|
|
566
|
+
q,
|
|
472
567
|
{
|
|
473
568
|
onRecover: this.handleRecover,
|
|
474
569
|
theme: this.props.theme
|
|
@@ -476,35 +571,77 @@ class ne extends I {
|
|
|
476
571
|
);
|
|
477
572
|
if (!this.state.hasError)
|
|
478
573
|
return this.props.children;
|
|
479
|
-
const { mode: e, theme: o, className: a } = this.props;
|
|
574
|
+
const { mode: e, theme: o, className: a, showRefresh: i, statusUrl: n } = this.props;
|
|
480
575
|
if (e === "manual") {
|
|
481
|
-
const { severity:
|
|
576
|
+
const { severity: s, title: l, description: m, actionLabel: d } = this.props;
|
|
482
577
|
try {
|
|
483
|
-
if (
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
578
|
+
if (s === "high")
|
|
579
|
+
return /* @__PURE__ */ r(
|
|
580
|
+
E,
|
|
581
|
+
{
|
|
582
|
+
isOpen: !0,
|
|
583
|
+
onOpenChange: (p) => {
|
|
584
|
+
p || this.handleRecover();
|
|
585
|
+
},
|
|
586
|
+
title: l,
|
|
587
|
+
description: m,
|
|
588
|
+
theme: o,
|
|
589
|
+
showRefresh: i,
|
|
590
|
+
statusUrl: n
|
|
591
|
+
}
|
|
592
|
+
);
|
|
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;
|
|
488
605
|
} catch {
|
|
489
606
|
return this.setState({ hasCrashedFallback: !0 }), null;
|
|
490
607
|
}
|
|
491
608
|
}
|
|
492
609
|
if (e === "auto") {
|
|
493
610
|
if (this.state.isProcessingAuto)
|
|
494
|
-
return /* @__PURE__ */
|
|
611
|
+
return /* @__PURE__ */ u("div", { className: "w-full h-full min-h-[100px] rounded-xl border border-zinc-200/50 dark:border-zinc-800/50 bg-zinc-50/50 dark:bg-zinc-900/20 flex flex-col items-center justify-center p-6 animate-pulse", children: [
|
|
495
612
|
/* @__PURE__ */ r("div", { className: "w-5 h-5 border-2 border-zinc-400/30 dark:border-zinc-500/30 border-t-zinc-900 dark:border-t-zinc-100 rounded-full animate-spin mb-3" }),
|
|
496
613
|
/* @__PURE__ */ r("p", { className: "text-xs font-medium text-zinc-500 dark:text-zinc-400", children: "Analyzing error context..." })
|
|
497
614
|
] });
|
|
498
615
|
if (this.state.aiData) {
|
|
499
|
-
const { severity:
|
|
616
|
+
const { severity: s, title: l, description: m, actionLabel: d } = this.state.aiData;
|
|
500
617
|
try {
|
|
501
|
-
if (
|
|
502
|
-
return /* @__PURE__ */ r(
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
618
|
+
if (s === "high")
|
|
619
|
+
return /* @__PURE__ */ r(
|
|
620
|
+
E,
|
|
621
|
+
{
|
|
622
|
+
isOpen: !0,
|
|
623
|
+
onOpenChange: (p) => {
|
|
624
|
+
p || this.handleRecover();
|
|
625
|
+
},
|
|
626
|
+
title: l,
|
|
627
|
+
description: m,
|
|
628
|
+
theme: o,
|
|
629
|
+
showRefresh: i,
|
|
630
|
+
statusUrl: n
|
|
631
|
+
}
|
|
632
|
+
);
|
|
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")
|
|
508
645
|
return null;
|
|
509
646
|
} catch {
|
|
510
647
|
return this.setState({ hasCrashedFallback: !0 }), null;
|
|
@@ -515,9 +652,9 @@ class ne extends I {
|
|
|
515
652
|
}
|
|
516
653
|
}
|
|
517
654
|
export {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
655
|
+
ie as AdaptiveErrorBoundary,
|
|
656
|
+
re as AdaptiveProvider,
|
|
657
|
+
ae as AdaptiveToastProvider,
|
|
658
|
+
ne as adaptiveToast,
|
|
659
|
+
oe as useAdaptive
|
|
523
660
|
};
|