@hanzo/iam 0.6.0 → 0.6.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/dist/auth.d.ts +1 -1
- package/dist/auth.js +3 -3
- package/dist/auth.js.map +1 -1
- package/dist/betterauth.d.ts +67 -0
- package/dist/betterauth.d.ts.map +1 -0
- package/dist/betterauth.js +64 -0
- package/dist/betterauth.js.map +1 -0
- package/dist/browser.d.ts +84 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +224 -3
- package/dist/browser.js.map +1 -1
- package/dist/client.d.ts +11 -22
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +39 -90
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/nextauth.d.ts +12 -10
- package/dist/nextauth.d.ts.map +1 -1
- package/dist/nextauth.js +12 -11
- package/dist/nextauth.js.map +1 -1
- package/dist/passport.d.ts +44 -0
- package/dist/passport.d.ts.map +1 -0
- package/dist/passport.js +67 -0
- package/dist/passport.js.map +1 -0
- package/dist/pkce.d.ts +1 -1
- package/dist/pkce.js +1 -1
- package/dist/react.d.ts +1 -87
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +20 -446
- package/dist/react.js.map +1 -1
- package/dist/types.d.ts +1 -16
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/package.json +16 -7
- package/src/auth.ts +3 -3
- package/src/betterauth.ts +91 -0
- package/src/browser.ts +247 -3
- package/src/client.ts +47 -147
- package/src/index.ts +1 -2
- package/src/nextauth.ts +15 -13
- package/src/passport.ts +97 -0
- package/src/pkce.ts +1 -1
- package/src/react.ts +20 -622
- package/src/types.ts +1 -21
package/src/react.ts
CHANGED
|
@@ -46,7 +46,7 @@ import type { ReactNode } from "react";
|
|
|
46
46
|
import { BrowserIamSdk } from "./browser.js";
|
|
47
47
|
import type { BrowserIamConfig } from "./browser.js";
|
|
48
48
|
import { IamClient } from "./client.js";
|
|
49
|
-
import type { IamUser, IamOrganization,
|
|
49
|
+
import type { IamUser, IamOrganization, IamProject, TokenResponse } from "./types.js";
|
|
50
50
|
|
|
51
51
|
// ---------------------------------------------------------------------------
|
|
52
52
|
// Types
|
|
@@ -405,34 +405,26 @@ export function useOrganizations(): OrgState {
|
|
|
405
405
|
const fetchOrgs = async () => {
|
|
406
406
|
setIsLoading(true);
|
|
407
407
|
|
|
408
|
-
// 1. Parse JWT
|
|
409
|
-
// The user's "owner" is the signup org (for auth). Their personal org
|
|
410
|
-
// (name == username) is their actual workspace.
|
|
408
|
+
// 1. Parse JWT sub claim for primary org (immediate, no API call)
|
|
411
409
|
try {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
if (!currentOrgId) {
|
|
431
|
-
setCurrentOrgId(workspaceOrg);
|
|
432
|
-
try {
|
|
433
|
-
localStorage.setItem(STORAGE_ORG_KEY, workspaceOrg);
|
|
434
|
-
} catch {
|
|
435
|
-
/* ok */
|
|
410
|
+
const payload = JSON.parse(atob(accessToken.split(".")[1]));
|
|
411
|
+
const sub = payload.sub as string;
|
|
412
|
+
if (sub?.includes("/")) {
|
|
413
|
+
const primaryOrg = sub.split("/")[0];
|
|
414
|
+
if (!cancelled) {
|
|
415
|
+
const syntheticOrg: IamOrganization = {
|
|
416
|
+
owner: "admin",
|
|
417
|
+
name: primaryOrg,
|
|
418
|
+
displayName: primaryOrg,
|
|
419
|
+
};
|
|
420
|
+
setOrganizations([syntheticOrg]);
|
|
421
|
+
if (!currentOrgId) {
|
|
422
|
+
setCurrentOrgId(primaryOrg);
|
|
423
|
+
try {
|
|
424
|
+
localStorage.setItem(STORAGE_ORG_KEY, primaryOrg);
|
|
425
|
+
} catch {
|
|
426
|
+
/* ok */
|
|
427
|
+
}
|
|
436
428
|
}
|
|
437
429
|
}
|
|
438
430
|
}
|
|
@@ -597,200 +589,6 @@ export function useIamToken(): {
|
|
|
597
589
|
};
|
|
598
590
|
}
|
|
599
591
|
|
|
600
|
-
// ---------------------------------------------------------------------------
|
|
601
|
-
// useOrgManagement
|
|
602
|
-
// ---------------------------------------------------------------------------
|
|
603
|
-
|
|
604
|
-
export interface OrgManagementState {
|
|
605
|
-
/** Create a new organization. */
|
|
606
|
-
createOrg: (org: Partial<IamOrganization>) => Promise<void>;
|
|
607
|
-
/** Update an existing organization. */
|
|
608
|
-
updateOrg: (org: Partial<IamOrganization>) => Promise<void>;
|
|
609
|
-
/** Delete an organization by owner and name. */
|
|
610
|
-
deleteOrg: (org: { owner: string; name: string }) => Promise<void>;
|
|
611
|
-
/** Whether a mutation is in progress. */
|
|
612
|
-
isLoading: boolean;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
* Manage organization CRUD operations.
|
|
617
|
-
*
|
|
618
|
-
* Provides create, update, and delete methods that call the IAM API
|
|
619
|
-
* using the current user's access token.
|
|
620
|
-
*/
|
|
621
|
-
export function useOrgManagement(): OrgManagementState {
|
|
622
|
-
const { config, accessToken } = useIam();
|
|
623
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
624
|
-
|
|
625
|
-
const client = useMemo(
|
|
626
|
-
() =>
|
|
627
|
-
new IamClient({
|
|
628
|
-
serverUrl: config.serverUrl,
|
|
629
|
-
clientId: config.clientId,
|
|
630
|
-
}),
|
|
631
|
-
[config.serverUrl, config.clientId],
|
|
632
|
-
);
|
|
633
|
-
|
|
634
|
-
const createOrg = useCallback(
|
|
635
|
-
async (org: Partial<IamOrganization>) => {
|
|
636
|
-
setIsLoading(true);
|
|
637
|
-
try {
|
|
638
|
-
await client.createOrganization(org, accessToken ?? undefined);
|
|
639
|
-
} finally {
|
|
640
|
-
setIsLoading(false);
|
|
641
|
-
}
|
|
642
|
-
},
|
|
643
|
-
[client, accessToken],
|
|
644
|
-
);
|
|
645
|
-
|
|
646
|
-
const updateOrg = useCallback(
|
|
647
|
-
async (org: Partial<IamOrganization>) => {
|
|
648
|
-
setIsLoading(true);
|
|
649
|
-
try {
|
|
650
|
-
await client.updateOrganization(org, accessToken ?? undefined);
|
|
651
|
-
} finally {
|
|
652
|
-
setIsLoading(false);
|
|
653
|
-
}
|
|
654
|
-
},
|
|
655
|
-
[client, accessToken],
|
|
656
|
-
);
|
|
657
|
-
|
|
658
|
-
const deleteOrg = useCallback(
|
|
659
|
-
async (org: { owner: string; name: string }) => {
|
|
660
|
-
setIsLoading(true);
|
|
661
|
-
try {
|
|
662
|
-
await client.deleteOrganization(org, accessToken ?? undefined);
|
|
663
|
-
} finally {
|
|
664
|
-
setIsLoading(false);
|
|
665
|
-
}
|
|
666
|
-
},
|
|
667
|
-
[client, accessToken],
|
|
668
|
-
);
|
|
669
|
-
|
|
670
|
-
return { createOrg, updateOrg, deleteOrg, isLoading };
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
// ---------------------------------------------------------------------------
|
|
674
|
-
// useInvitations
|
|
675
|
-
// ---------------------------------------------------------------------------
|
|
676
|
-
|
|
677
|
-
export interface InvitationsState {
|
|
678
|
-
/** All invitations for the organization. */
|
|
679
|
-
invitations: IamInvitation[];
|
|
680
|
-
/** Create a new invitation. */
|
|
681
|
-
createInvite: (invitation: Partial<IamInvitation>) => Promise<void>;
|
|
682
|
-
/** Send an existing invitation. */
|
|
683
|
-
sendInvite: (invitation: { owner: string; name: string }) => Promise<void>;
|
|
684
|
-
/** Verify an invitation code. */
|
|
685
|
-
verifyInvite: (code: string) => Promise<IamInvitation | null>;
|
|
686
|
-
/** Whether invitations are loading. */
|
|
687
|
-
isLoading: boolean;
|
|
688
|
-
/** Re-fetch the invitations list. */
|
|
689
|
-
refresh: () => Promise<void>;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
/**
|
|
693
|
-
* Manage invitations for an organization.
|
|
694
|
-
*
|
|
695
|
-
* Fetches the invitation list on mount and provides create, send,
|
|
696
|
-
* and verify methods using the current user's access token.
|
|
697
|
-
*/
|
|
698
|
-
export function useInvitations(orgName: string): InvitationsState {
|
|
699
|
-
const { config, accessToken, isAuthenticated } = useIam();
|
|
700
|
-
const [invitations, setInvitations] = useState<IamInvitation[]>([]);
|
|
701
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
702
|
-
|
|
703
|
-
const client = useMemo(
|
|
704
|
-
() =>
|
|
705
|
-
new IamClient({
|
|
706
|
-
serverUrl: config.serverUrl,
|
|
707
|
-
clientId: config.clientId,
|
|
708
|
-
}),
|
|
709
|
-
[config.serverUrl, config.clientId],
|
|
710
|
-
);
|
|
711
|
-
|
|
712
|
-
const fetchInvitations = useCallback(async () => {
|
|
713
|
-
if (!isAuthenticated || !accessToken || !orgName) return;
|
|
714
|
-
setIsLoading(true);
|
|
715
|
-
try {
|
|
716
|
-
const data = await client.getInvitations(orgName, accessToken);
|
|
717
|
-
setInvitations(data);
|
|
718
|
-
} catch {
|
|
719
|
-
setInvitations([]);
|
|
720
|
-
} finally {
|
|
721
|
-
setIsLoading(false);
|
|
722
|
-
}
|
|
723
|
-
}, [client, orgName, accessToken, isAuthenticated]);
|
|
724
|
-
|
|
725
|
-
// Fetch invitations on mount and when orgName changes
|
|
726
|
-
useEffect(() => {
|
|
727
|
-
if (!isAuthenticated || !accessToken || !orgName) {
|
|
728
|
-
setInvitations([]);
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
let cancelled = false;
|
|
733
|
-
|
|
734
|
-
const load = async () => {
|
|
735
|
-
setIsLoading(true);
|
|
736
|
-
try {
|
|
737
|
-
const data = await client.getInvitations(orgName, accessToken);
|
|
738
|
-
if (!cancelled) setInvitations(data);
|
|
739
|
-
} catch {
|
|
740
|
-
if (!cancelled) setInvitations([]);
|
|
741
|
-
} finally {
|
|
742
|
-
if (!cancelled) setIsLoading(false);
|
|
743
|
-
}
|
|
744
|
-
};
|
|
745
|
-
|
|
746
|
-
load();
|
|
747
|
-
return () => {
|
|
748
|
-
cancelled = true;
|
|
749
|
-
};
|
|
750
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
751
|
-
}, [isAuthenticated, accessToken, orgName, config.serverUrl, config.clientId]);
|
|
752
|
-
|
|
753
|
-
const createInvite = useCallback(
|
|
754
|
-
async (invitation: Partial<IamInvitation>) => {
|
|
755
|
-
setIsLoading(true);
|
|
756
|
-
try {
|
|
757
|
-
await client.createInvitation(invitation, accessToken ?? undefined);
|
|
758
|
-
await fetchInvitations();
|
|
759
|
-
} finally {
|
|
760
|
-
setIsLoading(false);
|
|
761
|
-
}
|
|
762
|
-
},
|
|
763
|
-
[client, accessToken, fetchInvitations],
|
|
764
|
-
);
|
|
765
|
-
|
|
766
|
-
const sendInvite = useCallback(
|
|
767
|
-
async (invitation: { owner: string; name: string }) => {
|
|
768
|
-
setIsLoading(true);
|
|
769
|
-
try {
|
|
770
|
-
await client.sendInvitation(invitation, accessToken ?? undefined);
|
|
771
|
-
} finally {
|
|
772
|
-
setIsLoading(false);
|
|
773
|
-
}
|
|
774
|
-
},
|
|
775
|
-
[client, accessToken],
|
|
776
|
-
);
|
|
777
|
-
|
|
778
|
-
const verifyInvite = useCallback(
|
|
779
|
-
async (code: string): Promise<IamInvitation | null> => {
|
|
780
|
-
setIsLoading(true);
|
|
781
|
-
try {
|
|
782
|
-
const resp = await client.verifyInvitation(code, accessToken ?? undefined);
|
|
783
|
-
return resp.data ?? null;
|
|
784
|
-
} finally {
|
|
785
|
-
setIsLoading(false);
|
|
786
|
-
}
|
|
787
|
-
},
|
|
788
|
-
[client, accessToken],
|
|
789
|
-
);
|
|
790
|
-
|
|
791
|
-
return { invitations, createInvite, sendInvite, verifyInvite, isLoading, refresh: fetchInvitations };
|
|
792
|
-
}
|
|
793
|
-
|
|
794
592
|
// Re-export context for advanced use
|
|
795
593
|
export { IamContext };
|
|
796
594
|
|
|
@@ -919,403 +717,3 @@ export function OrgProjectSwitcher({
|
|
|
919
717
|
: null,
|
|
920
718
|
);
|
|
921
719
|
}
|
|
922
|
-
|
|
923
|
-
// ---------------------------------------------------------------------------
|
|
924
|
-
// UserOrgMenu — shared org switcher + user menu for all Hanzo apps
|
|
925
|
-
// ---------------------------------------------------------------------------
|
|
926
|
-
|
|
927
|
-
export interface UserOrgMenuProps {
|
|
928
|
-
/** Additional CSS class for the outer container. */
|
|
929
|
-
className?: string;
|
|
930
|
-
/** Called when org changes. Use to sync external state (e.g., tenantStore). */
|
|
931
|
-
onOrgChange?: (orgId: string) => void;
|
|
932
|
-
/** Called when user clicks logout. */
|
|
933
|
-
onLogout?: () => void;
|
|
934
|
-
/** Whether to show the "Create Organization" option. Defaults to true. */
|
|
935
|
-
showCreateOrg?: boolean;
|
|
936
|
-
/** Optional endpoint for org creation (defaults to IAM's /api/add-organization). */
|
|
937
|
-
createOrgEndpoint?: string;
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
/**
|
|
941
|
-
* Shared user menu + organization switcher for all Hanzo apps.
|
|
942
|
-
*
|
|
943
|
-
* Shows current user info (name, email, avatar), a dropdown with org list,
|
|
944
|
-
* "Create Organization" option, and logout button. Uses only `@hanzo/iam`
|
|
945
|
-
* hooks — no external UI library required.
|
|
946
|
-
*
|
|
947
|
-
* @example
|
|
948
|
-
* ```tsx
|
|
949
|
-
* import { UserOrgMenu } from '@hanzo/iam/react'
|
|
950
|
-
*
|
|
951
|
-
* function TopBar() {
|
|
952
|
-
* return (
|
|
953
|
-
* <nav>
|
|
954
|
-
* <UserOrgMenu
|
|
955
|
-
* onOrgChange={(orgId) => myStore.setOrg(orgId)}
|
|
956
|
-
* onLogout={() => router.push('/login')}
|
|
957
|
-
* />
|
|
958
|
-
* </nav>
|
|
959
|
-
* )
|
|
960
|
-
* }
|
|
961
|
-
* ```
|
|
962
|
-
*/
|
|
963
|
-
export function UserOrgMenu({
|
|
964
|
-
className = "",
|
|
965
|
-
onOrgChange,
|
|
966
|
-
onLogout,
|
|
967
|
-
showCreateOrg = true,
|
|
968
|
-
createOrgEndpoint,
|
|
969
|
-
}: UserOrgMenuProps) {
|
|
970
|
-
const { config, isAuthenticated, accessToken, user, logout } = useIam();
|
|
971
|
-
const orgState = useOrganizations();
|
|
972
|
-
const [open, setOpen] = useState(false);
|
|
973
|
-
const [createOpen, setCreateOpen] = useState(false);
|
|
974
|
-
const [newOrgName, setNewOrgName] = useState("");
|
|
975
|
-
const [newOrgDisplay, setNewOrgDisplay] = useState("");
|
|
976
|
-
const [creating, setCreating] = useState(false);
|
|
977
|
-
const [error, setError] = useState<string | null>(null);
|
|
978
|
-
const menuRef = useRef<HTMLDivElement>(null);
|
|
979
|
-
|
|
980
|
-
// Close on outside click
|
|
981
|
-
useEffect(() => {
|
|
982
|
-
const handler = (e: MouseEvent) => {
|
|
983
|
-
if (menuRef.current && !menuRef.current.contains(e.target as Node)) {
|
|
984
|
-
setOpen(false);
|
|
985
|
-
}
|
|
986
|
-
};
|
|
987
|
-
document.addEventListener("mousedown", handler);
|
|
988
|
-
return () => document.removeEventListener("mousedown", handler);
|
|
989
|
-
}, []);
|
|
990
|
-
|
|
991
|
-
const handleSwitchOrg = useCallback(
|
|
992
|
-
(orgId: string) => {
|
|
993
|
-
orgState.switchOrg(orgId);
|
|
994
|
-
onOrgChange?.(orgId);
|
|
995
|
-
setOpen(false);
|
|
996
|
-
},
|
|
997
|
-
[orgState, onOrgChange],
|
|
998
|
-
);
|
|
999
|
-
|
|
1000
|
-
const handleLogout = useCallback(() => {
|
|
1001
|
-
setOpen(false);
|
|
1002
|
-
if (onLogout) {
|
|
1003
|
-
onLogout();
|
|
1004
|
-
} else {
|
|
1005
|
-
logout?.();
|
|
1006
|
-
}
|
|
1007
|
-
}, [onLogout, logout]);
|
|
1008
|
-
|
|
1009
|
-
const handleCreateOrg = useCallback(async () => {
|
|
1010
|
-
const name = newOrgName.trim();
|
|
1011
|
-
if (!name) return;
|
|
1012
|
-
|
|
1013
|
-
setCreating(true);
|
|
1014
|
-
setError(null);
|
|
1015
|
-
|
|
1016
|
-
try {
|
|
1017
|
-
const client = new IamClient({
|
|
1018
|
-
serverUrl: config.serverUrl,
|
|
1019
|
-
clientId: config.clientId,
|
|
1020
|
-
});
|
|
1021
|
-
|
|
1022
|
-
if (createOrgEndpoint) {
|
|
1023
|
-
// Use custom endpoint (e.g., playground's /v1/orgs)
|
|
1024
|
-
const res = await fetch(createOrgEndpoint, {
|
|
1025
|
-
method: "POST",
|
|
1026
|
-
headers: {
|
|
1027
|
-
"Content-Type": "application/json",
|
|
1028
|
-
...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
|
|
1029
|
-
},
|
|
1030
|
-
body: JSON.stringify({
|
|
1031
|
-
name,
|
|
1032
|
-
displayName: newOrgDisplay.trim() || name,
|
|
1033
|
-
}),
|
|
1034
|
-
});
|
|
1035
|
-
if (!res.ok) {
|
|
1036
|
-
const body = await res.json().catch(() => ({}));
|
|
1037
|
-
throw new Error(body.error || body.msg || `HTTP ${res.status}`);
|
|
1038
|
-
}
|
|
1039
|
-
} else {
|
|
1040
|
-
// Use IAM directly
|
|
1041
|
-
await client.createOrganization(
|
|
1042
|
-
{ owner: "admin", name, displayName: newOrgDisplay.trim() || name },
|
|
1043
|
-
accessToken ?? undefined,
|
|
1044
|
-
);
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
// Switch to new org
|
|
1048
|
-
orgState.switchOrg(name);
|
|
1049
|
-
onOrgChange?.(name);
|
|
1050
|
-
setNewOrgName("");
|
|
1051
|
-
setNewOrgDisplay("");
|
|
1052
|
-
setCreateOpen(false);
|
|
1053
|
-
setOpen(false);
|
|
1054
|
-
|
|
1055
|
-
// Reload to refresh org list
|
|
1056
|
-
window.location.reload();
|
|
1057
|
-
} catch (e) {
|
|
1058
|
-
setError(e instanceof Error ? e.message : String(e));
|
|
1059
|
-
} finally {
|
|
1060
|
-
setCreating(false);
|
|
1061
|
-
}
|
|
1062
|
-
}, [newOrgName, newOrgDisplay, config, accessToken, createOrgEndpoint, orgState, onOrgChange]);
|
|
1063
|
-
|
|
1064
|
-
if (!isAuthenticated) return null;
|
|
1065
|
-
|
|
1066
|
-
const orgs = orgState.organizations ?? [];
|
|
1067
|
-
const currentLabel =
|
|
1068
|
-
orgs.find((o) => o.name === orgState.currentOrgId)?.displayName ??
|
|
1069
|
-
orgState.currentOrgId ??
|
|
1070
|
-
"Select org";
|
|
1071
|
-
|
|
1072
|
-
const userName = user?.displayName || user?.name || user?.email || "User";
|
|
1073
|
-
const userEmail = user?.email || "";
|
|
1074
|
-
const userAvatar = user?.avatar || "";
|
|
1075
|
-
|
|
1076
|
-
// Inline styles (no external CSS dependencies)
|
|
1077
|
-
const menuStyle: React.CSSProperties = {
|
|
1078
|
-
position: "absolute",
|
|
1079
|
-
top: "100%",
|
|
1080
|
-
right: 0,
|
|
1081
|
-
marginTop: 4,
|
|
1082
|
-
minWidth: 240,
|
|
1083
|
-
borderRadius: 8,
|
|
1084
|
-
border: "1px solid var(--border, #333)",
|
|
1085
|
-
background: "var(--popover, #1a1a1a)",
|
|
1086
|
-
color: "var(--popover-foreground, #fff)",
|
|
1087
|
-
boxShadow: "0 8px 32px rgba(0,0,0,0.4)",
|
|
1088
|
-
zIndex: 50,
|
|
1089
|
-
overflow: "hidden",
|
|
1090
|
-
};
|
|
1091
|
-
|
|
1092
|
-
const itemStyle: React.CSSProperties = {
|
|
1093
|
-
display: "flex",
|
|
1094
|
-
alignItems: "center",
|
|
1095
|
-
gap: 8,
|
|
1096
|
-
padding: "8px 12px",
|
|
1097
|
-
fontSize: 13,
|
|
1098
|
-
cursor: "pointer",
|
|
1099
|
-
transition: "background 0.1s",
|
|
1100
|
-
width: "100%",
|
|
1101
|
-
border: "none",
|
|
1102
|
-
background: "transparent",
|
|
1103
|
-
color: "inherit",
|
|
1104
|
-
textAlign: "left",
|
|
1105
|
-
};
|
|
1106
|
-
|
|
1107
|
-
const activeItemStyle: React.CSSProperties = {
|
|
1108
|
-
...itemStyle,
|
|
1109
|
-
background: "var(--accent, #2a2a2a)",
|
|
1110
|
-
};
|
|
1111
|
-
|
|
1112
|
-
const separatorStyle: React.CSSProperties = {
|
|
1113
|
-
height: 1,
|
|
1114
|
-
background: "var(--border, #333)",
|
|
1115
|
-
margin: "4px 0",
|
|
1116
|
-
};
|
|
1117
|
-
|
|
1118
|
-
const labelStyle: React.CSSProperties = {
|
|
1119
|
-
padding: "6px 12px",
|
|
1120
|
-
fontSize: 11,
|
|
1121
|
-
fontWeight: 600,
|
|
1122
|
-
textTransform: "uppercase" as const,
|
|
1123
|
-
letterSpacing: "0.05em",
|
|
1124
|
-
color: "var(--muted-foreground, #888)",
|
|
1125
|
-
};
|
|
1126
|
-
|
|
1127
|
-
return createElement(
|
|
1128
|
-
"div",
|
|
1129
|
-
{ ref: menuRef, className: `relative ${className}`, style: { position: "relative" } },
|
|
1130
|
-
|
|
1131
|
-
// Trigger button
|
|
1132
|
-
createElement(
|
|
1133
|
-
"button",
|
|
1134
|
-
{
|
|
1135
|
-
onClick: () => setOpen(!open),
|
|
1136
|
-
style: {
|
|
1137
|
-
display: "flex",
|
|
1138
|
-
alignItems: "center",
|
|
1139
|
-
gap: 8,
|
|
1140
|
-
padding: "6px 10px",
|
|
1141
|
-
borderRadius: 6,
|
|
1142
|
-
border: "none",
|
|
1143
|
-
background: "transparent",
|
|
1144
|
-
cursor: "pointer",
|
|
1145
|
-
color: "inherit",
|
|
1146
|
-
fontSize: 13,
|
|
1147
|
-
fontWeight: 500,
|
|
1148
|
-
},
|
|
1149
|
-
"aria-label": "User menu",
|
|
1150
|
-
},
|
|
1151
|
-
userAvatar
|
|
1152
|
-
? createElement("img", {
|
|
1153
|
-
src: userAvatar,
|
|
1154
|
-
alt: userName,
|
|
1155
|
-
style: { width: 24, height: 24, borderRadius: "50%", objectFit: "cover" as const },
|
|
1156
|
-
})
|
|
1157
|
-
: createElement(
|
|
1158
|
-
"div",
|
|
1159
|
-
{
|
|
1160
|
-
style: {
|
|
1161
|
-
width: 24,
|
|
1162
|
-
height: 24,
|
|
1163
|
-
borderRadius: "50%",
|
|
1164
|
-
background: "var(--primary, #3b82f6)",
|
|
1165
|
-
display: "flex",
|
|
1166
|
-
alignItems: "center",
|
|
1167
|
-
justifyContent: "center",
|
|
1168
|
-
fontSize: 11,
|
|
1169
|
-
fontWeight: 600,
|
|
1170
|
-
color: "#fff",
|
|
1171
|
-
},
|
|
1172
|
-
},
|
|
1173
|
-
userName.charAt(0).toUpperCase(),
|
|
1174
|
-
),
|
|
1175
|
-
createElement("span", { style: { maxWidth: 120, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const } }, currentLabel),
|
|
1176
|
-
createElement("span", { style: { fontSize: 10, opacity: 0.5 } }, open ? "\u25B2" : "\u25BC"),
|
|
1177
|
-
),
|
|
1178
|
-
|
|
1179
|
-
// Dropdown menu
|
|
1180
|
-
open &&
|
|
1181
|
-
createElement(
|
|
1182
|
-
"div",
|
|
1183
|
-
{ style: menuStyle },
|
|
1184
|
-
|
|
1185
|
-
// User info section
|
|
1186
|
-
createElement(
|
|
1187
|
-
"div",
|
|
1188
|
-
{ style: { padding: "10px 12px", borderBottom: "1px solid var(--border, #333)" } },
|
|
1189
|
-
createElement("div", { style: { fontSize: 13, fontWeight: 600 } }, userName),
|
|
1190
|
-
userEmail && createElement("div", { style: { fontSize: 11, opacity: 0.6, marginTop: 2 } }, userEmail),
|
|
1191
|
-
),
|
|
1192
|
-
|
|
1193
|
-
// Organization section
|
|
1194
|
-
createElement("div", { style: labelStyle }, "Organization"),
|
|
1195
|
-
...orgs.map((org) =>
|
|
1196
|
-
createElement(
|
|
1197
|
-
"button",
|
|
1198
|
-
{
|
|
1199
|
-
key: org.name,
|
|
1200
|
-
onClick: () => handleSwitchOrg(org.name),
|
|
1201
|
-
style: org.name === orgState.currentOrgId ? activeItemStyle : itemStyle,
|
|
1202
|
-
onMouseEnter: (e: React.MouseEvent<HTMLButtonElement>) => { (e.target as HTMLElement).style.background = "var(--accent, #2a2a2a)"; },
|
|
1203
|
-
onMouseLeave: (e: React.MouseEvent<HTMLButtonElement>) => { if (org.name !== orgState.currentOrgId) (e.target as HTMLElement).style.background = "transparent"; },
|
|
1204
|
-
},
|
|
1205
|
-
org.name === orgState.currentOrgId ? "\u2713 " : " ",
|
|
1206
|
-
org.displayName || org.name,
|
|
1207
|
-
),
|
|
1208
|
-
),
|
|
1209
|
-
|
|
1210
|
-
// Create org option
|
|
1211
|
-
showCreateOrg &&
|
|
1212
|
-
createElement(
|
|
1213
|
-
"div",
|
|
1214
|
-
null,
|
|
1215
|
-
createElement("div", { style: separatorStyle }),
|
|
1216
|
-
!createOpen
|
|
1217
|
-
? createElement(
|
|
1218
|
-
"button",
|
|
1219
|
-
{
|
|
1220
|
-
onClick: () => setCreateOpen(true),
|
|
1221
|
-
style: itemStyle,
|
|
1222
|
-
onMouseEnter: (e: React.MouseEvent<HTMLButtonElement>) => { (e.target as HTMLElement).style.background = "var(--accent, #2a2a2a)"; },
|
|
1223
|
-
onMouseLeave: (e: React.MouseEvent<HTMLButtonElement>) => { (e.target as HTMLElement).style.background = "transparent"; },
|
|
1224
|
-
},
|
|
1225
|
-
"+ Create Organization",
|
|
1226
|
-
)
|
|
1227
|
-
: createElement(
|
|
1228
|
-
"div",
|
|
1229
|
-
{ style: { padding: "8px 12px" } },
|
|
1230
|
-
createElement("input", {
|
|
1231
|
-
type: "text",
|
|
1232
|
-
placeholder: "org-name",
|
|
1233
|
-
value: newOrgName,
|
|
1234
|
-
onChange: (e: React.ChangeEvent<HTMLInputElement>) => setNewOrgName(e.target.value),
|
|
1235
|
-
style: {
|
|
1236
|
-
width: "100%",
|
|
1237
|
-
padding: "6px 8px",
|
|
1238
|
-
fontSize: 12,
|
|
1239
|
-
borderRadius: 4,
|
|
1240
|
-
border: "1px solid var(--border, #333)",
|
|
1241
|
-
background: "var(--background, #111)",
|
|
1242
|
-
color: "inherit",
|
|
1243
|
-
marginBottom: 4,
|
|
1244
|
-
},
|
|
1245
|
-
disabled: creating,
|
|
1246
|
-
}),
|
|
1247
|
-
createElement("input", {
|
|
1248
|
-
type: "text",
|
|
1249
|
-
placeholder: "Display Name",
|
|
1250
|
-
value: newOrgDisplay,
|
|
1251
|
-
onChange: (e: React.ChangeEvent<HTMLInputElement>) => setNewOrgDisplay(e.target.value),
|
|
1252
|
-
style: {
|
|
1253
|
-
width: "100%",
|
|
1254
|
-
padding: "6px 8px",
|
|
1255
|
-
fontSize: 12,
|
|
1256
|
-
borderRadius: 4,
|
|
1257
|
-
border: "1px solid var(--border, #333)",
|
|
1258
|
-
background: "var(--background, #111)",
|
|
1259
|
-
color: "inherit",
|
|
1260
|
-
marginBottom: 4,
|
|
1261
|
-
},
|
|
1262
|
-
disabled: creating,
|
|
1263
|
-
}),
|
|
1264
|
-
error && createElement("div", { style: { fontSize: 11, color: "#ef4444", marginBottom: 4 } }, error),
|
|
1265
|
-
createElement(
|
|
1266
|
-
"div",
|
|
1267
|
-
{ style: { display: "flex", gap: 4 } },
|
|
1268
|
-
createElement(
|
|
1269
|
-
"button",
|
|
1270
|
-
{
|
|
1271
|
-
onClick: handleCreateOrg,
|
|
1272
|
-
disabled: creating || !newOrgName.trim(),
|
|
1273
|
-
style: {
|
|
1274
|
-
flex: 1,
|
|
1275
|
-
padding: "5px 8px",
|
|
1276
|
-
fontSize: 12,
|
|
1277
|
-
borderRadius: 4,
|
|
1278
|
-
border: "none",
|
|
1279
|
-
background: "var(--primary, #3b82f6)",
|
|
1280
|
-
color: "#fff",
|
|
1281
|
-
cursor: creating ? "wait" : "pointer",
|
|
1282
|
-
opacity: creating || !newOrgName.trim() ? 0.5 : 1,
|
|
1283
|
-
},
|
|
1284
|
-
},
|
|
1285
|
-
creating ? "Creating..." : "Create",
|
|
1286
|
-
),
|
|
1287
|
-
createElement(
|
|
1288
|
-
"button",
|
|
1289
|
-
{
|
|
1290
|
-
onClick: () => { setCreateOpen(false); setError(null); },
|
|
1291
|
-
style: {
|
|
1292
|
-
padding: "5px 8px",
|
|
1293
|
-
fontSize: 12,
|
|
1294
|
-
borderRadius: 4,
|
|
1295
|
-
border: "1px solid var(--border, #333)",
|
|
1296
|
-
background: "transparent",
|
|
1297
|
-
color: "inherit",
|
|
1298
|
-
cursor: "pointer",
|
|
1299
|
-
},
|
|
1300
|
-
},
|
|
1301
|
-
"Cancel",
|
|
1302
|
-
),
|
|
1303
|
-
),
|
|
1304
|
-
),
|
|
1305
|
-
),
|
|
1306
|
-
|
|
1307
|
-
// Logout
|
|
1308
|
-
createElement("div", { style: separatorStyle }),
|
|
1309
|
-
createElement(
|
|
1310
|
-
"button",
|
|
1311
|
-
{
|
|
1312
|
-
onClick: handleLogout,
|
|
1313
|
-
style: { ...itemStyle, color: "var(--destructive, #ef4444)" },
|
|
1314
|
-
onMouseEnter: (e: React.MouseEvent<HTMLButtonElement>) => { (e.target as HTMLElement).style.background = "var(--accent, #2a2a2a)"; },
|
|
1315
|
-
onMouseLeave: (e: React.MouseEvent<HTMLButtonElement>) => { (e.target as HTMLElement).style.background = "transparent"; },
|
|
1316
|
-
},
|
|
1317
|
-
"Sign out",
|
|
1318
|
-
),
|
|
1319
|
-
),
|
|
1320
|
-
);
|
|
1321
|
-
}
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Core types for the Hanzo IAM SDK.
|
|
3
|
-
*
|
|
3
|
+
* Hanzo IAM data models.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// ---------------------------------------------------------------------------
|
|
@@ -226,26 +226,6 @@ export type IamOrder = Order;
|
|
|
226
226
|
export type IamUsageRecord = UsageRecord;
|
|
227
227
|
export type IamUsageSummary = UsageSummary;
|
|
228
228
|
|
|
229
|
-
// ---------------------------------------------------------------------------
|
|
230
|
-
// Invitation
|
|
231
|
-
// ---------------------------------------------------------------------------
|
|
232
|
-
|
|
233
|
-
export type IamInvitation = {
|
|
234
|
-
owner: string;
|
|
235
|
-
name: string;
|
|
236
|
-
displayName?: string;
|
|
237
|
-
code: string;
|
|
238
|
-
quota: number;
|
|
239
|
-
usedCount: number;
|
|
240
|
-
application?: string;
|
|
241
|
-
email?: string;
|
|
242
|
-
phone?: string;
|
|
243
|
-
signupGroup?: string;
|
|
244
|
-
state?: string;
|
|
245
|
-
createdTime?: string;
|
|
246
|
-
updatedTime?: string;
|
|
247
|
-
};
|
|
248
|
-
|
|
249
229
|
// ---------------------------------------------------------------------------
|
|
250
230
|
// Project
|
|
251
231
|
// ---------------------------------------------------------------------------
|