@howone/sdk 0.1.23 → 0.1.25
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 +12 -8
- package/dist/index.d.ts +12 -8
- package/dist/index.js +45 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -430,7 +430,7 @@ type HowoneContextValue = {
|
|
|
430
430
|
isAuthenticated: boolean;
|
|
431
431
|
logout: () => void;
|
|
432
432
|
};
|
|
433
|
-
interface
|
|
433
|
+
interface HowOneProviderProps {
|
|
434
434
|
children: React$1.ReactNode;
|
|
435
435
|
autoRedirect?: boolean;
|
|
436
436
|
showFloatingButton?: boolean;
|
|
@@ -438,28 +438,32 @@ interface HowoneProviderProps {
|
|
|
438
438
|
defaultTheme?: Theme$1;
|
|
439
439
|
themeStorageKey?: string;
|
|
440
440
|
forceDefaultTheme?: boolean;
|
|
441
|
+
authUrl?: string;
|
|
442
|
+
redirectOnUnauthenticated?: boolean;
|
|
441
443
|
}
|
|
442
444
|
/**
|
|
443
|
-
*
|
|
445
|
+
* HowOneProvider - All-in-one application provider
|
|
444
446
|
*
|
|
445
447
|
* Includes:
|
|
446
|
-
* - Authentication management
|
|
448
|
+
* - Authentication management with auto-redirect to auth page
|
|
447
449
|
* - Theme management (dark/light/system)
|
|
448
450
|
* - Toast notifications
|
|
449
|
-
* - Floating button
|
|
451
|
+
* - Floating button (shows "Login" when unauthenticated)
|
|
450
452
|
*
|
|
451
453
|
* @example
|
|
452
454
|
* ```tsx
|
|
453
|
-
* <
|
|
455
|
+
* <HowOneProvider
|
|
454
456
|
* defaultTheme="dark"
|
|
455
457
|
* themeStorageKey="my-app-theme"
|
|
456
458
|
* showFloatingButton={true}
|
|
459
|
+
* authUrl="https://howone.dev/auth"
|
|
460
|
+
* redirectOnUnauthenticated={true}
|
|
457
461
|
* >
|
|
458
462
|
* <App />
|
|
459
|
-
* </
|
|
463
|
+
* </HowOneProvider>
|
|
460
464
|
* ```
|
|
461
465
|
*/
|
|
462
|
-
declare const
|
|
466
|
+
declare const HowOneProvider: React$1.FC<HowOneProviderProps>;
|
|
463
467
|
declare function useHowoneContext(): HowoneContextValue;
|
|
464
468
|
|
|
465
469
|
type AuthState = {
|
|
@@ -569,4 +573,4 @@ declare function useDebounce<T>(value: T, delay: number): T;
|
|
|
569
573
|
*/
|
|
570
574
|
declare function injectEarlyErrorHandler(): void;
|
|
571
575
|
|
|
572
|
-
export { type AIWorkflowClientOptions, type AIWorkflowResponse, AUTH_ROOT, AUTH_TOKEN_KEY, type AccessContext, type Artifact, type ArtifactCreateInput, type ArtifactListQuery, type AxiosAIWorkflowOptions, ClayxToast, DefaultErrorFallback, type EmailLoginRequest, type EmailLoginResponse, ErrorBoundary, FloatingButton, GlobalToastContainer,
|
|
576
|
+
export { type AIWorkflowClientOptions, type AIWorkflowResponse, AUTH_ROOT, AUTH_TOKEN_KEY, type AccessContext, type Artifact, type ArtifactCreateInput, type ArtifactListQuery, type AxiosAIWorkflowOptions, ClayxToast, DefaultErrorFallback, type EmailLoginRequest, type EmailLoginResponse, ErrorBoundary, FloatingButton, GlobalToastContainer, HowOneProvider, type HowOneProviderProps, Loading, LoadingSpinner, LoginForm, type SendCodeRequest, type SendCodeResponse, ThemeProvider, ThemeToggle, type Visibility, aiRequest, aiWorkflow, canAccessArtifact, createAIWorkflowClient, createAIWorkflowClientAxios, createArtifactsClient, createClient, getAuthRoot, getCodeStatus, getDefaultProjectId, getToken, howone, injectEarlyErrorHandler, isTokenValid, loginWithEmailCode, onAuthStateChanged, parseUserFromToken, request, sendEmailVerificationCode, setAuthRoot, setDefaultProjectId, setToken, unifiedAuth, unifiedOAuth, useAuth, useDebounce, useHowoneContext, useIsMobile, useTheme, workflowRequest };
|
package/dist/index.d.ts
CHANGED
|
@@ -430,7 +430,7 @@ type HowoneContextValue = {
|
|
|
430
430
|
isAuthenticated: boolean;
|
|
431
431
|
logout: () => void;
|
|
432
432
|
};
|
|
433
|
-
interface
|
|
433
|
+
interface HowOneProviderProps {
|
|
434
434
|
children: React$1.ReactNode;
|
|
435
435
|
autoRedirect?: boolean;
|
|
436
436
|
showFloatingButton?: boolean;
|
|
@@ -438,28 +438,32 @@ interface HowoneProviderProps {
|
|
|
438
438
|
defaultTheme?: Theme$1;
|
|
439
439
|
themeStorageKey?: string;
|
|
440
440
|
forceDefaultTheme?: boolean;
|
|
441
|
+
authUrl?: string;
|
|
442
|
+
redirectOnUnauthenticated?: boolean;
|
|
441
443
|
}
|
|
442
444
|
/**
|
|
443
|
-
*
|
|
445
|
+
* HowOneProvider - All-in-one application provider
|
|
444
446
|
*
|
|
445
447
|
* Includes:
|
|
446
|
-
* - Authentication management
|
|
448
|
+
* - Authentication management with auto-redirect to auth page
|
|
447
449
|
* - Theme management (dark/light/system)
|
|
448
450
|
* - Toast notifications
|
|
449
|
-
* - Floating button
|
|
451
|
+
* - Floating button (shows "Login" when unauthenticated)
|
|
450
452
|
*
|
|
451
453
|
* @example
|
|
452
454
|
* ```tsx
|
|
453
|
-
* <
|
|
455
|
+
* <HowOneProvider
|
|
454
456
|
* defaultTheme="dark"
|
|
455
457
|
* themeStorageKey="my-app-theme"
|
|
456
458
|
* showFloatingButton={true}
|
|
459
|
+
* authUrl="https://howone.dev/auth"
|
|
460
|
+
* redirectOnUnauthenticated={true}
|
|
457
461
|
* >
|
|
458
462
|
* <App />
|
|
459
|
-
* </
|
|
463
|
+
* </HowOneProvider>
|
|
460
464
|
* ```
|
|
461
465
|
*/
|
|
462
|
-
declare const
|
|
466
|
+
declare const HowOneProvider: React$1.FC<HowOneProviderProps>;
|
|
463
467
|
declare function useHowoneContext(): HowoneContextValue;
|
|
464
468
|
|
|
465
469
|
type AuthState = {
|
|
@@ -569,4 +573,4 @@ declare function useDebounce<T>(value: T, delay: number): T;
|
|
|
569
573
|
*/
|
|
570
574
|
declare function injectEarlyErrorHandler(): void;
|
|
571
575
|
|
|
572
|
-
export { type AIWorkflowClientOptions, type AIWorkflowResponse, AUTH_ROOT, AUTH_TOKEN_KEY, type AccessContext, type Artifact, type ArtifactCreateInput, type ArtifactListQuery, type AxiosAIWorkflowOptions, ClayxToast, DefaultErrorFallback, type EmailLoginRequest, type EmailLoginResponse, ErrorBoundary, FloatingButton, GlobalToastContainer,
|
|
576
|
+
export { type AIWorkflowClientOptions, type AIWorkflowResponse, AUTH_ROOT, AUTH_TOKEN_KEY, type AccessContext, type Artifact, type ArtifactCreateInput, type ArtifactListQuery, type AxiosAIWorkflowOptions, ClayxToast, DefaultErrorFallback, type EmailLoginRequest, type EmailLoginResponse, ErrorBoundary, FloatingButton, GlobalToastContainer, HowOneProvider, type HowOneProviderProps, Loading, LoadingSpinner, LoginForm, type SendCodeRequest, type SendCodeResponse, ThemeProvider, ThemeToggle, type Visibility, aiRequest, aiWorkflow, canAccessArtifact, createAIWorkflowClient, createAIWorkflowClientAxios, createArtifactsClient, createClient, getAuthRoot, getCodeStatus, getDefaultProjectId, getToken, howone, injectEarlyErrorHandler, isTokenValid, loginWithEmailCode, onAuthStateChanged, parseUserFromToken, request, sendEmailVerificationCode, setAuthRoot, setDefaultProjectId, setToken, unifiedAuth, unifiedOAuth, useAuth, useDebounce, useHowoneContext, useIsMobile, useTheme, workflowRequest };
|
package/dist/index.js
CHANGED
|
@@ -212,7 +212,7 @@ var AUTH_ROOT_VALUE, DEFAULT_PROJECT_ID, AUTH_ROOT, config_default;
|
|
|
212
212
|
var init_config = __esm({
|
|
213
213
|
"src/config.ts"() {
|
|
214
214
|
"use strict";
|
|
215
|
-
AUTH_ROOT_VALUE = "https://howone
|
|
215
|
+
AUTH_ROOT_VALUE = "https://howone.dev";
|
|
216
216
|
DEFAULT_PROJECT_ID = null;
|
|
217
217
|
AUTH_ROOT = getAuthRoot();
|
|
218
218
|
try {
|
|
@@ -240,7 +240,7 @@ __export(index_exports, {
|
|
|
240
240
|
ErrorBoundary: () => ErrorBoundary,
|
|
241
241
|
FloatingButton: () => FloatingButton,
|
|
242
242
|
GlobalToastContainer: () => GlobalToastContainer,
|
|
243
|
-
|
|
243
|
+
HowOneProvider: () => HowOneProvider,
|
|
244
244
|
Loading: () => Loading,
|
|
245
245
|
LoadingSpinner: () => LoadingSpinner,
|
|
246
246
|
LoginForm: () => LoginForm,
|
|
@@ -1629,33 +1629,70 @@ function GlobalToastContainer() {
|
|
|
1629
1629
|
// src/components/auth/HowoneProvider.tsx
|
|
1630
1630
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1631
1631
|
var HowoneContext = (0, import_react5.createContext)(null);
|
|
1632
|
-
var
|
|
1632
|
+
var HowOneProvider = ({
|
|
1633
1633
|
children,
|
|
1634
1634
|
showFloatingButton = true,
|
|
1635
|
+
projectId,
|
|
1635
1636
|
defaultTheme = "system",
|
|
1636
1637
|
themeStorageKey = "howone-theme",
|
|
1637
|
-
forceDefaultTheme = false
|
|
1638
|
+
forceDefaultTheme = false,
|
|
1639
|
+
authUrl = "https://howone.dev/auth",
|
|
1640
|
+
redirectOnUnauthenticated = true
|
|
1638
1641
|
}) => {
|
|
1639
1642
|
const [user, setUser] = (0, import_react5.useState)(() => parseUserFromToken(getToken()));
|
|
1640
1643
|
const [token, setTokenState] = (0, import_react5.useState)(() => getToken());
|
|
1644
|
+
const [hasCheckedUrlToken, setHasCheckedUrlToken] = (0, import_react5.useState)(false);
|
|
1641
1645
|
(0, import_react5.useEffect)(() => {
|
|
1642
1646
|
try {
|
|
1643
1647
|
const params = new URLSearchParams(window.location.search);
|
|
1644
|
-
|
|
1648
|
+
let urlToken = params.get("access_token") || params.get("token");
|
|
1649
|
+
if (!urlToken && window.location.hash) {
|
|
1650
|
+
const hashParams = new URLSearchParams(window.location.hash.slice(1));
|
|
1651
|
+
urlToken = hashParams.get("access_token") || hashParams.get("token");
|
|
1652
|
+
}
|
|
1645
1653
|
if (urlToken) {
|
|
1654
|
+
console.log("[HowOneProvider] Token captured from URL, storing to localStorage...");
|
|
1646
1655
|
setToken(urlToken);
|
|
1647
1656
|
setTokenState(urlToken);
|
|
1648
1657
|
setUser(parseUserFromToken(urlToken));
|
|
1649
1658
|
params.delete("access_token");
|
|
1650
1659
|
params.delete("token");
|
|
1660
|
+
params.delete("project_id");
|
|
1651
1661
|
const newSearch = params.toString();
|
|
1652
|
-
const newUrl = window.location.pathname + (newSearch ? "?" + newSearch : "")
|
|
1662
|
+
const newUrl = window.location.pathname + (newSearch ? "?" + newSearch : "");
|
|
1653
1663
|
window.history.replaceState({}, "", newUrl);
|
|
1664
|
+
console.log("[HowOneProvider] Token stored successfully, URL cleaned");
|
|
1654
1665
|
}
|
|
1655
1666
|
} catch (e) {
|
|
1656
|
-
console.error("[
|
|
1667
|
+
console.error("[HowOneProvider] Failed to capture token from URL:", e);
|
|
1668
|
+
} finally {
|
|
1669
|
+
setHasCheckedUrlToken(true);
|
|
1657
1670
|
}
|
|
1658
1671
|
}, []);
|
|
1672
|
+
(0, import_react5.useEffect)(() => {
|
|
1673
|
+
if (!hasCheckedUrlToken) {
|
|
1674
|
+
return;
|
|
1675
|
+
}
|
|
1676
|
+
if (redirectOnUnauthenticated && !token && !user) {
|
|
1677
|
+
const currentUrl = new URL(window.location.href);
|
|
1678
|
+
if (!currentUrl.pathname.includes("/auth")) {
|
|
1679
|
+
console.log("[HowOneProvider] No token found, redirecting to auth page...");
|
|
1680
|
+
try {
|
|
1681
|
+
const authUrlObj = new URL(authUrl);
|
|
1682
|
+
const redirectUri = window.location.href;
|
|
1683
|
+
authUrlObj.searchParams.set("redirect_uri", redirectUri);
|
|
1684
|
+
if (projectId) {
|
|
1685
|
+
authUrlObj.searchParams.set("project_id", projectId);
|
|
1686
|
+
}
|
|
1687
|
+
console.log("[HowOneProvider] Redirecting to:", authUrlObj.toString());
|
|
1688
|
+
window.location.href = authUrlObj.toString();
|
|
1689
|
+
} catch (error) {
|
|
1690
|
+
console.error("[HowOneProvider] Failed to build auth URL:", error);
|
|
1691
|
+
window.location.href = authUrl;
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
}, [token, user, redirectOnUnauthenticated, authUrl, projectId, hasCheckedUrlToken]);
|
|
1659
1696
|
const logout = () => {
|
|
1660
1697
|
try {
|
|
1661
1698
|
setToken(null);
|
|
@@ -2484,7 +2521,7 @@ init_config();
|
|
|
2484
2521
|
ErrorBoundary,
|
|
2485
2522
|
FloatingButton,
|
|
2486
2523
|
GlobalToastContainer,
|
|
2487
|
-
|
|
2524
|
+
HowOneProvider,
|
|
2488
2525
|
Loading,
|
|
2489
2526
|
LoadingSpinner,
|
|
2490
2527
|
LoginForm,
|