@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/react.d.ts CHANGED
@@ -34,7 +34,7 @@
34
34
  import type { ReactNode } from "react";
35
35
  import { BrowserIamSdk } from "./browser.js";
36
36
  import type { BrowserIamConfig } from "./browser.js";
37
- import type { IamUser, IamOrganization, IamInvitation, IamProject, TokenResponse } from "./types.js";
37
+ import type { IamUser, IamOrganization, IamProject, TokenResponse } from "./types.js";
38
38
  export interface IamProviderProps {
39
39
  /** Browser IAM SDK configuration. */
40
40
  config: BrowserIamConfig;
@@ -123,50 +123,6 @@ export declare function useIamToken(): {
123
123
  isValid: boolean;
124
124
  refresh: () => Promise<string | null>;
125
125
  };
126
- export interface OrgManagementState {
127
- /** Create a new organization. */
128
- createOrg: (org: Partial<IamOrganization>) => Promise<void>;
129
- /** Update an existing organization. */
130
- updateOrg: (org: Partial<IamOrganization>) => Promise<void>;
131
- /** Delete an organization by owner and name. */
132
- deleteOrg: (org: {
133
- owner: string;
134
- name: string;
135
- }) => Promise<void>;
136
- /** Whether a mutation is in progress. */
137
- isLoading: boolean;
138
- }
139
- /**
140
- * Manage organization CRUD operations.
141
- *
142
- * Provides create, update, and delete methods that call the IAM API
143
- * using the current user's access token.
144
- */
145
- export declare function useOrgManagement(): OrgManagementState;
146
- export interface InvitationsState {
147
- /** All invitations for the organization. */
148
- invitations: IamInvitation[];
149
- /** Create a new invitation. */
150
- createInvite: (invitation: Partial<IamInvitation>) => Promise<void>;
151
- /** Send an existing invitation. */
152
- sendInvite: (invitation: {
153
- owner: string;
154
- name: string;
155
- }) => Promise<void>;
156
- /** Verify an invitation code. */
157
- verifyInvite: (code: string) => Promise<IamInvitation | null>;
158
- /** Whether invitations are loading. */
159
- isLoading: boolean;
160
- /** Re-fetch the invitations list. */
161
- refresh: () => Promise<void>;
162
- }
163
- /**
164
- * Manage invitations for an organization.
165
- *
166
- * Fetches the invitation list on mount and provides create, send,
167
- * and verify methods using the current user's access token.
168
- */
169
- export declare function useInvitations(orgName: string): InvitationsState;
170
126
  export { IamContext };
171
127
  export interface OrgProjectSwitcherProps {
172
128
  organizations: Array<{
@@ -205,46 +161,4 @@ export interface OrgProjectSwitcherProps {
205
161
  export declare function OrgProjectSwitcher({ organizations, currentOrgId, switchOrg, projects, currentProjectId, switchProject, onTenantChange, environment, className, alwaysShow, }: OrgProjectSwitcherProps): import("react").DetailedReactHTMLElement<{
206
162
  className: string;
207
163
  }, HTMLElement> | null;
208
- export interface UserOrgMenuProps {
209
- /** Additional CSS class for the outer container. */
210
- className?: string;
211
- /** Called when org changes. Use to sync external state (e.g., tenantStore). */
212
- onOrgChange?: (orgId: string) => void;
213
- /** Called when user clicks logout. */
214
- onLogout?: () => void;
215
- /** Whether to show the "Create Organization" option. Defaults to true. */
216
- showCreateOrg?: boolean;
217
- /** Optional endpoint for org creation (defaults to IAM's /api/add-organization). */
218
- createOrgEndpoint?: string;
219
- }
220
- /**
221
- * Shared user menu + organization switcher for all Hanzo apps.
222
- *
223
- * Shows current user info (name, email, avatar), a dropdown with org list,
224
- * "Create Organization" option, and logout button. Uses only `@hanzo/iam`
225
- * hooks — no external UI library required.
226
- *
227
- * @example
228
- * ```tsx
229
- * import { UserOrgMenu } from '@hanzo/iam/react'
230
- *
231
- * function TopBar() {
232
- * return (
233
- * <nav>
234
- * <UserOrgMenu
235
- * onOrgChange={(orgId) => myStore.setOrg(orgId)}
236
- * onLogout={() => router.push('/login')}
237
- * />
238
- * </nav>
239
- * )
240
- * }
241
- * ```
242
- */
243
- export declare function UserOrgMenu({ className, onOrgChange, onLogout, showCreateOrg, createOrgEndpoint, }: UserOrgMenuProps): import("react").DetailedReactHTMLElement<{
244
- ref: import("react").RefObject<HTMLDivElement | null>;
245
- className: string;
246
- style: {
247
- position: "relative";
248
- };
249
- }, HTMLDivElement> | null;
250
164
  //# sourceMappingURL=react.d.ts.map
@@ -1 +1 @@
1
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AAkB,CAAC,EACjC,aAAa,EACb,YAAY,EACZ,SAAS,EACT,QAAa,EACb,gBAAuB,EACvB,aAAa,EACb,cAAc,EACd,WAAW,EACX,SAAc,EACd,UAAkB,GACnB,EAAE,uBAAuB;;uBAmFzB"}
package/dist/react.js CHANGED
@@ -297,33 +297,27 @@ export function useOrganizations() {
297
297
  let cancelled = false;
298
298
  const fetchOrgs = async () => {
299
299
  setIsLoading(true);
300
- // 1. Parse JWT claims for user's workspace org (immediate, no API call)
301
- // The user's "owner" is the signup org (for auth). Their personal org
302
- // (name == username) is their actual workspace.
300
+ // 1. Parse JWT sub claim for primary org (immediate, no API call)
303
301
  try {
304
- let b64 = accessToken.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
305
- while (b64.length % 4)
306
- b64 += "=";
307
- const payload = JSON.parse(atob(b64));
308
- const userOwner = payload.owner ?? "";
309
- const userName = payload.name ?? "";
310
- const sub = payload.sub ?? "";
311
- // Personal org is the default workspace
312
- const workspaceOrg = (userName && userName !== userOwner)
313
- ? userName
314
- : userOwner || (sub.includes("/") ? sub.split("/")[0] : "");
315
- if (workspaceOrg && !cancelled) {
316
- const immediateOrgs = [
317
- { owner: "admin", name: workspaceOrg, displayName: workspaceOrg },
318
- ];
319
- setOrganizations(immediateOrgs);
320
- if (!currentOrgId) {
321
- setCurrentOrgId(workspaceOrg);
322
- try {
323
- localStorage.setItem(STORAGE_ORG_KEY, workspaceOrg);
324
- }
325
- catch {
326
- /* ok */
302
+ const payload = JSON.parse(atob(accessToken.split(".")[1]));
303
+ const sub = payload.sub;
304
+ if (sub?.includes("/")) {
305
+ const primaryOrg = sub.split("/")[0];
306
+ if (!cancelled) {
307
+ const syntheticOrg = {
308
+ owner: "admin",
309
+ name: primaryOrg,
310
+ displayName: primaryOrg,
311
+ };
312
+ setOrganizations([syntheticOrg]);
313
+ if (!currentOrgId) {
314
+ setCurrentOrgId(primaryOrg);
315
+ try {
316
+ localStorage.setItem(STORAGE_ORG_KEY, primaryOrg);
317
+ }
318
+ catch {
319
+ /* ok */
320
+ }
327
321
  }
328
322
  }
329
323
  }
@@ -470,137 +464,6 @@ export function useIamToken() {
470
464
  refresh,
471
465
  };
472
466
  }
473
- /**
474
- * Manage organization CRUD operations.
475
- *
476
- * Provides create, update, and delete methods that call the IAM API
477
- * using the current user's access token.
478
- */
479
- export function useOrgManagement() {
480
- const { config, accessToken } = useIam();
481
- const [isLoading, setIsLoading] = useState(false);
482
- const client = useMemo(() => new IamClient({
483
- serverUrl: config.serverUrl,
484
- clientId: config.clientId,
485
- }), [config.serverUrl, config.clientId]);
486
- const createOrg = useCallback(async (org) => {
487
- setIsLoading(true);
488
- try {
489
- await client.createOrganization(org, accessToken ?? undefined);
490
- }
491
- finally {
492
- setIsLoading(false);
493
- }
494
- }, [client, accessToken]);
495
- const updateOrg = useCallback(async (org) => {
496
- setIsLoading(true);
497
- try {
498
- await client.updateOrganization(org, accessToken ?? undefined);
499
- }
500
- finally {
501
- setIsLoading(false);
502
- }
503
- }, [client, accessToken]);
504
- const deleteOrg = useCallback(async (org) => {
505
- setIsLoading(true);
506
- try {
507
- await client.deleteOrganization(org, accessToken ?? undefined);
508
- }
509
- finally {
510
- setIsLoading(false);
511
- }
512
- }, [client, accessToken]);
513
- return { createOrg, updateOrg, deleteOrg, isLoading };
514
- }
515
- /**
516
- * Manage invitations for an organization.
517
- *
518
- * Fetches the invitation list on mount and provides create, send,
519
- * and verify methods using the current user's access token.
520
- */
521
- export function useInvitations(orgName) {
522
- const { config, accessToken, isAuthenticated } = useIam();
523
- const [invitations, setInvitations] = useState([]);
524
- const [isLoading, setIsLoading] = useState(false);
525
- const client = useMemo(() => new IamClient({
526
- serverUrl: config.serverUrl,
527
- clientId: config.clientId,
528
- }), [config.serverUrl, config.clientId]);
529
- const fetchInvitations = useCallback(async () => {
530
- if (!isAuthenticated || !accessToken || !orgName)
531
- return;
532
- setIsLoading(true);
533
- try {
534
- const data = await client.getInvitations(orgName, accessToken);
535
- setInvitations(data);
536
- }
537
- catch {
538
- setInvitations([]);
539
- }
540
- finally {
541
- setIsLoading(false);
542
- }
543
- }, [client, orgName, accessToken, isAuthenticated]);
544
- // Fetch invitations on mount and when orgName changes
545
- useEffect(() => {
546
- if (!isAuthenticated || !accessToken || !orgName) {
547
- setInvitations([]);
548
- return;
549
- }
550
- let cancelled = false;
551
- const load = async () => {
552
- setIsLoading(true);
553
- try {
554
- const data = await client.getInvitations(orgName, accessToken);
555
- if (!cancelled)
556
- setInvitations(data);
557
- }
558
- catch {
559
- if (!cancelled)
560
- setInvitations([]);
561
- }
562
- finally {
563
- if (!cancelled)
564
- setIsLoading(false);
565
- }
566
- };
567
- load();
568
- return () => {
569
- cancelled = true;
570
- };
571
- // eslint-disable-next-line react-hooks/exhaustive-deps
572
- }, [isAuthenticated, accessToken, orgName, config.serverUrl, config.clientId]);
573
- const createInvite = useCallback(async (invitation) => {
574
- setIsLoading(true);
575
- try {
576
- await client.createInvitation(invitation, accessToken ?? undefined);
577
- await fetchInvitations();
578
- }
579
- finally {
580
- setIsLoading(false);
581
- }
582
- }, [client, accessToken, fetchInvitations]);
583
- const sendInvite = useCallback(async (invitation) => {
584
- setIsLoading(true);
585
- try {
586
- await client.sendInvitation(invitation, accessToken ?? undefined);
587
- }
588
- finally {
589
- setIsLoading(false);
590
- }
591
- }, [client, accessToken]);
592
- const verifyInvite = useCallback(async (code) => {
593
- setIsLoading(true);
594
- try {
595
- const resp = await client.verifyInvitation(code, accessToken ?? undefined);
596
- return resp.data ?? null;
597
- }
598
- finally {
599
- setIsLoading(false);
600
- }
601
- }, [client, accessToken]);
602
- return { invitations, createInvite, sendInvite, verifyInvite, isLoading, refresh: fetchInvitations };
603
- }
604
467
  // Re-export context for advanced use
605
468
  export { IamContext };
606
469
  /**
@@ -656,293 +519,4 @@ export function OrgProjectSwitcher({ organizations, currentOrgId, switchOrg, pro
656
519
  ? createElement("span", { className: "rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground" }, environment)
657
520
  : null);
658
521
  }
659
- /**
660
- * Shared user menu + organization switcher for all Hanzo apps.
661
- *
662
- * Shows current user info (name, email, avatar), a dropdown with org list,
663
- * "Create Organization" option, and logout button. Uses only `@hanzo/iam`
664
- * hooks — no external UI library required.
665
- *
666
- * @example
667
- * ```tsx
668
- * import { UserOrgMenu } from '@hanzo/iam/react'
669
- *
670
- * function TopBar() {
671
- * return (
672
- * <nav>
673
- * <UserOrgMenu
674
- * onOrgChange={(orgId) => myStore.setOrg(orgId)}
675
- * onLogout={() => router.push('/login')}
676
- * />
677
- * </nav>
678
- * )
679
- * }
680
- * ```
681
- */
682
- export function UserOrgMenu({ className = "", onOrgChange, onLogout, showCreateOrg = true, createOrgEndpoint, }) {
683
- const { config, isAuthenticated, accessToken, user, logout } = useIam();
684
- const orgState = useOrganizations();
685
- const [open, setOpen] = useState(false);
686
- const [createOpen, setCreateOpen] = useState(false);
687
- const [newOrgName, setNewOrgName] = useState("");
688
- const [newOrgDisplay, setNewOrgDisplay] = useState("");
689
- const [creating, setCreating] = useState(false);
690
- const [error, setError] = useState(null);
691
- const menuRef = useRef(null);
692
- // Close on outside click
693
- useEffect(() => {
694
- const handler = (e) => {
695
- if (menuRef.current && !menuRef.current.contains(e.target)) {
696
- setOpen(false);
697
- }
698
- };
699
- document.addEventListener("mousedown", handler);
700
- return () => document.removeEventListener("mousedown", handler);
701
- }, []);
702
- const handleSwitchOrg = useCallback((orgId) => {
703
- orgState.switchOrg(orgId);
704
- onOrgChange?.(orgId);
705
- setOpen(false);
706
- }, [orgState, onOrgChange]);
707
- const handleLogout = useCallback(() => {
708
- setOpen(false);
709
- if (onLogout) {
710
- onLogout();
711
- }
712
- else {
713
- logout?.();
714
- }
715
- }, [onLogout, logout]);
716
- const handleCreateOrg = useCallback(async () => {
717
- const name = newOrgName.trim();
718
- if (!name)
719
- return;
720
- setCreating(true);
721
- setError(null);
722
- try {
723
- const client = new IamClient({
724
- serverUrl: config.serverUrl,
725
- clientId: config.clientId,
726
- });
727
- if (createOrgEndpoint) {
728
- // Use custom endpoint (e.g., playground's /v1/orgs)
729
- const res = await fetch(createOrgEndpoint, {
730
- method: "POST",
731
- headers: {
732
- "Content-Type": "application/json",
733
- ...(accessToken ? { Authorization: `Bearer ${accessToken}` } : {}),
734
- },
735
- body: JSON.stringify({
736
- name,
737
- displayName: newOrgDisplay.trim() || name,
738
- }),
739
- });
740
- if (!res.ok) {
741
- const body = await res.json().catch(() => ({}));
742
- throw new Error(body.error || body.msg || `HTTP ${res.status}`);
743
- }
744
- }
745
- else {
746
- // Use IAM directly
747
- await client.createOrganization({ owner: "admin", name, displayName: newOrgDisplay.trim() || name }, accessToken ?? undefined);
748
- }
749
- // Switch to new org
750
- orgState.switchOrg(name);
751
- onOrgChange?.(name);
752
- setNewOrgName("");
753
- setNewOrgDisplay("");
754
- setCreateOpen(false);
755
- setOpen(false);
756
- // Reload to refresh org list
757
- window.location.reload();
758
- }
759
- catch (e) {
760
- setError(e instanceof Error ? e.message : String(e));
761
- }
762
- finally {
763
- setCreating(false);
764
- }
765
- }, [newOrgName, newOrgDisplay, config, accessToken, createOrgEndpoint, orgState, onOrgChange]);
766
- if (!isAuthenticated)
767
- return null;
768
- const orgs = orgState.organizations ?? [];
769
- const currentLabel = orgs.find((o) => o.name === orgState.currentOrgId)?.displayName ??
770
- orgState.currentOrgId ??
771
- "Select org";
772
- const userName = user?.displayName || user?.name || user?.email || "User";
773
- const userEmail = user?.email || "";
774
- const userAvatar = user?.avatar || "";
775
- // Inline styles (no external CSS dependencies)
776
- const menuStyle = {
777
- position: "absolute",
778
- top: "100%",
779
- right: 0,
780
- marginTop: 4,
781
- minWidth: 240,
782
- borderRadius: 8,
783
- border: "1px solid var(--border, #333)",
784
- background: "var(--popover, #1a1a1a)",
785
- color: "var(--popover-foreground, #fff)",
786
- boxShadow: "0 8px 32px rgba(0,0,0,0.4)",
787
- zIndex: 50,
788
- overflow: "hidden",
789
- };
790
- const itemStyle = {
791
- display: "flex",
792
- alignItems: "center",
793
- gap: 8,
794
- padding: "8px 12px",
795
- fontSize: 13,
796
- cursor: "pointer",
797
- transition: "background 0.1s",
798
- width: "100%",
799
- border: "none",
800
- background: "transparent",
801
- color: "inherit",
802
- textAlign: "left",
803
- };
804
- const activeItemStyle = {
805
- ...itemStyle,
806
- background: "var(--accent, #2a2a2a)",
807
- };
808
- const separatorStyle = {
809
- height: 1,
810
- background: "var(--border, #333)",
811
- margin: "4px 0",
812
- };
813
- const labelStyle = {
814
- padding: "6px 12px",
815
- fontSize: 11,
816
- fontWeight: 600,
817
- textTransform: "uppercase",
818
- letterSpacing: "0.05em",
819
- color: "var(--muted-foreground, #888)",
820
- };
821
- return createElement("div", { ref: menuRef, className: `relative ${className}`, style: { position: "relative" } },
822
- // Trigger button
823
- createElement("button", {
824
- onClick: () => setOpen(!open),
825
- style: {
826
- display: "flex",
827
- alignItems: "center",
828
- gap: 8,
829
- padding: "6px 10px",
830
- borderRadius: 6,
831
- border: "none",
832
- background: "transparent",
833
- cursor: "pointer",
834
- color: "inherit",
835
- fontSize: 13,
836
- fontWeight: 500,
837
- },
838
- "aria-label": "User menu",
839
- }, userAvatar
840
- ? createElement("img", {
841
- src: userAvatar,
842
- alt: userName,
843
- style: { width: 24, height: 24, borderRadius: "50%", objectFit: "cover" },
844
- })
845
- : createElement("div", {
846
- style: {
847
- width: 24,
848
- height: 24,
849
- borderRadius: "50%",
850
- background: "var(--primary, #3b82f6)",
851
- display: "flex",
852
- alignItems: "center",
853
- justifyContent: "center",
854
- fontSize: 11,
855
- fontWeight: 600,
856
- color: "#fff",
857
- },
858
- }, userName.charAt(0).toUpperCase()), createElement("span", { style: { maxWidth: 120, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, currentLabel), createElement("span", { style: { fontSize: 10, opacity: 0.5 } }, open ? "\u25B2" : "\u25BC")),
859
- // Dropdown menu
860
- open &&
861
- createElement("div", { style: menuStyle },
862
- // User info section
863
- createElement("div", { style: { padding: "10px 12px", borderBottom: "1px solid var(--border, #333)" } }, createElement("div", { style: { fontSize: 13, fontWeight: 600 } }, userName), userEmail && createElement("div", { style: { fontSize: 11, opacity: 0.6, marginTop: 2 } }, userEmail)),
864
- // Organization section
865
- createElement("div", { style: labelStyle }, "Organization"), ...orgs.map((org) => createElement("button", {
866
- key: org.name,
867
- onClick: () => handleSwitchOrg(org.name),
868
- style: org.name === orgState.currentOrgId ? activeItemStyle : itemStyle,
869
- onMouseEnter: (e) => { e.target.style.background = "var(--accent, #2a2a2a)"; },
870
- onMouseLeave: (e) => { if (org.name !== orgState.currentOrgId)
871
- e.target.style.background = "transparent"; },
872
- }, org.name === orgState.currentOrgId ? "\u2713 " : " ", org.displayName || org.name)),
873
- // Create org option
874
- showCreateOrg &&
875
- createElement("div", null, createElement("div", { style: separatorStyle }), !createOpen
876
- ? createElement("button", {
877
- onClick: () => setCreateOpen(true),
878
- style: itemStyle,
879
- onMouseEnter: (e) => { e.target.style.background = "var(--accent, #2a2a2a)"; },
880
- onMouseLeave: (e) => { e.target.style.background = "transparent"; },
881
- }, "+ Create Organization")
882
- : createElement("div", { style: { padding: "8px 12px" } }, createElement("input", {
883
- type: "text",
884
- placeholder: "org-name",
885
- value: newOrgName,
886
- onChange: (e) => setNewOrgName(e.target.value),
887
- style: {
888
- width: "100%",
889
- padding: "6px 8px",
890
- fontSize: 12,
891
- borderRadius: 4,
892
- border: "1px solid var(--border, #333)",
893
- background: "var(--background, #111)",
894
- color: "inherit",
895
- marginBottom: 4,
896
- },
897
- disabled: creating,
898
- }), createElement("input", {
899
- type: "text",
900
- placeholder: "Display Name",
901
- value: newOrgDisplay,
902
- onChange: (e) => setNewOrgDisplay(e.target.value),
903
- style: {
904
- width: "100%",
905
- padding: "6px 8px",
906
- fontSize: 12,
907
- borderRadius: 4,
908
- border: "1px solid var(--border, #333)",
909
- background: "var(--background, #111)",
910
- color: "inherit",
911
- marginBottom: 4,
912
- },
913
- disabled: creating,
914
- }), error && createElement("div", { style: { fontSize: 11, color: "#ef4444", marginBottom: 4 } }, error), createElement("div", { style: { display: "flex", gap: 4 } }, createElement("button", {
915
- onClick: handleCreateOrg,
916
- disabled: creating || !newOrgName.trim(),
917
- style: {
918
- flex: 1,
919
- padding: "5px 8px",
920
- fontSize: 12,
921
- borderRadius: 4,
922
- border: "none",
923
- background: "var(--primary, #3b82f6)",
924
- color: "#fff",
925
- cursor: creating ? "wait" : "pointer",
926
- opacity: creating || !newOrgName.trim() ? 0.5 : 1,
927
- },
928
- }, creating ? "Creating..." : "Create"), createElement("button", {
929
- onClick: () => { setCreateOpen(false); setError(null); },
930
- style: {
931
- padding: "5px 8px",
932
- fontSize: 12,
933
- borderRadius: 4,
934
- border: "1px solid var(--border, #333)",
935
- background: "transparent",
936
- color: "inherit",
937
- cursor: "pointer",
938
- },
939
- }, "Cancel")))),
940
- // Logout
941
- createElement("div", { style: separatorStyle }), createElement("button", {
942
- onClick: handleLogout,
943
- style: { ...itemStyle, color: "var(--destructive, #ef4444)" },
944
- onMouseEnter: (e) => { e.target.style.background = "var(--accent, #2a2a2a)"; },
945
- onMouseLeave: (e) => { e.target.style.background = "transparent"; },
946
- }, "Sign out")));
947
- }
948
522
  //# sourceMappingURL=react.js.map