@howone/sdk 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +7 -21
- package/dist/index.d.ts +7 -21
- package/dist/index.js +151 -274
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -268
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/README.md +0 -129
package/dist/index.mjs
CHANGED
|
@@ -31,41 +31,32 @@ __export(auth_exports, {
|
|
|
31
31
|
useAuth: () => useAuth
|
|
32
32
|
});
|
|
33
33
|
import { useEffect, useState } from "react";
|
|
34
|
-
function
|
|
34
|
+
function setLocal(name, value) {
|
|
35
35
|
try {
|
|
36
|
-
if (typeof
|
|
37
|
-
if (
|
|
38
|
-
|
|
36
|
+
if (typeof window === "undefined" || !window?.localStorage) return;
|
|
37
|
+
if (value === null) {
|
|
38
|
+
window.localStorage.removeItem(name);
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
document.cookie = `${name}=${encodeURIComponent(value)}; Expires=${expires}; Path=/; SameSite=Lax`;
|
|
41
|
+
window.localStorage.setItem(name, value);
|
|
43
42
|
} catch (e) {
|
|
44
43
|
void e;
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
|
-
function
|
|
46
|
+
function getLocal(name) {
|
|
48
47
|
try {
|
|
49
|
-
if (typeof
|
|
50
|
-
|
|
51
|
-
return match ? decodeURIComponent(match[1]) : null;
|
|
48
|
+
if (typeof window === "undefined" || !window?.localStorage) return null;
|
|
49
|
+
return window.localStorage.getItem(name);
|
|
52
50
|
} catch (e) {
|
|
53
51
|
return null;
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
function setToken(token) {
|
|
57
55
|
try {
|
|
58
|
-
|
|
56
|
+
setLocal(AUTH_TOKEN_KEY, token);
|
|
59
57
|
} catch (e) {
|
|
60
58
|
void e;
|
|
61
59
|
}
|
|
62
|
-
if (!token) {
|
|
63
|
-
try {
|
|
64
|
-
notifyAuthStateChanged();
|
|
65
|
-
} catch {
|
|
66
|
-
}
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
60
|
try {
|
|
70
61
|
notifyAuthStateChanged();
|
|
71
62
|
} catch {
|
|
@@ -73,8 +64,8 @@ function setToken(token) {
|
|
|
73
64
|
}
|
|
74
65
|
function getToken() {
|
|
75
66
|
try {
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
67
|
+
const v = getLocal(AUTH_TOKEN_KEY);
|
|
68
|
+
if (v) return v;
|
|
78
69
|
} catch (e) {
|
|
79
70
|
void e;
|
|
80
71
|
}
|
|
@@ -229,26 +220,29 @@ var init_config = __esm({
|
|
|
229
220
|
});
|
|
230
221
|
|
|
231
222
|
// src/components/FloatingButton.tsx
|
|
223
|
+
import { Icon } from "@iconify/react/dist/iconify.js";
|
|
232
224
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
233
225
|
var FloatingButton = ({
|
|
234
226
|
text = "Made in Howone",
|
|
235
227
|
onClick,
|
|
236
228
|
className = ""
|
|
237
229
|
}) => {
|
|
238
|
-
return /* @__PURE__ */
|
|
230
|
+
return /* @__PURE__ */ jsx(
|
|
239
231
|
"button",
|
|
240
232
|
{
|
|
241
233
|
onClick,
|
|
234
|
+
id: "floating-howone-btn",
|
|
242
235
|
className: `fixed flex bg-white gap-2 items-center right-4 z-50 text-black px-3 py-2 rounded-lg shadow-lg transition-colors duration-200 ${className}`,
|
|
243
236
|
style: {
|
|
244
237
|
fontSize: "14px",
|
|
245
238
|
fontWeight: "bold",
|
|
246
239
|
bottom: "28px"
|
|
247
240
|
},
|
|
248
|
-
children: [
|
|
249
|
-
/* @__PURE__ */ jsx("img", { width: 20, src: "https://sxwxqoixnnklnpeutjrj.supabase.co/storage/v1/object/public/create-x/logo/logo-sm.svg", alt: "" }),
|
|
250
|
-
text
|
|
251
|
-
|
|
241
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
242
|
+
/* @__PURE__ */ jsx("img", { width: 20, className: "pointer-events-auto", src: "https://sxwxqoixnnklnpeutjrj.supabase.co/storage/v1/object/public/create-x/logo/logo-sm.svg", alt: "" }),
|
|
243
|
+
text,
|
|
244
|
+
/* @__PURE__ */ jsx(Icon, { icon: "mdi:close", className: "w-5 h-5 font-bold pointer-events-auto" })
|
|
245
|
+
] })
|
|
252
246
|
}
|
|
253
247
|
);
|
|
254
248
|
};
|
|
@@ -526,6 +520,30 @@ var UnifiedAuthService = class {
|
|
|
526
520
|
hashToken = null;
|
|
527
521
|
}
|
|
528
522
|
const finalToken = accessTokenQuery || token || hashToken;
|
|
523
|
+
if (!finalToken && window.top && window.top !== window) {
|
|
524
|
+
try {
|
|
525
|
+
const topHref = String(window.top.location.href || "");
|
|
526
|
+
if (topHref) {
|
|
527
|
+
const up = new URL(topHref);
|
|
528
|
+
const topSearch = new URLSearchParams(up.search);
|
|
529
|
+
const topToken = topSearch.get("access_token") || topSearch.get("token") || null;
|
|
530
|
+
if (topToken) {
|
|
531
|
+
this.saveAuthData(topToken);
|
|
532
|
+
try {
|
|
533
|
+
topSearch.delete("token");
|
|
534
|
+
topSearch.delete("access_token");
|
|
535
|
+
topSearch.delete("project_id");
|
|
536
|
+
up.search = topSearch.toString();
|
|
537
|
+
up.hash = "";
|
|
538
|
+
window.top.history.replaceState({}, document.title, up.toString());
|
|
539
|
+
} catch {
|
|
540
|
+
}
|
|
541
|
+
return { success: true, token: topToken };
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
} catch {
|
|
545
|
+
}
|
|
546
|
+
}
|
|
529
547
|
if (finalToken) {
|
|
530
548
|
let user = null;
|
|
531
549
|
if (userParam) {
|
|
@@ -537,8 +555,8 @@ var UnifiedAuthService = class {
|
|
|
537
555
|
this.saveAuthData(finalToken);
|
|
538
556
|
try {
|
|
539
557
|
const u = new URL(window.location.href);
|
|
540
|
-
u.searchParams.delete("token");
|
|
541
558
|
u.searchParams.delete("access_token");
|
|
559
|
+
u.searchParams.delete("project_id");
|
|
542
560
|
u.hash = "";
|
|
543
561
|
window.history.replaceState({}, document.title, u.toString());
|
|
544
562
|
} catch (e) {
|
|
@@ -583,9 +601,6 @@ var UnifiedAuthService = class {
|
|
|
583
601
|
return { valid: false };
|
|
584
602
|
}
|
|
585
603
|
}
|
|
586
|
-
/**
|
|
587
|
-
* 从本地存储获取认证数据
|
|
588
|
-
*/
|
|
589
604
|
getSavedAuthData() {
|
|
590
605
|
try {
|
|
591
606
|
let token = null;
|
|
@@ -887,6 +902,7 @@ function createArtifactsClient(req) {
|
|
|
887
902
|
init_auth();
|
|
888
903
|
init_config();
|
|
889
904
|
init_config();
|
|
905
|
+
init_auth();
|
|
890
906
|
var request = new request_default({
|
|
891
907
|
baseURL: "https://create-x-backend.fly.dev/api",
|
|
892
908
|
timeout: 6e4,
|
|
@@ -1022,6 +1038,15 @@ function createClient(opts) {
|
|
|
1022
1038
|
workflowRequest: ai,
|
|
1023
1039
|
// artifact helpers using artifacts-client
|
|
1024
1040
|
artifacts: createArtifactsClient(biz),
|
|
1041
|
+
me: async () => {
|
|
1042
|
+
try {
|
|
1043
|
+
const t = token ?? (opts?.auth?.getToken ? await opts.auth.getToken() : null) ?? getToken();
|
|
1044
|
+
if (!t) return null;
|
|
1045
|
+
return parseUserFromToken(t);
|
|
1046
|
+
} catch (_e2) {
|
|
1047
|
+
return null;
|
|
1048
|
+
}
|
|
1049
|
+
},
|
|
1025
1050
|
// auth helpers
|
|
1026
1051
|
auth: {
|
|
1027
1052
|
setToken: (t) => {
|
|
@@ -1057,7 +1082,7 @@ function createClient(opts) {
|
|
|
1057
1082
|
|
|
1058
1083
|
// src/components/auth/LoginForm.tsx
|
|
1059
1084
|
import { useState as useState2, useEffect as useEffect2 } from "react";
|
|
1060
|
-
import { Icon } from "@iconify/react";
|
|
1085
|
+
import { Icon as Icon2 } from "@iconify/react";
|
|
1061
1086
|
import { Loader2 } from "lucide-react";
|
|
1062
1087
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1063
1088
|
var LoginForm = ({
|
|
@@ -1211,7 +1236,7 @@ var LoginForm = ({
|
|
|
1211
1236
|
validationErrors.code && /* @__PURE__ */ jsx2("p", { className: "text-red-600 text-sm", children: validationErrors.code })
|
|
1212
1237
|
] }),
|
|
1213
1238
|
validationErrors.form && /* @__PURE__ */ jsx2("div", { className: "text-red-600 text-sm p-3 bg-red-50 rounded-md border border-red-200", children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center", children: [
|
|
1214
|
-
/* @__PURE__ */ jsx2(
|
|
1239
|
+
/* @__PURE__ */ jsx2(Icon2, { icon: "material-symbols:error", className: "text-red-600 mr-2" }),
|
|
1215
1240
|
/* @__PURE__ */ jsx2("span", { children: validationErrors.form })
|
|
1216
1241
|
] }) }),
|
|
1217
1242
|
/* @__PURE__ */ jsxs2(
|
|
@@ -1245,7 +1270,7 @@ var LoginForm = ({
|
|
|
1245
1270
|
},
|
|
1246
1271
|
disabled: isAnyLoading,
|
|
1247
1272
|
children: [
|
|
1248
|
-
isAnyLoading ? /* @__PURE__ */ jsx2(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx2(
|
|
1273
|
+
isAnyLoading ? /* @__PURE__ */ jsx2(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx2(Icon2, { icon: "flat-color-icons:google", className: "w-6 h-6 mr-2" }),
|
|
1249
1274
|
isAnyLoading ? "Connecting..." : "Log in with Google"
|
|
1250
1275
|
]
|
|
1251
1276
|
}
|
|
@@ -1262,7 +1287,7 @@ var LoginForm = ({
|
|
|
1262
1287
|
},
|
|
1263
1288
|
disabled: isAnyLoading,
|
|
1264
1289
|
children: [
|
|
1265
|
-
isAnyLoading ? /* @__PURE__ */ jsx2(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx2(
|
|
1290
|
+
isAnyLoading ? /* @__PURE__ */ jsx2(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx2(Icon2, { icon: "mdi:github", className: "w-6 h-6 mr-2" }),
|
|
1266
1291
|
isAnyLoading ? "Connecting..." : "Log in with GitHub"
|
|
1267
1292
|
]
|
|
1268
1293
|
}
|
|
@@ -1271,153 +1296,60 @@ var LoginForm = ({
|
|
|
1271
1296
|
] });
|
|
1272
1297
|
};
|
|
1273
1298
|
|
|
1274
|
-
// src/components/auth/
|
|
1299
|
+
// src/components/auth/AuthProvider.tsx
|
|
1300
|
+
import { createContext, useContext, useEffect as useEffect3, useState as useState3 } from "react";
|
|
1275
1301
|
init_auth();
|
|
1276
|
-
import { Navigate, useLocation } from "react-router-dom";
|
|
1277
1302
|
init_config();
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1303
|
+
|
|
1304
|
+
// src/components/ui/Loading.tsx
|
|
1305
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1306
|
+
var Loading = ({
|
|
1307
|
+
size = "md",
|
|
1308
|
+
text = "Loading...",
|
|
1309
|
+
className = "",
|
|
1310
|
+
fullScreen = false
|
|
1286
1311
|
}) => {
|
|
1287
|
-
const
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
try {
|
|
1299
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
1300
|
-
const tokenInUrl = urlParams.get("token") || urlParams.get("access_token");
|
|
1301
|
-
let tokenInHash = null;
|
|
1302
|
-
try {
|
|
1303
|
-
if (window.location.hash && window.location.hash.length > 1) {
|
|
1304
|
-
const hashParams = new URLSearchParams(window.location.hash.slice(1));
|
|
1305
|
-
tokenInHash = hashParams.get("access_token") || hashParams.get("token");
|
|
1306
|
-
}
|
|
1307
|
-
} catch {
|
|
1308
|
-
tokenInHash = null;
|
|
1309
|
-
}
|
|
1310
|
-
const localToken = getToken();
|
|
1311
|
-
if (tokenInUrl || tokenInHash) {
|
|
1312
|
-
try {
|
|
1313
|
-
const res = unifiedAuth.checkOAuthCallback();
|
|
1314
|
-
if (res && res.success) {
|
|
1315
|
-
return null;
|
|
1316
|
-
}
|
|
1317
|
-
} catch {
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
if (localToken) {
|
|
1321
|
-
return null;
|
|
1322
|
-
}
|
|
1323
|
-
} catch (e) {
|
|
1324
|
-
void e;
|
|
1325
|
-
}
|
|
1326
|
-
if (redirectTo === "/login") {
|
|
1327
|
-
const root = getAuthRoot() || "http://localhost:3000";
|
|
1328
|
-
try {
|
|
1329
|
-
const authUrl = new URL("/auth", String(root));
|
|
1330
|
-
authUrl.searchParams.set("redirect_uri", window.location.href);
|
|
1331
|
-
const pid = getDefaultProjectId();
|
|
1332
|
-
if (pid) authUrl.searchParams.set("project_id", pid);
|
|
1333
|
-
window.location.replace(authUrl.toString());
|
|
1334
|
-
} catch {
|
|
1335
|
-
window.location.replace(root);
|
|
1336
|
-
}
|
|
1337
|
-
return null;
|
|
1338
|
-
}
|
|
1339
|
-
return /* @__PURE__ */ jsx3(Navigate, { to: redirectTo, state: { from: location }, replace: true });
|
|
1340
|
-
}
|
|
1341
|
-
if (roles.length > 0 && user !== null) {
|
|
1342
|
-
const currentUser = user;
|
|
1343
|
-
if (currentUser.roles) {
|
|
1344
|
-
const hasRole = roles.some((role) => currentUser.roles.includes(role));
|
|
1345
|
-
if (!hasRole) {
|
|
1346
|
-
if (fallback) {
|
|
1347
|
-
return /* @__PURE__ */ jsx3(Fragment, { children: fallback });
|
|
1348
|
-
}
|
|
1349
|
-
return /* @__PURE__ */ jsx3("div", { className: "min-h-screen flex items-center justify-center", children: /* @__PURE__ */ jsxs3("div", { className: "text-center", children: [
|
|
1350
|
-
/* @__PURE__ */ jsx3("h1", { className: "text-2xl font-bold text-gray-900 mb-2", children: "Access Denied" }),
|
|
1351
|
-
/* @__PURE__ */ jsx3("p", { className: "text-gray-600", children: "You don't have the required role to access this page." })
|
|
1352
|
-
] }) });
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
if (permissions.length > 0 && user !== null) {
|
|
1357
|
-
const currentUser = user;
|
|
1358
|
-
if (currentUser.permissions) {
|
|
1359
|
-
const hasPermission = permissions.some((permission) => currentUser.permissions.includes(permission));
|
|
1360
|
-
if (!hasPermission) {
|
|
1361
|
-
if (fallback) {
|
|
1362
|
-
return /* @__PURE__ */ jsx3(Fragment, { children: fallback });
|
|
1363
|
-
}
|
|
1364
|
-
return /* @__PURE__ */ jsx3("div", { className: "min-h-screen flex items-center justify-center", children: /* @__PURE__ */ jsxs3("div", { className: "text-center", children: [
|
|
1365
|
-
/* @__PURE__ */ jsx3("h1", { className: "text-2xl font-bold text-gray-900 mb-2", children: "Access Denied" }),
|
|
1366
|
-
/* @__PURE__ */ jsx3("p", { className: "text-gray-600", children: "You don't have the required permission to access this page." })
|
|
1367
|
-
] }) });
|
|
1312
|
+
const sizeClasses = {
|
|
1313
|
+
sm: "h-4 w-4",
|
|
1314
|
+
md: "h-8 w-8",
|
|
1315
|
+
lg: "h-12 w-12"
|
|
1316
|
+
};
|
|
1317
|
+
const containerClasses = fullScreen ? "fixed inset-0 flex items-center justify-center bg-white/80 backdrop-blur-sm z-50" : "flex items-center justify-center p-4";
|
|
1318
|
+
return /* @__PURE__ */ jsx3("div", { className: `${containerClasses} ${className}`, children: /* @__PURE__ */ jsxs3("div", { className: "text-center", children: [
|
|
1319
|
+
/* @__PURE__ */ jsx3(
|
|
1320
|
+
"div",
|
|
1321
|
+
{
|
|
1322
|
+
className: `animate-spin rounded-full border-2 border-gray-300 border-t-blue-600 mx-auto ${sizeClasses[size]}`
|
|
1368
1323
|
}
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1324
|
+
),
|
|
1325
|
+
text && /* @__PURE__ */ jsx3("p", { className: "mt-2 text-sm text-gray-600", children: text })
|
|
1326
|
+
] }) });
|
|
1372
1327
|
};
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
try {
|
|
1387
|
-
const root = getAuthRoot() || "http://localhost:3000";
|
|
1388
|
-
const authUrl = new URL("/auth", String(root));
|
|
1389
|
-
authUrl.searchParams.set("redirect_uri", window.location.href);
|
|
1390
|
-
const pid = getDefaultProjectId && getDefaultProjectId();
|
|
1391
|
-
if (pid) authUrl.searchParams.set("project_id", pid);
|
|
1392
|
-
window.location.replace(authUrl.toString());
|
|
1393
|
-
} catch {
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
});
|
|
1397
|
-
return () => {
|
|
1398
|
-
try {
|
|
1399
|
-
unsubscribe();
|
|
1400
|
-
} catch {
|
|
1401
|
-
}
|
|
1402
|
-
};
|
|
1403
|
-
} catch {
|
|
1328
|
+
var LoadingSpinner = ({
|
|
1329
|
+
size = "md",
|
|
1330
|
+
className = ""
|
|
1331
|
+
}) => {
|
|
1332
|
+
const sizeClasses = {
|
|
1333
|
+
sm: "h-4 w-4",
|
|
1334
|
+
md: "h-8 w-8",
|
|
1335
|
+
lg: "h-12 w-12"
|
|
1336
|
+
};
|
|
1337
|
+
return /* @__PURE__ */ jsx3(
|
|
1338
|
+
"div",
|
|
1339
|
+
{
|
|
1340
|
+
className: `animate-spin rounded-full border-2 border-gray-300 border-t-blue-600 ${sizeClasses[size]} ${className}`
|
|
1404
1341
|
}
|
|
1405
|
-
|
|
1406
|
-
return /* @__PURE__ */ jsx4("div", { className: "min-h-screen flex items-center justify-center bg-white", children: fallback ?? /* @__PURE__ */ jsx4("div", { className: "text-center", children: /* @__PURE__ */ jsx4("h2", { className: "text-lg font-semibold", children: "Redirecting to authentication..." }) }) });
|
|
1342
|
+
);
|
|
1407
1343
|
};
|
|
1408
|
-
var AuthRedirector_default = AuthRedirector;
|
|
1409
1344
|
|
|
1410
1345
|
// src/components/auth/AuthProvider.tsx
|
|
1411
|
-
import {
|
|
1412
|
-
init_auth();
|
|
1413
|
-
init_config();
|
|
1414
|
-
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1346
|
+
import { Fragment, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1415
1347
|
var AuthContext = createContext(null);
|
|
1416
1348
|
var AuthProvider = ({ children, autoRedirect = true, showFloatingButton = true, projectId }) => {
|
|
1417
1349
|
const [user, setUser] = useState3(() => parseUserFromToken(getToken()));
|
|
1418
1350
|
const [token, setTokenState] = useState3(() => getToken());
|
|
1419
1351
|
const [isLoading, setIsLoading] = useState3(false);
|
|
1420
|
-
|
|
1352
|
+
useEffect3(() => {
|
|
1421
1353
|
try {
|
|
1422
1354
|
if (projectId) setDefaultProjectId(String(projectId));
|
|
1423
1355
|
} catch {
|
|
@@ -1447,7 +1379,18 @@ var AuthProvider = ({ children, autoRedirect = true, showFloatingButton = true,
|
|
|
1447
1379
|
authUrl.searchParams.set("redirect_uri", window.location.href);
|
|
1448
1380
|
const pid = getDefaultProjectId();
|
|
1449
1381
|
if (pid) authUrl.searchParams.set("project_id", pid);
|
|
1450
|
-
|
|
1382
|
+
try {
|
|
1383
|
+
if (window.top && window.top !== window) {
|
|
1384
|
+
window.top.location.replace(authUrl.toString());
|
|
1385
|
+
} else {
|
|
1386
|
+
window.location.replace(authUrl.toString());
|
|
1387
|
+
}
|
|
1388
|
+
} catch (e) {
|
|
1389
|
+
try {
|
|
1390
|
+
window.location.replace(authUrl.toString());
|
|
1391
|
+
} catch {
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1451
1394
|
} catch {
|
|
1452
1395
|
}
|
|
1453
1396
|
}
|
|
@@ -1471,13 +1414,15 @@ var AuthProvider = ({ children, autoRedirect = true, showFloatingButton = true,
|
|
|
1471
1414
|
user,
|
|
1472
1415
|
token,
|
|
1473
1416
|
isAuthenticated: !!token,
|
|
1474
|
-
isLoading,
|
|
1475
1417
|
logout
|
|
1476
1418
|
};
|
|
1477
|
-
return /* @__PURE__ */
|
|
1419
|
+
return /* @__PURE__ */ jsx4(AuthContext.Provider, { value, children: isLoading ? /* @__PURE__ */ jsxs4(Fragment, { children: [
|
|
1420
|
+
/* @__PURE__ */ jsx4(Loading, { fullScreen: true, text: "Checking authentication..." }),
|
|
1421
|
+
showFloatingButton && /* @__PURE__ */ jsx4(FloatingButton, { onClick: () => window.open("https://howone.ai", "_blank") })
|
|
1422
|
+
] }) : /* @__PURE__ */ jsxs4(Fragment, { children: [
|
|
1478
1423
|
children,
|
|
1479
|
-
showFloatingButton && /* @__PURE__ */
|
|
1480
|
-
] });
|
|
1424
|
+
showFloatingButton && /* @__PURE__ */ jsx4(FloatingButton, { onClick: () => window.open("https://howone.ai", "_blank") })
|
|
1425
|
+
] }) });
|
|
1481
1426
|
};
|
|
1482
1427
|
function useAuthContext() {
|
|
1483
1428
|
const ctx = useContext(AuthContext);
|
|
@@ -1487,7 +1432,6 @@ function useAuthContext() {
|
|
|
1487
1432
|
user: parseUserFromToken(t),
|
|
1488
1433
|
token: t,
|
|
1489
1434
|
isAuthenticated: !!t,
|
|
1490
|
-
isLoading: false,
|
|
1491
1435
|
logout: () => {
|
|
1492
1436
|
try {
|
|
1493
1437
|
setToken(null);
|
|
@@ -1547,9 +1491,23 @@ var HowoneAuthClient = class {
|
|
|
1547
1491
|
if (pid) authUrl.searchParams.set("project_id", String(pid));
|
|
1548
1492
|
} catch {
|
|
1549
1493
|
}
|
|
1550
|
-
|
|
1494
|
+
try {
|
|
1495
|
+
if (window.top && window.top !== window) {
|
|
1496
|
+
window.top.location.replace(authUrl.toString());
|
|
1497
|
+
} else {
|
|
1498
|
+
window.location.replace(authUrl.toString());
|
|
1499
|
+
}
|
|
1500
|
+
} catch {
|
|
1501
|
+
try {
|
|
1502
|
+
window.location.replace(String(root));
|
|
1503
|
+
} catch {
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1551
1506
|
} catch {
|
|
1552
|
-
|
|
1507
|
+
try {
|
|
1508
|
+
window.location.replace(String(root));
|
|
1509
|
+
} catch {
|
|
1510
|
+
}
|
|
1553
1511
|
}
|
|
1554
1512
|
}
|
|
1555
1513
|
logout() {
|
|
@@ -1570,50 +1528,9 @@ var howone = {
|
|
|
1570
1528
|
};
|
|
1571
1529
|
var client_default = howone;
|
|
1572
1530
|
|
|
1573
|
-
// src/components/ui/Loading.tsx
|
|
1574
|
-
import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1575
|
-
var Loading = ({
|
|
1576
|
-
size = "md",
|
|
1577
|
-
text = "Loading...",
|
|
1578
|
-
className = "",
|
|
1579
|
-
fullScreen = false
|
|
1580
|
-
}) => {
|
|
1581
|
-
const sizeClasses = {
|
|
1582
|
-
sm: "h-4 w-4",
|
|
1583
|
-
md: "h-8 w-8",
|
|
1584
|
-
lg: "h-12 w-12"
|
|
1585
|
-
};
|
|
1586
|
-
const containerClasses = fullScreen ? "fixed inset-0 flex items-center justify-center bg-white/80 backdrop-blur-sm z-50" : "flex items-center justify-center p-4";
|
|
1587
|
-
return /* @__PURE__ */ jsx6("div", { className: `${containerClasses} ${className}`, children: /* @__PURE__ */ jsxs5("div", { className: "text-center", children: [
|
|
1588
|
-
/* @__PURE__ */ jsx6(
|
|
1589
|
-
"div",
|
|
1590
|
-
{
|
|
1591
|
-
className: `animate-spin rounded-full border-2 border-gray-300 border-t-blue-600 mx-auto ${sizeClasses[size]}`
|
|
1592
|
-
}
|
|
1593
|
-
),
|
|
1594
|
-
text && /* @__PURE__ */ jsx6("p", { className: "mt-2 text-sm text-gray-600", children: text })
|
|
1595
|
-
] }) });
|
|
1596
|
-
};
|
|
1597
|
-
var LoadingSpinner = ({
|
|
1598
|
-
size = "md",
|
|
1599
|
-
className = ""
|
|
1600
|
-
}) => {
|
|
1601
|
-
const sizeClasses = {
|
|
1602
|
-
sm: "h-4 w-4",
|
|
1603
|
-
md: "h-8 w-8",
|
|
1604
|
-
lg: "h-12 w-12"
|
|
1605
|
-
};
|
|
1606
|
-
return /* @__PURE__ */ jsx6(
|
|
1607
|
-
"div",
|
|
1608
|
-
{
|
|
1609
|
-
className: `animate-spin rounded-full border-2 border-gray-300 border-t-blue-600 ${sizeClasses[size]} ${className}`
|
|
1610
|
-
}
|
|
1611
|
-
);
|
|
1612
|
-
};
|
|
1613
|
-
|
|
1614
1531
|
// src/components/ui/ErrorBoundary.tsx
|
|
1615
1532
|
import { Component } from "react";
|
|
1616
|
-
import { jsx as
|
|
1533
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1617
1534
|
var ErrorBoundary = class extends Component {
|
|
1618
1535
|
constructor(props) {
|
|
1619
1536
|
super(props);
|
|
@@ -1636,13 +1553,13 @@ var ErrorBoundary = class extends Component {
|
|
|
1636
1553
|
if (this.state.hasError) {
|
|
1637
1554
|
if (this.props.fallback) {
|
|
1638
1555
|
const FallbackComponent = this.props.fallback;
|
|
1639
|
-
return /* @__PURE__ */
|
|
1556
|
+
return /* @__PURE__ */ jsx5(FallbackComponent, { error: this.state.error, retry: this.handleRetry });
|
|
1640
1557
|
}
|
|
1641
|
-
return /* @__PURE__ */
|
|
1642
|
-
/* @__PURE__ */
|
|
1643
|
-
/* @__PURE__ */
|
|
1644
|
-
/* @__PURE__ */
|
|
1645
|
-
/* @__PURE__ */
|
|
1558
|
+
return /* @__PURE__ */ jsx5("div", { className: "min-h-[400px] flex items-center justify-center p-4", children: /* @__PURE__ */ jsxs5("div", { className: "text-center max-w-md", children: [
|
|
1559
|
+
/* @__PURE__ */ jsx5("div", { className: "text-red-500 text-6xl mb-4", children: "\u26A0\uFE0F" }),
|
|
1560
|
+
/* @__PURE__ */ jsx5("h2", { className: "text-xl font-semibold text-gray-900 mb-2", children: "Something went wrong" }),
|
|
1561
|
+
/* @__PURE__ */ jsx5("p", { className: "text-gray-600 mb-4", children: "An unexpected error occurred. Please try refreshing the page." }),
|
|
1562
|
+
/* @__PURE__ */ jsx5(
|
|
1646
1563
|
"button",
|
|
1647
1564
|
{
|
|
1648
1565
|
onClick: this.handleRetry,
|
|
@@ -1656,10 +1573,10 @@ var ErrorBoundary = class extends Component {
|
|
|
1656
1573
|
return this.props.children;
|
|
1657
1574
|
}
|
|
1658
1575
|
};
|
|
1659
|
-
var DefaultErrorFallback = ({ retry }) => /* @__PURE__ */
|
|
1660
|
-
/* @__PURE__ */
|
|
1661
|
-
/* @__PURE__ */
|
|
1662
|
-
retry && /* @__PURE__ */
|
|
1576
|
+
var DefaultErrorFallback = ({ retry }) => /* @__PURE__ */ jsx5("div", { className: "min-h-[200px] flex items-center justify-center p-4", children: /* @__PURE__ */ jsxs5("div", { className: "text-center", children: [
|
|
1577
|
+
/* @__PURE__ */ jsx5("div", { className: "text-red-500 text-4xl mb-2", children: "\u26A0\uFE0F" }),
|
|
1578
|
+
/* @__PURE__ */ jsx5("p", { className: "text-gray-600 mb-2", children: "Something went wrong" }),
|
|
1579
|
+
retry && /* @__PURE__ */ jsx5(
|
|
1663
1580
|
"button",
|
|
1664
1581
|
{
|
|
1665
1582
|
onClick: retry,
|
|
@@ -1670,11 +1587,11 @@ var DefaultErrorFallback = ({ retry }) => /* @__PURE__ */ jsx7("div", { classNam
|
|
|
1670
1587
|
] }) });
|
|
1671
1588
|
|
|
1672
1589
|
// src/hooks/use-mobile.ts
|
|
1673
|
-
import * as
|
|
1590
|
+
import * as React4 from "react";
|
|
1674
1591
|
var MOBILE_BREAKPOINT = 768;
|
|
1675
1592
|
function useIsMobile() {
|
|
1676
|
-
const [isMobile, setIsMobile] =
|
|
1677
|
-
|
|
1593
|
+
const [isMobile, setIsMobile] = React4.useState(void 0);
|
|
1594
|
+
React4.useEffect(() => {
|
|
1678
1595
|
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
|
1679
1596
|
const onChange = () => {
|
|
1680
1597
|
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
@@ -1686,43 +1603,11 @@ function useIsMobile() {
|
|
|
1686
1603
|
return !!isMobile;
|
|
1687
1604
|
}
|
|
1688
1605
|
|
|
1689
|
-
// src/hooks/use-local-storage.ts
|
|
1690
|
-
import { useState as useState5 } from "react";
|
|
1691
|
-
function useLocalStorage(key, initialValue) {
|
|
1692
|
-
const [storedValue, setStoredValue] = useState5(() => {
|
|
1693
|
-
try {
|
|
1694
|
-
const item = window.localStorage.getItem(key);
|
|
1695
|
-
return item ? JSON.parse(item) : initialValue;
|
|
1696
|
-
} catch (error) {
|
|
1697
|
-
console.error(`Error reading localStorage key "${key}":`, error);
|
|
1698
|
-
return initialValue;
|
|
1699
|
-
}
|
|
1700
|
-
});
|
|
1701
|
-
const setValue = (value) => {
|
|
1702
|
-
try {
|
|
1703
|
-
const valueToStore = value instanceof Function ? value(storedValue) : value;
|
|
1704
|
-
setStoredValue(valueToStore);
|
|
1705
|
-
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
1706
|
-
} catch (error) {
|
|
1707
|
-
console.error(`Error setting localStorage key "${key}":`, error);
|
|
1708
|
-
}
|
|
1709
|
-
};
|
|
1710
|
-
const removeValue = () => {
|
|
1711
|
-
try {
|
|
1712
|
-
window.localStorage.removeItem(key);
|
|
1713
|
-
setStoredValue(initialValue);
|
|
1714
|
-
} catch (error) {
|
|
1715
|
-
console.error(`Error removing localStorage key "${key}":`, error);
|
|
1716
|
-
}
|
|
1717
|
-
};
|
|
1718
|
-
return [storedValue, setValue, removeValue];
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
1606
|
// src/hooks/use-debounce.ts
|
|
1722
|
-
import { useState as
|
|
1607
|
+
import { useState as useState5, useEffect as useEffect5 } from "react";
|
|
1723
1608
|
function useDebounce(value, delay) {
|
|
1724
|
-
const [debouncedValue, setDebouncedValue] =
|
|
1725
|
-
|
|
1609
|
+
const [debouncedValue, setDebouncedValue] = useState5(value);
|
|
1610
|
+
useEffect5(() => {
|
|
1726
1611
|
const handler = setTimeout(() => {
|
|
1727
1612
|
setDebouncedValue(value);
|
|
1728
1613
|
}, delay);
|
|
@@ -1950,10 +1835,7 @@ init_config();
|
|
|
1950
1835
|
export {
|
|
1951
1836
|
AUTH_ROOT,
|
|
1952
1837
|
AUTH_TOKEN_KEY,
|
|
1953
|
-
AuthGuard,
|
|
1954
1838
|
AuthProvider,
|
|
1955
|
-
AuthRedirector,
|
|
1956
|
-
AuthRedirector_default as AuthRedirectorDefault,
|
|
1957
1839
|
DefaultErrorFallback,
|
|
1958
1840
|
ErrorBoundary,
|
|
1959
1841
|
FloatingButton,
|
|
@@ -1988,7 +1870,6 @@ export {
|
|
|
1988
1870
|
useAuthContext,
|
|
1989
1871
|
useDebounce,
|
|
1990
1872
|
useIsMobile,
|
|
1991
|
-
useLocalStorage,
|
|
1992
1873
|
workflowRequest
|
|
1993
1874
|
};
|
|
1994
1875
|
//# sourceMappingURL=index.mjs.map
|