@enterprisestandard/react 0.0.20-beta.20260522.3 → 0.0.20-beta.20260615.1

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.ts CHANGED
@@ -1,25 +1,113 @@
1
1
  export * from "@enterprisestandard/core";
2
+ import { generateULID } from "@enterprisestandard/core";
3
+ import { Customer, Logger } from "@enterprisestandard/core";
4
+ import { ReactNode as ReactNode2 } from "react";
5
+ type StorageType = "local" | "session" | "memory";
6
+ interface CIAMProviderProps {
7
+ customerUrl: string;
8
+ /** Optional storage key. When provided, this key is used for localStorage/sessionStorage; otherwise `'es.ciam.customer'` is used. */
9
+ storageKey?: string;
10
+ storage?: StorageType;
11
+ disableListener?: boolean;
12
+ log?: Logger;
13
+ children: ReactNode2;
14
+ }
15
+ interface CIAMContext {
16
+ customer: Customer | null;
17
+ setCustomer: (customer: Customer | null) => void;
18
+ isLoading: boolean;
19
+ }
20
+ declare function CIAMProvider({ storageKey: storageKeyProp, customerUrl, storage, disableListener, log, children }: CIAMProviderProps): React.ReactNode2;
21
+ declare function useCIAMContext(): CIAMContext;
22
+ /** Non-throwing variant; returns undefined when no CIAMProvider is present. */
23
+ declare function useOptionalCIAMContext(): CIAMContext | undefined;
24
+ declare function getCustomer(customerUrl: string, storageKey?: string): Promise<Customer | undefined>;
25
+ declare function logoutCustomer(logoutUrl: string): Promise<{
26
+ success: boolean;
27
+ error?: string;
28
+ }>;
29
+ import { CIAMProviderDescriptor, Logger as Logger2 } from "@enterprisestandard/core";
30
+ import { ReactNode as ReactNode3 } from "react";
31
+ type UseCIAMProvidersResult = {
32
+ /** Providers in the recommended display order returned by the discovery endpoint. */
33
+ providers: CIAMProviderDescriptor[];
34
+ isLoading: boolean;
35
+ error: Error | null;
36
+ /** Re-fetch the provider list. */
37
+ refresh: () => void;
38
+ };
39
+ /**
40
+ * Fetch the sanitized, ordered list of CIAM customer-login providers from the
41
+ * discovery endpoint (`${basePath}/auth/customer/providers`). The list is
42
+ * returned in the recommended presentation order declared in RemoteConfig; do
43
+ * not re-sort it.
44
+ */
45
+ declare function useCIAMProviders(providersUrl: string, log?: Logger2): UseCIAMProvidersResult;
46
+ type CIAMProviderListProps = {
47
+ /** Discovery endpoint URL (`${basePath}/auth/customer/providers`). */
48
+ providersUrl: string;
49
+ /**
50
+ * Maximum number of providers to show initially. Remaining providers are
51
+ * revealed via a "Show more" affordance. Preserves recommended order.
52
+ */
53
+ limit?: number;
54
+ /** Resolve the theme used to pick a provider's branding color. Defaults to 'light'. */
55
+ theme?: "light" | "dark";
56
+ /** Optional render override for a single provider entry (headless usage). */
57
+ renderProvider?: (provider: CIAMProviderDescriptor) => ReactNode3;
58
+ /** Rendered while the provider list is loading. */
59
+ loadingFallback?: ReactNode3;
60
+ /** Rendered when no providers are available. */
61
+ emptyFallback?: ReactNode3;
62
+ /** Label for the "show more" button. */
63
+ moreLabel?: string;
64
+ className?: string;
65
+ log?: Logger2;
66
+ };
67
+ /**
68
+ * Renders the CIAM customer-login providers as branded buttons in the
69
+ * recommended order. Each entry navigates to its SDK-derived `loginUrl`
70
+ * (mirrors the SSO `<a href={LOGIN_URL}>` pattern). Supports an optional
71
+ * `limit` (first N + "show more") that preserves order by default.
72
+ */
73
+ declare function CIAMProviderList({ providersUrl, limit, theme, renderProvider, loadingFallback, emptyFallback, moreLabel, className, log }: CIAMProviderListProps): React.ReactNode3;
2
74
  import { PropsWithChildren } from "react";
3
- declare function SignInLoading({ complete, children }: {
75
+ type Audience = "workforce" | "customer";
76
+ declare function SignInLoading({ complete, audience, children }: {
4
77
  complete?: boolean;
78
+ audience?: Audience;
5
79
  } & PropsWithChildren): React.ReactNode;
6
80
  import { PropsWithChildren as PropsWithChildren2 } from "react";
7
- declare function SignedIn({ children }: PropsWithChildren2): React.ReactNode;
81
+ type Audience2 = "workforce" | "customer";
82
+ declare function SignedIn({ audience, children }: {
83
+ audience?: Audience2;
84
+ } & PropsWithChildren2): React.ReactNode;
8
85
  import { PropsWithChildren as PropsWithChildren3 } from "react";
9
- declare function SignedOut({ children }: PropsWithChildren3): React.ReactNode;
10
- import { Logger, WorkforceUser } from "@enterprisestandard/core";
11
- import { ReactNode as ReactNode2 } from "react";
12
- type StorageType = "local" | "session" | "memory";
86
+ type Audience3 = "workforce" | "customer";
87
+ declare function SignedOut({ audience, children }: {
88
+ audience?: Audience3;
89
+ } & PropsWithChildren3): React.ReactNode;
90
+ import { Logger as Logger3, WorkforceUser } from "@enterprisestandard/core";
91
+ import { ReactNode as ReactNode4 } from "react";
92
+ type StorageType2 = "local" | "session" | "memory";
13
93
  interface SSOProviderProps {
14
94
  userUrl: string;
15
95
  /** Optional storage key. When provided, this key is used for localStorage/sessionStorage; otherwise `'es.sso.user'` is used. */
16
96
  storageKey?: string;
17
- storage?: StorageType;
97
+ storage?: StorageType2;
18
98
  disableListener?: boolean;
19
- log?: Logger;
20
- children: ReactNode2;
99
+ log?: Logger3;
100
+ children: ReactNode4;
101
+ }
102
+ interface SSOContext {
103
+ user: WorkforceUser | null;
104
+ setUser: (user: WorkforceUser | null) => void;
105
+ isLoading: boolean;
21
106
  }
22
- declare function SSOProvider({ storageKey: storageKeyProp, userUrl, storage, disableListener, log, children }: SSOProviderProps): React.ReactNode2;
107
+ declare function SSOProvider({ storageKey: storageKeyProp, userUrl, storage, disableListener, log, children }: SSOProviderProps): React.ReactNode4;
108
+ declare function useSSOContext(): SSOContext;
109
+ /** Non-throwing variant; returns undefined when no SSOProvider is present. */
110
+ declare function useOptionalSSOContext(): SSOContext | undefined;
23
111
  declare function getUser(userUrl: string, storageKey?: string): Promise<WorkforceUser | undefined>;
24
112
  declare function logout(logoutUrl: string): Promise<{
25
113
  success: boolean;
@@ -59,4 +147,4 @@ declare function useTenantDirectory<TTenant extends TenantResponse = TenantRespo
59
147
  error: Error | null;
60
148
  refresh: () => Promise<void>;
61
149
  };
62
- export { useTenantDirectory, useTenant, logout, getUser, createTenantUrls, UseTenantDirectoryOptions, TenantProvider, SignedOut, SignedIn, SignInLoading, SSOProvider };
150
+ export { useTenantDirectory, useTenant, useSSOContext, useOptionalSSOContext, useOptionalCIAMContext, useCIAMProviders, useCIAMContext, logoutCustomer, logout, getUser, getCustomer, generateULID, createTenantUrls, UseTenantDirectoryOptions, UseCIAMProvidersResult, TenantProvider, SignedOut, SignedIn, SignInLoading, SSOProvider, CIAMProviderListProps, CIAMProviderList, CIAMProvider };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export*from"@enterprisestandard/core";import{silentLogger as A}from"@enterprisestandard/core";import{createContext as D,useCallback as l,useContext as H,useEffect as $,useState as w}from"react";import{jsx as S}from"react/jsx-runtime";var O=D(void 0),J=/^[a-zA-Z0-9._-]{1,1024}$/;function Q(n){if(!n.trim())throw Error("SSOProvider storageKey must be a non-empty string.");if(!J.test(n))throw Error("SSOProvider storageKey must be 1-1024 characters and contain only letters, numbers, dots, underscores, and hyphens.")}var W=(n)=>{if(n===void 0||n==="")return"es.sso.user";return Q(n),n};function e(n,i,t=A){if(typeof window>"u")return null;try{let T=(n==="local"?localStorage:sessionStorage).getItem(i);if(!T)return null;let p=JSON.parse(T);if(p.sso?.expires)p.sso.expires=new Date(p.sso.expires);return p}catch(c){return t.error("Error loading user from storage:",c),null}}async function _(n,i=A){try{let t=await fetch(n);if(t.status===401)return null;if(!t.ok)throw Error(`Failed to fetch user: ${t.status} ${t.statusText}`);let c=await t.json();if(c.sso?.expires&&typeof c.sso.expires==="string")c.sso.expires=new Date(c.sso.expires);return c}catch(t){return i.error("Error fetching user from URL:",t),null}}function Z({storageKey:n,userUrl:i,storage:t="memory",disableListener:c=!1,log:T=A,children:p}){let[h,r]=w(null),[N,o]=w(!!i),m=W(n),x=l(()=>{if(t==="memory")return null;return e(t,m,T)},[t,m,T]),d=l((f)=>{if(t==="memory"||typeof window>"u")return;try{let a=t==="local"?localStorage:sessionStorage;if(f===null)a.removeItem(m);else a.setItem(m,JSON.stringify(f))}catch(a){T.error("Error saving user to storage:",a)}},[t,m,T]),u=l((f)=>{r(f),d(f)},[d]),E=l(async()=>{if(!i)return;o(!0);try{let f=await _(i,T);r(f),d(f)}finally{o(!1)}},[i,d,T]);$(()=>{let f=x();if(f)r(f);if(i)E();else o(!1)},[x,i,E]),$(()=>{if(c||t==="memory")return;let f=(C)=>{if(C.key!==m)return;if(C.newValue===null)r(null);else try{let P=JSON.parse(C.newValue);if(P.sso?.expires)P.sso.expires=new Date(P.sso.expires);r(P)}catch(P){T.error("Error parsing user from storage event:",P)}},a=()=>{r(null)};return window.addEventListener("storage",f),window.addEventListener("es-sso-logout",a),()=>{window.removeEventListener("storage",f),window.removeEventListener("es-sso-logout",a)}},[c,t,m,T]);let V={user:h,setUser:u,isLoading:N};return S(O.Provider,{value:V,children:p})}function R(){let n=H(O);if(n===void 0)throw Error("useSSOContext must be used within a SSOProvider");return n}async function G(n,i){let t=W(i),c=e("local",t);if(c)return c;let T=e("session",t);if(T)return T;if(n){let p=await _(n);if(p)return p}return}async function Y(n){try{let i=await fetch(n,{headers:{Accept:"application/json"}});if(!i.ok)return{success:!1,error:`HTTP ${i.status}`};let t=await i.json();if(!t.success)return{success:!1,error:t.message||"Logout failed"};if(typeof window<"u")localStorage.removeItem("es.sso.user"),sessionStorage.removeItem("es.sso.user"),window.dispatchEvent(new CustomEvent("es-sso-logout"));return{success:!0}}catch(i){return{success:!1,error:i instanceof Error?i.message:"Network error"}}}import{jsx as v,Fragment as b}from"react/jsx-runtime";function X({complete:n=!1,children:i}){let{isLoading:t}=R();if(t&&!n)return v(b,{children:i});return null}import{jsx as j,Fragment as k}from"react/jsx-runtime";function L({children:n}){let{user:i}=R();if(i)return j(k,{children:n});return null}import{jsx as s,Fragment as K}from"react/jsx-runtime";function F({children:n}){let{user:i,isLoading:t}=R();if(i||t)return null;return s(K,{children:n})}import{buildTenantPath as y,DEFAULT_TENANT_API_NAMESPACE as U,DEFAULT_TENANT_UI_NAMESPACE as g,normalizeTenantRoutingStrategy as B}from"@enterprisestandard/core";import{createContext as nn,useContext as tn,useMemo as cn}from"react";import{jsx as un}from"react/jsx-runtime";var I=nn(null);function q(n,i){let t=B(i);if(t.type==="jwt"){let p=t.ui?.segments??[],h=t.api?.segments??["api"];return{ui:(r="/")=>z(p,r),api:(r="/")=>z(h,r)}}let c=t.ui??g,T=t.api??U;return{ui:(p="/")=>y(n,p,c),api:(p="/")=>y(n,p,T)}}function z(n,i="/"){let t=n.join("/"),c=i.trim().replace(/^\/+/,"");if(!t&&!c)return"/";if(!t)return`/${c}`;if(!c)return`/${t}`;return`/${t}/${c}`}function Tn({id:n,strategy:i,children:t}){let c=cn(()=>{let T=B(i);return{id:n,strategy:T,urls:q(n,T)}},[i,n]);return un(I.Provider,{value:c,children:t})}function pn(){let n=tn(I);if(!n)throw Error("useTenant() must be used within a TenantProvider");return n}import{useCallback as rn,useEffect as fn,useMemo as mn,useState as M}from"react";function on(n={}){let i=n.tenantManagerBaseUrl??"/api/tenants/mine",[t,c]=M(null),[T,p]=M(!0),[h,r]=M(null),N=mn(()=>{let u=new URL(i,"http://localhost");if(n.start!=null)u.searchParams.set("start",String(n.start));if(n.limit!=null)u.searchParams.set("limit",String(n.limit));if(n.order)u.searchParams.set("order",n.order);return`${u.pathname}${u.search}`},[n.limit,n.order,n.start,i]),o=rn(async()=>{p(!0),r(null);try{let u=await fetch(N);if(!u.ok){c(null),r(Error(`Tenant directory request failed with status ${u.status}`));return}let E=await u.json();c(E)}catch(u){c(null),r(u instanceof Error?u:Error("Failed to load tenant directory"))}finally{p(!1)}},[N]);fn(()=>{o()},[o]);let m=t?.tenants??{},x=t?.ids??[],d=x.map((u)=>m[u]).filter((u)=>!!u);return{directory:t,tenants:m,ids:x,items:d,isLoading:T,error:h,refresh:o}}export{on as useTenantDirectory,pn as useTenant,Y as logout,G as getUser,q as createTenantUrls,Tn as TenantProvider,F as SignedOut,L as SignedIn,X as SignInLoading,Z as SSOProvider};
1
+ export*from"@enterprisestandard/core";import{generateULID as Bi}from"@enterprisestandard/core";import{silentLogger as Y}from"@enterprisestandard/core";import{createContext as s,useCallback as J,useContext as b,useEffect as C,useState as L}from"react";import{jsx as Rn}from"react/jsx-runtime";var G=s(void 0),r=/^[a-zA-Z0-9._-]{1,1024}$/;function e(n){if(!n.trim())throw Error("CIAMProvider storageKey must be a non-empty string.");if(!r.test(n))throw Error("CIAMProvider storageKey must be 1-1024 characters and contain only letters, numbers, dots, underscores, and hyphens.")}var u=(n)=>{if(n===void 0||n==="")return"es.ciam.customer";return e(n),n};function Z(n,T,i=Y){if(typeof window>"u")return null;try{let P=(n==="local"?localStorage:sessionStorage).getItem(T);if(!P)return null;let R=JSON.parse(P);if(R.ciam?.expires)R.ciam.expires=new Date(R.ciam.expires);return R}catch(f){return i.error("Error loading customer from storage:",f),null}}async function F(n,T=Y){try{let i=await fetch(n);if(i.status===401)return null;if(!i.ok)throw Error(`Failed to fetch customer: ${i.status} ${i.statusText}`);let f=await i.json();if(f.ciam?.expires&&typeof f.ciam.expires==="string")f.ciam.expires=new Date(f.ciam.expires);return f}catch(i){return T.error("Error fetching customer from URL:",i),null}}function nn({storageKey:n,customerUrl:T,storage:i="memory",disableListener:f=!1,log:P=Y,children:R}){let[q,M]=L(null),[E,x]=L(!!T),A=u(n),N=J(()=>{if(i==="memory")return null;return Z(i,A,P)},[i,A,P]),W=J((c)=>{if(i==="memory"||typeof window>"u")return;try{let $=i==="local"?localStorage:sessionStorage;if(c===null)$.removeItem(A);else $.setItem(A,JSON.stringify(c))}catch($){P.error("Error saving customer to storage:",$)}},[i,A,P]),O=J((c)=>{M(c),W(c)},[W]),B=J(async()=>{if(!T)return;x(!0);try{let c=await F(T,P);M(c),W(c)}finally{x(!1)}},[T,W,P]);C(()=>{let c=N();if(c)M(c);if(T)B();else x(!1)},[N,T,B]),C(()=>{if(f||i==="memory")return;let c=(z)=>{if(z.key!==A)return;if(z.newValue===null)M(null);else try{let I=JSON.parse(z.newValue);if(I.ciam?.expires)I.ciam.expires=new Date(I.ciam.expires);M(I)}catch(I){P.error("Error parsing customer from storage event:",I)}},$=()=>{M(null)};return window.addEventListener("storage",c),window.addEventListener("es-ciam-logout",$),()=>{window.removeEventListener("storage",c),window.removeEventListener("es-ciam-logout",$)}},[f,i,A,P]);let w={customer:q,setCustomer:O,isLoading:E};return Rn(G.Provider,{value:w,children:R})}function Tn(){let n=b(G);if(n===void 0)throw Error("useCIAMContext must be used within a CIAMProvider");return n}function _(){return b(G)}async function fn(n,T){let i=u(T),f=Z("local",i);if(f)return f;let P=Z("session",i);if(P)return P;if(n){let R=await F(n);if(R)return R}return}async function Pn(n){try{let T=await fetch(n,{headers:{Accept:"application/json"}});if(!T.ok)return{success:!1,error:`HTTP ${T.status}`};let i=await T.json();if(!i.success)return{success:!1,error:i.message||"Logout failed"};if(typeof window<"u")localStorage.removeItem("es.ciam.customer"),sessionStorage.removeItem("es.ciam.customer"),window.dispatchEvent(new CustomEvent("es-ciam-logout"));return{success:!0}}catch(T){return{success:!1,error:T instanceof Error?T.message:"Network error"}}}import{silentLogger as y}from"@enterprisestandard/core";import{useCallback as An,useEffect as cn,useState as Q}from"react";import{jsx as p,jsxs as X}from"react/jsx-runtime";function S(n,T=y){let[i,f]=Q([]),[P,R]=Q(Boolean(n)),[q,M]=Q(null),E=An(()=>{if(!n)return;let x=!1;return R(!0),M(null),fetch(n,{headers:{Accept:"application/json"}}).then(async(A)=>{if(!A.ok)throw Error(`Failed to fetch CIAM providers: ${A.status} ${A.statusText}`);let N=await A.json();if(!x)f(Array.isArray(N.providers)?N.providers:[])}).catch((A)=>{let N=A instanceof Error?A:Error(String(A));if(T.error("Error fetching CIAM providers:",N),!x)M(N)}).finally(()=>{if(!x)R(!1)}),()=>{x=!0}},[n,T]);return cn(()=>{return E()},[E]),{providers:i,isLoading:P,error:q,refresh:E}}function Mn(n,T){return{display:"flex",alignItems:"center",gap:"0.5rem",width:"100%",padding:"0.625rem 0.875rem",border:"1px solid rgba(0,0,0,0.15)",borderRadius:"0.5rem",background:(T==="dark"?n.colors?.dark:n.colors?.light)??(T==="dark"?"#1f1f1f":"#ffffff"),color:T==="dark"?"#ffffff":"#111111",textDecoration:"none",font:"inherit",cursor:"pointer"}}function On({providersUrl:n,limit:T,theme:i="light",renderProvider:f,loadingFallback:P,emptyFallback:R,moreLabel:q="Show more",className:M,log:E=y}){let{providers:x,isLoading:A}=S(n,E),[N,W]=Q(!1);if(A)return P??null;if(x.length===0)return R??null;let O=!N&&typeof T==="number"&&T>0?x.slice(0,T):x,B=O.length<x.length;return X("div",{className:M,style:{display:"flex",flexDirection:"column",gap:"0.5rem"},"data-es-ciam-providers":"",children:[O.map((w)=>f?p("span",{children:f(w)},w.name):X("a",{href:w.loginUrl,style:Mn(w,i),"data-es-ciam-provider":w.name,children:[w.iconUrl?p("img",{src:w.iconUrl,alt:"",width:20,height:20,"aria-hidden":"true"}):null,X("span",{children:["Continue with ",w.displayName]})]},w.name)),B?p("button",{type:"button",onClick:()=>W(!0),"data-es-ciam-show-more":"",children:q}):null]})}import{silentLogger as h}from"@enterprisestandard/core";import{createContext as xn,useCallback as V,useContext as K,useEffect as t,useState as m}from"react";import{jsx as qn}from"react/jsx-runtime";var k=xn(void 0),Nn=/^[a-zA-Z0-9._-]{1,1024}$/;function $n(n){if(!n.trim())throw Error("SSOProvider storageKey must be a non-empty string.");if(!Nn.test(n))throw Error("SSOProvider storageKey must be 1-1024 characters and contain only letters, numbers, dots, underscores, and hyphens.")}var v=(n)=>{if(n===void 0||n==="")return"es.sso.user";return $n(n),n};function D(n,T,i=h){if(typeof window>"u")return null;try{let P=(n==="local"?localStorage:sessionStorage).getItem(T);if(!P)return null;let R=JSON.parse(P);if(R.sso?.expires)R.sso.expires=new Date(R.sso.expires);return R}catch(f){return i.error("Error loading user from storage:",f),null}}async function U(n,T=h){try{let i=await fetch(n);if(i.status===401)return null;if(!i.ok)throw Error(`Failed to fetch user: ${i.status} ${i.statusText}`);let f=await i.json();if(f.sso?.expires&&typeof f.sso.expires==="string")f.sso.expires=new Date(f.sso.expires);return f}catch(i){return T.error("Error fetching user from URL:",i),null}}function Wn({storageKey:n,userUrl:T,storage:i="memory",disableListener:f=!1,log:P=h,children:R}){let[q,M]=m(null),[E,x]=m(!!T),A=v(n),N=V(()=>{if(i==="memory")return null;return D(i,A,P)},[i,A,P]),W=V((c)=>{if(i==="memory"||typeof window>"u")return;try{let $=i==="local"?localStorage:sessionStorage;if(c===null)$.removeItem(A);else $.setItem(A,JSON.stringify(c))}catch($){P.error("Error saving user to storage:",$)}},[i,A,P]),O=V((c)=>{M(c),W(c)},[W]),B=V(async()=>{if(!T)return;x(!0);try{let c=await U(T,P);M(c),W(c)}finally{x(!1)}},[T,W,P]);t(()=>{let c=N();if(c)M(c);if(T)B();else x(!1)},[N,T,B]),t(()=>{if(f||i==="memory")return;let c=(z)=>{if(z.key!==A)return;if(z.newValue===null)M(null);else try{let I=JSON.parse(z.newValue);if(I.sso?.expires)I.sso.expires=new Date(I.sso.expires);M(I)}catch(I){P.error("Error parsing user from storage event:",I)}},$=()=>{M(null)};return window.addEventListener("storage",c),window.addEventListener("es-sso-logout",$),()=>{window.removeEventListener("storage",c),window.removeEventListener("es-sso-logout",$)}},[f,i,A,P]);let w={user:q,setUser:O,isLoading:E};return qn(k.Provider,{value:w,children:R})}function wn(){let n=K(k);if(n===void 0)throw Error("useSSOContext must be used within a SSOProvider");return n}function H(){return K(k)}async function In(n,T){let i=v(T),f=D("local",i);if(f)return f;let P=D("session",i);if(P)return P;if(n){let R=await U(n);if(R)return R}return}async function En(n){try{let T=await fetch(n,{headers:{Accept:"application/json"}});if(!T.ok)return{success:!1,error:`HTTP ${T.status}`};let i=await T.json();if(!i.success)return{success:!1,error:i.message||"Logout failed"};if(typeof window<"u")localStorage.removeItem("es.sso.user"),sessionStorage.removeItem("es.sso.user"),window.dispatchEvent(new CustomEvent("es-sso-logout"));return{success:!0}}catch(T){return{success:!1,error:T instanceof Error?T.message:"Network error"}}}import{jsx as _n,Fragment as zn}from"react/jsx-runtime";function Bn({complete:n=!1,audience:T="workforce",children:i}){let f=H(),P=_();if((T==="customer"?!!P?.isLoading:!!f?.isLoading)&&!n)return _n(zn,{children:i});return null}import{jsx as Qn,Fragment as Jn}from"react/jsx-runtime";function Hn({audience:n="workforce",children:T}){let i=H(),f=_();if(n==="customer"?!!f?.customer:!!i?.user)return Qn(Jn,{children:T});return null}import{jsx as Yn,Fragment as Zn}from"react/jsx-runtime";function Vn({audience:n="workforce",children:T}){let i=H(),f=_(),P=n==="customer"?!!f?.customer:!!i?.user,R=n==="customer"?!!f?.isLoading:!!i?.isLoading;if(P||R)return null;return Yn(Zn,{children:T})}import{buildTenantPath as d,DEFAULT_TENANT_API_NAMESPACE as Gn,DEFAULT_TENANT_UI_NAMESPACE as pn,normalizeTenantRoutingStrategy as a}from"@enterprisestandard/core";import{createContext as Xn,useContext as Dn,useMemo as hn}from"react";import{jsx as Cn}from"react/jsx-runtime";var g=Xn(null);function o(n,T){let i=a(T);if(i.type==="jwt"){let R=i.ui?.segments??[],q=i.api?.segments??["api"];return{ui:(M="/")=>l(R,M),api:(M="/")=>l(q,M)}}let f=i.ui??pn,P=i.api??Gn;return{ui:(R="/")=>d(n,R,f),api:(R="/")=>d(n,R,P)}}function l(n,T="/"){let i=n.join("/"),f=T.trim().replace(/^\/+/,"");if(!i&&!f)return"/";if(!i)return`/${f}`;if(!f)return`/${i}`;return`/${i}/${f}`}function kn({id:n,strategy:T,children:i}){let f=hn(()=>{let P=a(T);return{id:n,strategy:P,urls:o(n,P)}},[T,n]);return Cn(g.Provider,{value:f,children:i})}function jn(){let n=Dn(g);if(!n)throw Error("useTenant() must be used within a TenantProvider");return n}import{useCallback as Ln,useEffect as bn,useMemo as un,useState as j}from"react";function Fn(n={}){let T=n.tenantManagerBaseUrl??"/api/tenants/mine",[i,f]=j(null),[P,R]=j(!0),[q,M]=j(null),E=un(()=>{let O=new URL(T,"http://localhost");if(n.start!=null)O.searchParams.set("start",String(n.start));if(n.limit!=null)O.searchParams.set("limit",String(n.limit));if(n.order)O.searchParams.set("order",n.order);return`${O.pathname}${O.search}`},[n.limit,n.order,n.start,T]),x=Ln(async()=>{R(!0),M(null);try{let O=await fetch(E);if(!O.ok){f(null),M(Error(`Tenant directory request failed with status ${O.status}`));return}let B=await O.json();f(B)}catch(O){f(null),M(O instanceof Error?O:Error("Failed to load tenant directory"))}finally{R(!1)}},[E]);bn(()=>{x()},[x]);let A=i?.tenants??{},N=i?.ids??[],W=N.map((O)=>A[O]).filter((O)=>!!O);return{directory:i,tenants:A,ids:N,items:W,isLoading:P,error:q,refresh:x}}export{Fn as useTenantDirectory,jn as useTenant,wn as useSSOContext,H as useOptionalSSOContext,_ as useOptionalCIAMContext,S as useCIAMProviders,Tn as useCIAMContext,Pn as logoutCustomer,En as logout,In as getUser,fn as getCustomer,Bi as generateULID,o as createTenantUrls,kn as TenantProvider,Vn as SignedOut,Hn as SignedIn,Bn as SignInLoading,Wn as SSOProvider,On as CIAMProviderList,nn as CIAMProvider};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enterprisestandard/react",
3
- "version": "0.0.20-beta.20260522.3",
3
+ "version": "0.0.20-beta.20260615.1",
4
4
  "description": "Enterprise Standard React Components",
5
5
  "private": false,
6
6
  "author": "enterprisestandard",
@@ -22,7 +22,7 @@
22
22
  "./package.json": "./package.json"
23
23
  },
24
24
  "dependencies": {
25
- "@enterprisestandard/core": "0.0.20-beta.20260522.3"
25
+ "@enterprisestandard/core": "0.0.20-beta.20260615.1"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": "^18.0.0 || ^19.0.0",