@howone/sdk 0.5.1 → 0.5.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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +102 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +102 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -577,6 +577,7 @@ declare function onAuthStateChanged(cb: (state: AuthState$1) => void): () => voi
|
|
|
577
577
|
type Environment = 'local' | 'dev' | 'prod';
|
|
578
578
|
type envs = {
|
|
579
579
|
AUTH_ROOT_VALUE: string;
|
|
580
|
+
AUTH_COOKIE_ROOT_VALUE: string;
|
|
580
581
|
baseUrl: string;
|
|
581
582
|
aiBaseUrl: string;
|
|
582
583
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -577,6 +577,7 @@ declare function onAuthStateChanged(cb: (state: AuthState$1) => void): () => voi
|
|
|
577
577
|
type Environment = 'local' | 'dev' | 'prod';
|
|
578
578
|
type envs = {
|
|
579
579
|
AUTH_ROOT_VALUE: string;
|
|
580
|
+
AUTH_COOKIE_ROOT_VALUE: string;
|
|
580
581
|
baseUrl: string;
|
|
581
582
|
aiBaseUrl: string;
|
|
582
583
|
};
|
package/dist/index.js
CHANGED
|
@@ -80,16 +80,19 @@ var init_config = __esm({
|
|
|
80
80
|
env = "dev";
|
|
81
81
|
localEnv = {
|
|
82
82
|
AUTH_ROOT_VALUE: "https://howone.dev",
|
|
83
|
+
AUTH_COOKIE_ROOT_VALUE: "https://auth.howone.app",
|
|
83
84
|
baseUrl: "http://localhost:3002/api",
|
|
84
85
|
aiBaseUrl: "https://evoagentx-server.fly.dev"
|
|
85
86
|
};
|
|
86
87
|
devEnv = {
|
|
87
88
|
AUTH_ROOT_VALUE: "https://howone.dev",
|
|
89
|
+
AUTH_COOKIE_ROOT_VALUE: "https://auth.howone.app",
|
|
88
90
|
baseUrl: "https://api.howone.dev/api",
|
|
89
91
|
aiBaseUrl: "https://evoagentx-server-stable.fly.dev"
|
|
90
92
|
};
|
|
91
93
|
prodEnv = {
|
|
92
94
|
AUTH_ROOT_VALUE: "https://howone.ai",
|
|
95
|
+
AUTH_COOKIE_ROOT_VALUE: "https://auth.howone.app",
|
|
93
96
|
baseUrl: "https://api.howone.ai/api",
|
|
94
97
|
aiBaseUrl: "https://eax.services"
|
|
95
98
|
};
|
|
@@ -212,6 +215,13 @@ function useAuth() {
|
|
|
212
215
|
setTokenState(null);
|
|
213
216
|
setUser(null);
|
|
214
217
|
notifyAuthStateChanged();
|
|
218
|
+
try {
|
|
219
|
+
fetch(`${env2.AUTH_COOKIE_ROOT_VALUE}/logout`, {
|
|
220
|
+
method: "POST",
|
|
221
|
+
credentials: "include"
|
|
222
|
+
}).catch(() => void 0);
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
215
225
|
if (typeof window !== "undefined") {
|
|
216
226
|
const loc = window.location.href;
|
|
217
227
|
const pid = getDefaultProjectId();
|
|
@@ -1322,6 +1332,7 @@ var ElementSelectorProvider = ({ children }) => {
|
|
|
1322
1332
|
init_config();
|
|
1323
1333
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1324
1334
|
var HowoneContext = (0, import_react8.createContext)(null);
|
|
1335
|
+
var consumedTokenCache = /* @__PURE__ */ new Set();
|
|
1325
1336
|
var redirectOverlayStylesInjected = false;
|
|
1326
1337
|
var injectRedirectOverlayStyles = () => {
|
|
1327
1338
|
if (redirectOverlayStylesInjected || typeof document === "undefined") return;
|
|
@@ -1385,6 +1396,63 @@ var HowOneProvider = ({
|
|
|
1385
1396
|
const [token, setTokenState] = (0, import_react8.useState)(() => getToken());
|
|
1386
1397
|
const [hasCheckedUrlToken, setHasCheckedUrlToken] = (0, import_react8.useState)(false);
|
|
1387
1398
|
const [pendingRedirect, setPendingRedirect] = (0, import_react8.useState)(false);
|
|
1399
|
+
const authCookieRoot = (0, import_react8.useMemo)(() => {
|
|
1400
|
+
const env3 = getGlobalEnvironment() ?? "dev";
|
|
1401
|
+
return setEnvironment(env3).AUTH_COOKIE_ROOT_VALUE;
|
|
1402
|
+
}, []);
|
|
1403
|
+
const consumeTokenToCookie = (0, import_react8.useCallback)(async (value2) => {
|
|
1404
|
+
if (!value2) return;
|
|
1405
|
+
if (consumedTokenCache.has(value2)) return;
|
|
1406
|
+
consumedTokenCache.add(value2);
|
|
1407
|
+
try {
|
|
1408
|
+
const response = await fetch(`${authCookieRoot}/consume`, {
|
|
1409
|
+
method: "POST",
|
|
1410
|
+
credentials: "include",
|
|
1411
|
+
headers: {
|
|
1412
|
+
Authorization: `Bearer ${value2}`
|
|
1413
|
+
}
|
|
1414
|
+
});
|
|
1415
|
+
if (!response.ok) {
|
|
1416
|
+
console.info("[HowOneProvider] consume token request failed:", response.status, response.statusText);
|
|
1417
|
+
}
|
|
1418
|
+
} catch (error) {
|
|
1419
|
+
try {
|
|
1420
|
+
const inIframe = typeof window !== "undefined" && window.top !== window.self;
|
|
1421
|
+
if (inIframe) {
|
|
1422
|
+
console.info("[HowOneProvider] consume token skipped in iframe context (likely third-party cookie/CORS policy).");
|
|
1423
|
+
return;
|
|
1424
|
+
}
|
|
1425
|
+
} catch {
|
|
1426
|
+
}
|
|
1427
|
+
console.warn("[HowOneProvider] Failed to consume token:", error);
|
|
1428
|
+
}
|
|
1429
|
+
}, [authCookieRoot]);
|
|
1430
|
+
const logoutFromCookie = (0, import_react8.useCallback)(async () => {
|
|
1431
|
+
try {
|
|
1432
|
+
await fetch(`${authCookieRoot}/logout`, {
|
|
1433
|
+
method: "POST",
|
|
1434
|
+
credentials: "include"
|
|
1435
|
+
});
|
|
1436
|
+
} catch (error) {
|
|
1437
|
+
console.warn("[HowOneProvider] Failed to logout from cookie:", error);
|
|
1438
|
+
}
|
|
1439
|
+
}, [authCookieRoot]);
|
|
1440
|
+
const readAccessTokenCookie = (0, import_react8.useCallback)(() => {
|
|
1441
|
+
if (typeof document === "undefined") return null;
|
|
1442
|
+
try {
|
|
1443
|
+
const parts = document.cookie.split("; ");
|
|
1444
|
+
for (const part of parts) {
|
|
1445
|
+
const [key, ...rest] = part.split("=");
|
|
1446
|
+
if (key === "access_token") {
|
|
1447
|
+
const raw = rest.join("=");
|
|
1448
|
+
return raw ? decodeURIComponent(raw) : null;
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
} catch {
|
|
1452
|
+
return null;
|
|
1453
|
+
}
|
|
1454
|
+
return null;
|
|
1455
|
+
}, []);
|
|
1388
1456
|
(0, import_react8.useEffect)(() => {
|
|
1389
1457
|
try {
|
|
1390
1458
|
const params = new URLSearchParams(window.location.search);
|
|
@@ -1393,10 +1461,11 @@ var HowOneProvider = ({
|
|
|
1393
1461
|
const hashParams = new URLSearchParams(window.location.hash.slice(1));
|
|
1394
1462
|
urlToken = hashParams.get("access_token") || hashParams.get("token");
|
|
1395
1463
|
}
|
|
1396
|
-
if (urlToken) {
|
|
1464
|
+
if (urlToken && isTokenValid(urlToken)) {
|
|
1397
1465
|
setToken(urlToken);
|
|
1398
1466
|
setTokenState(urlToken);
|
|
1399
1467
|
setUser(parseUserFromToken(urlToken));
|
|
1468
|
+
void consumeTokenToCookie(urlToken);
|
|
1400
1469
|
params.delete("access_token");
|
|
1401
1470
|
params.delete("token");
|
|
1402
1471
|
params.delete("project_id");
|
|
@@ -1404,12 +1473,20 @@ var HowOneProvider = ({
|
|
|
1404
1473
|
const newUrl = window.location.pathname + (newSearch ? "?" + newSearch : "");
|
|
1405
1474
|
window.history.replaceState({}, "", newUrl);
|
|
1406
1475
|
}
|
|
1476
|
+
if (!urlToken) {
|
|
1477
|
+
const cookieToken = readAccessTokenCookie();
|
|
1478
|
+
if (cookieToken && isTokenValid(cookieToken)) {
|
|
1479
|
+
setToken(cookieToken);
|
|
1480
|
+
setTokenState(cookieToken);
|
|
1481
|
+
setUser(parseUserFromToken(cookieToken));
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1407
1484
|
} catch (e) {
|
|
1408
|
-
console.
|
|
1485
|
+
console.warn("[HowOneProvider] Failed to capture token from URL:", e);
|
|
1409
1486
|
} finally {
|
|
1410
1487
|
setHasCheckedUrlToken(true);
|
|
1411
1488
|
}
|
|
1412
|
-
}, []);
|
|
1489
|
+
}, [consumeTokenToCookie, readAccessTokenCookie]);
|
|
1413
1490
|
const resolvedAuthUrl = (0, import_react8.useMemo)(() => {
|
|
1414
1491
|
const env3 = getGlobalEnvironment() ?? "dev";
|
|
1415
1492
|
switch (env3) {
|
|
@@ -1427,11 +1504,6 @@ var HowOneProvider = ({
|
|
|
1427
1504
|
injectRedirectOverlayStyles();
|
|
1428
1505
|
}
|
|
1429
1506
|
}, [pendingRedirect]);
|
|
1430
|
-
(0, import_react8.useEffect)(() => {
|
|
1431
|
-
if (pendingRedirect) {
|
|
1432
|
-
injectRedirectOverlayStyles();
|
|
1433
|
-
}
|
|
1434
|
-
}, [pendingRedirect]);
|
|
1435
1507
|
const redirectToAuth = (0, import_react8.useCallback)(() => {
|
|
1436
1508
|
if (!redirectOnUnauthenticated || typeof window === "undefined") return;
|
|
1437
1509
|
const activeProjectId = projectId ?? getDefaultProjectId();
|
|
@@ -1446,7 +1518,7 @@ var HowOneProvider = ({
|
|
|
1446
1518
|
window.location.href = url.toString();
|
|
1447
1519
|
return;
|
|
1448
1520
|
} catch (error) {
|
|
1449
|
-
console.
|
|
1521
|
+
console.warn("[HowOneProvider] Failed to attach project_id to auth URL:", error);
|
|
1450
1522
|
}
|
|
1451
1523
|
}
|
|
1452
1524
|
window.location.href = resolvedAuthUrl;
|
|
@@ -1467,7 +1539,7 @@ var HowOneProvider = ({
|
|
|
1467
1539
|
});
|
|
1468
1540
|
return;
|
|
1469
1541
|
} catch (error) {
|
|
1470
|
-
console.
|
|
1542
|
+
console.warn("[HowOneProvider] Failed to build auth URL:", error);
|
|
1471
1543
|
}
|
|
1472
1544
|
navigateToResolvedAuth();
|
|
1473
1545
|
} catch {
|
|
@@ -1487,6 +1559,7 @@ var HowOneProvider = ({
|
|
|
1487
1559
|
}
|
|
1488
1560
|
setTokenState(null);
|
|
1489
1561
|
setUser(null);
|
|
1562
|
+
void logoutFromCookie();
|
|
1490
1563
|
redirectToAuth();
|
|
1491
1564
|
};
|
|
1492
1565
|
const value = {
|
|
@@ -2345,6 +2418,7 @@ var Request = class {
|
|
|
2345
2418
|
this.abortControllers = /* @__PURE__ */ new Map();
|
|
2346
2419
|
this.instance = import_axios.default.create({
|
|
2347
2420
|
...config,
|
|
2421
|
+
withCredentials: true,
|
|
2348
2422
|
validateStatus: (status) => {
|
|
2349
2423
|
return status >= 200 && status < 300;
|
|
2350
2424
|
}
|
|
@@ -2721,6 +2795,17 @@ async function executeSSEWorkflow(request, options = {}) {
|
|
|
2721
2795
|
options.onStreamContent(logData.delta);
|
|
2722
2796
|
}
|
|
2723
2797
|
}
|
|
2798
|
+
if (rawEvent.type === "execution_error" && rawEvent.data) {
|
|
2799
|
+
const errorData = rawEvent.data;
|
|
2800
|
+
if (errorData.log_type === "execution_display_error") {
|
|
2801
|
+
const errorContent = errorData.content;
|
|
2802
|
+
const displayMessage = errorContent || "Workflow execution failed";
|
|
2803
|
+
ClayxToast.error({
|
|
2804
|
+
title: "Execution Error",
|
|
2805
|
+
message: displayMessage
|
|
2806
|
+
});
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2724
2809
|
if (rawEvent.type === "stream" && rawEvent.delta && options.onStreamContent) {
|
|
2725
2810
|
options.onStreamContent(rawEvent.delta);
|
|
2726
2811
|
}
|
|
@@ -3786,6 +3871,13 @@ function createClient(opts) {
|
|
|
3786
3871
|
applyToken(null);
|
|
3787
3872
|
rememberExternalToken(null, 0);
|
|
3788
3873
|
pendingExternalTokenPromise = null;
|
|
3874
|
+
try {
|
|
3875
|
+
fetch(`${env3.AUTH_COOKIE_ROOT_VALUE}/logout`, {
|
|
3876
|
+
method: "POST",
|
|
3877
|
+
credentials: "include"
|
|
3878
|
+
}).catch(() => void 0);
|
|
3879
|
+
} catch {
|
|
3880
|
+
}
|
|
3789
3881
|
if (typeof window !== "undefined") {
|
|
3790
3882
|
const loc = window.location.href;
|
|
3791
3883
|
try {
|