@enterprisestandard/react 0.0.20-beta.20260701.1 → 0.0.20
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/README.md +2 -3
- package/dist/index.d.ts +1 -7
- package/dist/index.js +1 -1
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -22,7 +22,6 @@ Workforce (SSO):
|
|
|
22
22
|
|
|
23
23
|
- `SSOProvider`
|
|
24
24
|
- `useSSOContext` / `useOptionalSSOContext` (non-throwing)
|
|
25
|
-
- `getUser`
|
|
26
25
|
- `logout`
|
|
27
26
|
|
|
28
27
|
Customer (CIAM):
|
|
@@ -77,13 +76,13 @@ refresh fails.
|
|
|
77
76
|
`storage` defaults to `'memory'` (no tokens are ever stored). Opt into `'local'`/`'session'` to
|
|
78
77
|
survive reloads; the stored record is a non-secret display subset. On load, records are validated
|
|
79
78
|
against an identity shape and discarded if expired. A custom `storageKey` is honored by the provider,
|
|
80
|
-
`
|
|
79
|
+
`getCustomer`, and `logout`/`logoutCustomer`.
|
|
81
80
|
|
|
82
81
|
## Cross-origin
|
|
83
82
|
|
|
84
83
|
By default `fetch` does not send cookies cross-origin. When `userUrl`/`customerUrl` is on a different
|
|
85
84
|
origin, pass `fetchInit={{ credentials: 'include' }}` (keep the object stable/memoized). The same
|
|
86
|
-
option exists on `
|
|
85
|
+
option exists on `getCustomer`/`logout`/`logoutCustomer`.
|
|
87
86
|
|
|
88
87
|
## Docs
|
|
89
88
|
|
package/dist/index.d.ts
CHANGED
|
@@ -130,12 +130,6 @@ declare function SSOProvider({ storageKey: storageKeyProp, userUrl, storage, dis
|
|
|
130
130
|
declare function useSSOContext(): SSOContext;
|
|
131
131
|
/** Non-throwing variant; returns undefined when no SSOProvider is present. */
|
|
132
132
|
declare function useOptionalSSOContext(): SSOContext | undefined;
|
|
133
|
-
declare function getUser(userUrl: string, options?: {
|
|
134
|
-
storageKey?: string;
|
|
135
|
-
storage?: StorageType;
|
|
136
|
-
fetchInit?: RequestInit;
|
|
137
|
-
log?: Logger4;
|
|
138
|
-
}): Promise<WorkforceUser | undefined>;
|
|
139
133
|
declare function logout(logoutUrl: string, options?: {
|
|
140
134
|
navigate?: boolean;
|
|
141
135
|
storageKey?: string;
|
|
@@ -165,4 +159,4 @@ declare function TenantProvider({ id, strategy, children }: TenantProviderProps)
|
|
|
165
159
|
declare function useTenant(): TenantContextValue;
|
|
166
160
|
/** Non-throwing variant; returns undefined when no TenantProvider is present (parity with `useOptionalSSOContext`). */
|
|
167
161
|
declare function useOptionalTenant(): TenantContextValue | undefined;
|
|
168
|
-
export { useTenant, useSSOContext, useOptionalTenant, useOptionalSSOContext, useOptionalCIAMContext, useCIAMProviders, useCIAMContext, silentLogger, logoutCustomer, logout,
|
|
162
|
+
export { useTenant, useSSOContext, useOptionalTenant, useOptionalSSOContext, useOptionalCIAMContext, useCIAMProviders, useCIAMContext, silentLogger, logoutCustomer, logout, getCustomer, defaultLogger, createTenantUrls, WorkforceUser2 as WorkforceUser, UseCIAMProvidersResult, TenantUrls, TenantRoutingStrategy2 as TenantRoutingStrategy, TenantProviderProps, TenantProvider, TenantPathNamespace, TenantContextValue, SignedOut, SignedIn, SignInLoading, SSOProvider, Logger5 as Logger, IdTokenClaims, Customer2 as Customer, CIAMProviderType, CIAMProviderListProps, CIAMProviderList, CIAMProviderDescriptor3 as CIAMProviderDescriptor, CIAMProviderColors, CIAMProviderBranding, CIAMProvider, AuthenticatedUser };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defaultLogger as RM,silentLogger as FM}from"@enterprisestandard/core";import{silentLogger as $W}from"@enterprisestandard/core";import{createContext as OW,useContext as a,useMemo as BW}from"react";import{silentLogger as S}from"@enterprisestandard/core";import{useCallback as V,useEffect as g,useRef as i,useState as U}from"react";var QW=/^[a-zA-Z0-9._-]{1,1024}$/;function ZW(W,M){if(!W.trim())throw Error(`${M} storageKey must be a non-empty string.`);if(!QW.test(W))throw Error(`${M} storageKey must be 1-1024 characters and contain only letters, numbers, dots, underscores, and hyphens.`)}function G(W,M,C){if(M===void 0||M==="")return W;return ZW(M,C),M}function d(W,M,C,H=S){if(typeof window>"u")return null;try{let q=W==="local"?localStorage:sessionStorage,J=q.getItem(M);if(!J)return null;let Q=JSON.parse(J),Z=C.validate(Q);if(!Z)return q.removeItem(M),null;let $=C.revive(Z);if(C.isExpired($))return q.removeItem(M),null;return $}catch(q){return H.error("Error loading auth record from storage:",q),null}}async function l(W,M,C,H=S){try{let q=await fetch(W,C);if(q.status===401)return{kind:"unauthenticated"};if(!q.ok){let Z=Error(`Failed to fetch auth record: ${q.status} ${q.statusText}`);return H.error("Error fetching auth record from URL:",Z),{kind:"error",error:Z}}let J=await q.json(),Q=M.validate(J);if(!Q){let Z=Error("Auth record from server failed validation.");return H.error("Error validating auth record from URL:",Z),{kind:"error",error:Z}}return{kind:"ok",value:M.revive(Q)}}catch(q){let J=q instanceof Error?q:Error(String(q));return H.error("Error fetching auth record from URL:",J),{kind:"error",error:J}}}function b(W){let{url:M,storage:C,storageKey:H,disableListener:q,logoutEventName:J,codec:Q}=W,[Z,$]=U(null),[I,O]=U(!!M),[X,z]=U(null),N=i(W.fetchInit);N.current=W.fetchInit;let P=i(W.log);P.current=W.log;let f=V((B)=>{if(C==="memory"||typeof window>"u")return;try{let k=C==="local"?localStorage:sessionStorage;if(B===null)k.removeItem(H);else k.setItem(H,JSON.stringify(B))}catch(k){P.current.error("Error saving auth record to storage:",k)}},[C,H]),w=V((B)=>{$(B),f(B)},[f]),j=V(()=>{if(C==="memory")return null;return d(C,H,Q,P.current)},[C,H,Q]),Y=V(async()=>{if(!M)return;O(!0);try{let B=await l(M,Q,N.current,P.current);if(B.kind==="ok")$(B.value),z(null),f(B.value);else if(B.kind==="unauthenticated")$(null),z(null),f(null);else z(B.error)}finally{O(!1)}},[M,Q,f]);return g(()=>{let B=j();if(B)$(B);if(M)Y();else O(!1)},[j,M,Y]),g(()=>{if(q||C==="memory")return;let B=(_)=>{if(_.key!==H)return;if(_.newValue===null){$(null);return}try{let m=JSON.parse(_.newValue),c=Q.validate(m);if(!c)return;let n=Q.revive(c);if(Q.isExpired(n)){$(null);return}$(n)}catch(m){P.current.error("Error parsing auth record from storage event:",m)}},k=()=>{$(null),z(null)};return window.addEventListener("storage",B),window.addEventListener(J,k),()=>{window.removeEventListener("storage",B),window.removeEventListener(J,k)}},[q,C,H,J,Q]),{value:Z,setValue:w,isLoading:I,error:X}}async function R(W,M,C){let{storageKey:H,storage:q,fetchInit:J,log:Q=S}=C;if(q==="local"||q==="session"){let Z=d(q,H,M,Q);if(Z)return Z}if(W){let Z=await l(W,M,J,Q);if(Z.kind==="ok")return Z.value}return}async function F(W,M,C){try{let H=await fetch(W,{...C?.fetchInit,headers:{Accept:"application/json",...C?.fetchInit?.headers}});if(!H.ok)return{success:!1,error:`HTTP ${H.status}`};let q=await H.json();if(!q.success)return{success:!1,error:q.message||"Logout failed"};let J=typeof q.redirect==="string"?q.redirect:void 0;if(typeof window<"u"){let Q=G(M.defaultStorageKey,C?.storageKey,M.providerLabel);if(localStorage.removeItem(Q),sessionStorage.removeItem(Q),window.dispatchEvent(new CustomEvent(M.logoutEventName)),J&&C?.navigate!==!1)window.location.assign(J)}return{success:!0,redirect:J}}catch(H){return{success:!1,error:H instanceof Error?H.message:"Network error"}}}import{jsx as PW}from"react/jsx-runtime";var T="es.ciam.customer",s="es-ciam-logout",y="CIAMProvider",t={validate(W){if(!W||typeof W!=="object")return null;let M=W;if(typeof M.userName!=="string"||typeof M.name!=="string"||typeof M.email!=="string")return null;return W},revive(W){if(W.ciam?.expires)W.ciam.expires=new Date(W.ciam.expires);return W},isExpired(W){let M=W.ciam?.expires;if(!M)return!1;let C=M instanceof Date?M.getTime():new Date(M).getTime();return Number.isFinite(C)&&C<=Date.now()}},h=OW(void 0);function IW({storageKey:W,customerUrl:M,storage:C="memory",disableListener:H=!1,fetchInit:q,log:J=$W,children:Q}){let Z=G(T,W,y),{value:$,setValue:I,isLoading:O,error:X}=b({url:M,storage:C,storageKey:Z,disableListener:H,logoutEventName:s,codec:t,fetchInit:q,log:J}),z=BW(()=>({customer:$,setCustomer:I,isLoading:O,error:X}),[$,I,O,X]);return PW(h.Provider,{value:z,children:Q})}function XW(){let W=a(h);if(W===void 0)throw Error("useCIAMContext must be used within a CIAMProvider");return W}function A(){return a(h)}async function YW(W,M){return R(W,t,{storageKey:G(T,M?.storageKey,y),storage:M?.storage??"memory",fetchInit:M?.fetchInit,log:M?.log})}async function zW(W,M){return F(W,{defaultStorageKey:T,logoutEventName:s,providerLabel:y},M)}import{silentLogger as o}from"@enterprisestandard/core";import{useCallback as fW,useEffect as kW,useState as x}from"react";import{jsx as K,jsxs as L}from"react/jsx-runtime";function r(W,M=o){let[C,H]=x([]),[q,J]=x(Boolean(W)),[Q,Z]=x(null),$=fW(()=>{if(!W)return;let I=!1;return J(!0),Z(null),fetch(W,{headers:{Accept:"application/json"}}).then(async(O)=>{if(!O.ok)throw Error(`Failed to fetch CIAM providers: ${O.status} ${O.statusText}`);let X=await O.json();if(!I)H(Array.isArray(X.providers)?X.providers:[])}).catch((O)=>{let X=O instanceof Error?O:Error(String(O));if(M.error("Error fetching CIAM providers:",X),!I)H([]),Z(X)}).finally(()=>{if(!I)J(!1)}),()=>{I=!0}},[W,M]);return kW(()=>{return $()},[$]),{providers:C,isLoading:q,error:Q,refresh:$}}function GW(W,M){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:(M==="dark"?W.colors?.dark:W.colors?.light)??(M==="dark"?"#1f1f1f":"#ffffff"),color:M==="dark"?"#ffffff":"#111111",textDecoration:"none",font:"inherit",cursor:"pointer"}}function AW({providersUrl:W,limit:M,theme:C="light",renderProvider:H,loadingFallback:q,emptyFallback:J,errorFallback:Q,moreLabel:Z="Show more",className:$,log:I=o}){let{providers:O,isLoading:X,error:z,refresh:N}=r(W,I),[P,f]=x(!1);if(X)return q??null;if(z)return Q?Q(z,N):J??null;if(O.length===0)return J??null;let w=!P&&typeof M==="number"&&M>0?O.slice(0,M):O,j=w.length<O.length;return L("div",{className:$,style:{display:"flex",flexDirection:"column",gap:"0.5rem"},"data-es-ciam-providers":"",children:[w.map((Y)=>H?K("span",{children:H(Y)},Y.name):L("a",{href:Y.loginUrl,style:GW(Y,C),"data-es-ciam-provider":Y.name,children:[Y.iconUrl?K("img",{src:Y.iconUrl,alt:"",width:20,height:20,"aria-hidden":"true"}):null,L("span",{children:["Continue with ",Y.displayName]})]},Y.name)),j?K("button",{type:"button",onClick:()=>f(!0),"data-es-ciam-show-more":"",children:Z}):null]})}import{silentLogger as DW}from"@enterprisestandard/core";import{createContext as NW,useContext as e,useMemo as wW}from"react";import{jsx as FW}from"react/jsx-runtime";var E="es.sso.user",WW="es-sso-logout",p="SSOProvider",MW={validate(W){if(!W||typeof W!=="object")return null;let M=W;if(typeof M.userName!=="string"||typeof M.name!=="string"||typeof M.email!=="string")return null;return W},revive(W){if(W.sso?.expires)W.sso.expires=new Date(W.sso.expires);return W},isExpired(W){let M=W.sso?.expires;if(!M)return!1;let C=M instanceof Date?M.getTime():new Date(M).getTime();return Number.isFinite(C)&&C<=Date.now()}},v=NW(void 0);function jW({storageKey:W,userUrl:M,storage:C="memory",disableListener:H=!1,fetchInit:q,log:J=DW,children:Q}){let Z=G(E,W,p),{value:$,setValue:I,isLoading:O,error:X}=b({url:M,storage:C,storageKey:Z,disableListener:H,logoutEventName:WW,codec:MW,fetchInit:q,log:J}),z=wW(()=>({user:$,setUser:I,isLoading:O,error:X}),[$,I,O,X]);return FW(v.Provider,{value:z,children:Q})}function VW(){let W=e(v);if(W===void 0)throw Error("useSSOContext must be used within a SSOProvider");return W}function D(){return e(v)}async function bW(W,M){return R(W,MW,{storageKey:G(E,M?.storageKey,p),storage:M?.storage??"memory",fetchInit:M?.fetchInit,log:M?.log})}async function RW(W,M){return F(W,{defaultStorageKey:E,logoutEventName:WW,providerLabel:p},M)}import{jsx as mW,Fragment as _W}from"react/jsx-runtime";function xW({complete:W=!1,audience:M="workforce",children:C}){let H=D(),q=A();if((M==="customer"?!!q?.isLoading:!!H?.isLoading)&&!W)return mW(_W,{children:C});return null}import{jsx as TW,Fragment as SW}from"react/jsx-runtime";function UW({audience:W="workforce",children:M}){let C=D(),H=A();if(W==="customer"?!!H?.customer:!!C?.user)return TW(SW,{children:M});return null}import{jsx as KW,Fragment as hW}from"react/jsx-runtime";function yW({audience:W="workforce",children:M}){let C=D(),H=A(),q=W==="customer"?!!H?.customer:!!C?.user,J=W==="customer"?!!H?.isLoading:!!C?.isLoading;if(q||J)return null;return KW(hW,{children:M})}import{buildTenantPath as CW,DEFAULT_TENANT_API_NAMESPACE as LW,DEFAULT_TENANT_UI_NAMESPACE as EW,normalizeTenantRoutingStrategy as qW}from"@enterprisestandard/core";import{createContext as pW,useContext as HW,useMemo as vW}from"react";import{jsx as gW}from"react/jsx-runtime";var u=pW(null);function JW(W,M){let C=qW(M),H=C.ui??EW,q=C.api??LW;return{ui:(J="/")=>CW(W,J,H),api:(J="/")=>CW(W,J,q)}}function uW({id:W,strategy:M,children:C}){let H=vW(()=>{let q=qW(M);return{id:W,strategy:q,urls:JW(W,q)}},[M,W]);return gW(u.Provider,{value:H,children:C})}function cW(){let W=HW(u);if(!W)throw Error("useTenant() must be used within a TenantProvider");return W}function nW(){return HW(u)??void 0}export{cW as useTenant,VW as useSSOContext,nW as useOptionalTenant,D as useOptionalSSOContext,A as useOptionalCIAMContext,r as useCIAMProviders,XW as useCIAMContext,FM as silentLogger,zW as logoutCustomer,RW as logout,bW as getUser,YW as getCustomer,RM as defaultLogger,JW as createTenantUrls,uW as TenantProvider,yW as SignedOut,UW as SignedIn,xW as SignInLoading,jW as SSOProvider,AW as CIAMProviderList,IW as CIAMProvider};
|
|
1
|
+
import{defaultLogger as VM,silentLogger as _M}from"@enterprisestandard/core";import{silentLogger as ZW}from"@enterprisestandard/core";import{createContext as $W,useContext as d,useMemo as OW}from"react";import{silentLogger as S}from"@enterprisestandard/core";import{useCallback as R,useEffect as v,useRef as c,useState as U}from"react";var JW=/^[a-zA-Z0-9._-]{1,1024}$/;function QW(W,M){if(!W.trim())throw Error(`${M} storageKey must be a non-empty string.`);if(!JW.test(W))throw Error(`${M} storageKey must be 1-1024 characters and contain only letters, numbers, dots, underscores, and hyphens.`)}function D(W,M,C){if(M===void 0||M==="")return W;return QW(M,C),M}function n(W,M,C,H=S){if(typeof window>"u")return null;try{let q=W==="local"?localStorage:sessionStorage,J=q.getItem(M);if(!J)return null;let Q=JSON.parse(J),Z=C.validate(Q);if(!Z)return q.removeItem(M),null;let $=C.revive(Z);if(C.isExpired($))return q.removeItem(M),null;return $}catch(q){return H.error("Error loading auth record from storage:",q),null}}async function g(W,M,C,H=S){try{let q=await fetch(W,C);if(q.status===401)return{kind:"unauthenticated"};if(!q.ok){let Z=Error(`Failed to fetch auth record: ${q.status} ${q.statusText}`);return H.error("Error fetching auth record from URL:",Z),{kind:"error",error:Z}}let J=await q.json(),Q=M.validate(J);if(!Q){let Z=Error("Auth record from server failed validation.");return H.error("Error validating auth record from URL:",Z),{kind:"error",error:Z}}return{kind:"ok",value:M.revive(Q)}}catch(q){let J=q instanceof Error?q:Error(String(q));return H.error("Error fetching auth record from URL:",J),{kind:"error",error:J}}}function V(W){let{url:M,storage:C,storageKey:H,disableListener:q,logoutEventName:J,codec:Q}=W,[Z,$]=U(null),[I,O]=U(!!M),[X,P]=U(null),N=c(W.fetchInit);N.current=W.fetchInit;let z=c(W.log);z.current=W.log;let A=R((B)=>{if(C==="memory"||typeof window>"u")return;try{let f=C==="local"?localStorage:sessionStorage;if(B===null)f.removeItem(H);else f.setItem(H,JSON.stringify(B))}catch(f){z.current.error("Error saving auth record to storage:",f)}},[C,H]),w=R((B)=>{$(B),A(B)},[A]),j=R(()=>{if(C==="memory")return null;return n(C,H,Q,z.current)},[C,H,Q]),Y=R(async()=>{if(!M)return;O(!0);try{let B=await g(M,Q,N.current,z.current);if(B.kind==="ok")$(B.value),P(null),A(B.value);else if(B.kind==="unauthenticated")$(null),P(null),A(null);else P(B.error)}finally{O(!1)}},[M,Q,A]);return v(()=>{let B=j();if(B)$(B);if(M)Y();else O(!1)},[j,M,Y]),v(()=>{if(q||C==="memory")return;let B=(F)=>{if(F.key!==H)return;if(F.newValue===null){$(null);return}try{let x=JSON.parse(F.newValue),p=Q.validate(x);if(!p)return;let u=Q.revive(p);if(Q.isExpired(u)){$(null);return}$(u)}catch(x){z.current.error("Error parsing auth record from storage event:",x)}},f=()=>{$(null),P(null)};return window.addEventListener("storage",B),window.addEventListener(J,f),()=>{window.removeEventListener("storage",B),window.removeEventListener(J,f)}},[q,C,H,J,Q]),{value:Z,setValue:w,isLoading:I,error:X}}async function i(W,M,C){let{storageKey:H,storage:q,fetchInit:J,log:Q=S}=C;if(q==="local"||q==="session"){let Z=n(q,H,M,Q);if(Z)return Z}if(W){let Z=await g(W,M,J,Q);if(Z.kind==="ok")return Z.value}return}async function _(W,M,C){try{let H=await fetch(W,{...C?.fetchInit,headers:{Accept:"application/json",...C?.fetchInit?.headers}});if(!H.ok)return{success:!1,error:`HTTP ${H.status}`};let q=await H.json();if(!q.success)return{success:!1,error:q.message||"Logout failed"};let J=typeof q.redirect==="string"?q.redirect:void 0;if(typeof window<"u"){let Q=D(M.defaultStorageKey,C?.storageKey,M.providerLabel);if(localStorage.removeItem(Q),sessionStorage.removeItem(Q),window.dispatchEvent(new CustomEvent(M.logoutEventName)),J&&C?.navigate!==!1)window.location.assign(J)}return{success:!0,redirect:J}}catch(H){return{success:!1,error:H instanceof Error?H.message:"Network error"}}}import{jsx as PW}from"react/jsx-runtime";var m="es.ciam.customer",l="es-ciam-logout",T="CIAMProvider",s={validate(W){if(!W||typeof W!=="object")return null;let M=W;if(typeof M.userName!=="string"||typeof M.name!=="string"||typeof M.email!=="string")return null;return W},revive(W){if(W.ciam?.expires)W.ciam.expires=new Date(W.ciam.expires);return W},isExpired(W){let M=W.ciam?.expires;if(!M)return!1;let C=M instanceof Date?M.getTime():new Date(M).getTime();return Number.isFinite(C)&&C<=Date.now()}},y=$W(void 0);function BW({storageKey:W,customerUrl:M,storage:C="memory",disableListener:H=!1,fetchInit:q,log:J=ZW,children:Q}){let Z=D(m,W,T),{value:$,setValue:I,isLoading:O,error:X}=V({url:M,storage:C,storageKey:Z,disableListener:H,logoutEventName:l,codec:s,fetchInit:q,log:J}),P=OW(()=>({customer:$,setCustomer:I,isLoading:O,error:X}),[$,I,O,X]);return PW(y.Provider,{value:P,children:Q})}function IW(){let W=d(y);if(W===void 0)throw Error("useCIAMContext must be used within a CIAMProvider");return W}function G(){return d(y)}async function XW(W,M){return i(W,s,{storageKey:D(m,M?.storageKey,T),storage:M?.storage??"memory",fetchInit:M?.fetchInit,log:M?.log})}async function YW(W,M){return _(W,{defaultStorageKey:m,logoutEventName:l,providerLabel:T},M)}import{silentLogger as a}from"@enterprisestandard/core";import{useCallback as zW,useEffect as AW,useState as b}from"react";import{jsx as h,jsxs as K}from"react/jsx-runtime";function t(W,M=a){let[C,H]=b([]),[q,J]=b(Boolean(W)),[Q,Z]=b(null),$=zW(()=>{if(!W)return;let I=!1;return J(!0),Z(null),fetch(W,{headers:{Accept:"application/json"}}).then(async(O)=>{if(!O.ok)throw Error(`Failed to fetch CIAM providers: ${O.status} ${O.statusText}`);let X=await O.json();if(!I)H(Array.isArray(X.providers)?X.providers:[])}).catch((O)=>{let X=O instanceof Error?O:Error(String(O));if(M.error("Error fetching CIAM providers:",X),!I)H([]),Z(X)}).finally(()=>{if(!I)J(!1)}),()=>{I=!0}},[W,M]);return AW(()=>{return $()},[$]),{providers:C,isLoading:q,error:Q,refresh:$}}function fW(W,M){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:(M==="dark"?W.colors?.dark:W.colors?.light)??(M==="dark"?"#1f1f1f":"#ffffff"),color:M==="dark"?"#ffffff":"#111111",textDecoration:"none",font:"inherit",cursor:"pointer"}}function GW({providersUrl:W,limit:M,theme:C="light",renderProvider:H,loadingFallback:q,emptyFallback:J,errorFallback:Q,moreLabel:Z="Show more",className:$,log:I=a}){let{providers:O,isLoading:X,error:P,refresh:N}=t(W,I),[z,A]=b(!1);if(X)return q??null;if(P)return Q?Q(P,N):J??null;if(O.length===0)return J??null;let w=!z&&typeof M==="number"&&M>0?O.slice(0,M):O,j=w.length<O.length;return K("div",{className:$,style:{display:"flex",flexDirection:"column",gap:"0.5rem"},"data-es-ciam-providers":"",children:[w.map((Y)=>H?h("span",{children:H(Y)},Y.name):K("a",{href:Y.loginUrl,style:fW(Y,C),"data-es-ciam-provider":Y.name,children:[Y.iconUrl?h("img",{src:Y.iconUrl,alt:"",width:20,height:20,"aria-hidden":"true"}):null,K("span",{children:["Continue with ",Y.displayName]})]},Y.name)),j?h("button",{type:"button",onClick:()=>A(!0),"data-es-ciam-show-more":"",children:Z}):null]})}import{silentLogger as kW}from"@enterprisestandard/core";import{createContext as DW,useContext as o,useMemo as NW}from"react";import{jsx as _W}from"react/jsx-runtime";var r="es.sso.user",e="es-sso-logout",WW="SSOProvider",wW={validate(W){if(!W||typeof W!=="object")return null;let M=W;if(typeof M.userName!=="string"||typeof M.name!=="string"||typeof M.email!=="string")return null;return W},revive(W){if(W.sso?.expires)W.sso.expires=new Date(W.sso.expires);return W},isExpired(W){let M=W.sso?.expires;if(!M)return!1;let C=M instanceof Date?M.getTime():new Date(M).getTime();return Number.isFinite(C)&&C<=Date.now()}},L=DW(void 0);function jW({storageKey:W,userUrl:M,storage:C="memory",disableListener:H=!1,fetchInit:q,log:J=kW,children:Q}){let Z=D(r,W,WW),{value:$,setValue:I,isLoading:O,error:X}=V({url:M,storage:C,storageKey:Z,disableListener:H,logoutEventName:e,codec:wW,fetchInit:q,log:J}),P=NW(()=>({user:$,setUser:I,isLoading:O,error:X}),[$,I,O,X]);return _W(L.Provider,{value:P,children:Q})}function RW(){let W=o(L);if(W===void 0)throw Error("useSSOContext must be used within a SSOProvider");return W}function k(){return o(L)}async function VW(W,M){return _(W,{defaultStorageKey:r,logoutEventName:e,providerLabel:WW},M)}import{jsx as xW,Fragment as FW}from"react/jsx-runtime";function bW({complete:W=!1,audience:M="workforce",children:C}){let H=k(),q=G();if((M==="customer"?!!q?.isLoading:!!H?.isLoading)&&!W)return xW(FW,{children:C});return null}import{jsx as mW,Fragment as SW}from"react/jsx-runtime";function UW({audience:W="workforce",children:M}){let C=k(),H=G();if(W==="customer"?!!H?.customer:!!C?.user)return mW(SW,{children:M});return null}import{jsx as hW,Fragment as yW}from"react/jsx-runtime";function TW({audience:W="workforce",children:M}){let C=k(),H=G(),q=W==="customer"?!!H?.customer:!!C?.user,J=W==="customer"?!!H?.isLoading:!!C?.isLoading;if(q||J)return null;return hW(yW,{children:M})}import{buildTenantPath as MW,DEFAULT_TENANT_API_NAMESPACE as KW,DEFAULT_TENANT_UI_NAMESPACE as LW,normalizeTenantRoutingStrategy as CW}from"@enterprisestandard/core";import{createContext as EW,useContext as qW,useMemo as pW}from"react";import{jsx as nW}from"react/jsx-runtime";var E=EW(null);function HW(W,M){let C=CW(M),H=C.ui??LW,q=C.api??KW;return{ui:(J="/")=>MW(W,J,H),api:(J="/")=>MW(W,J,q)}}function uW({id:W,strategy:M,children:C}){let H=pW(()=>{let q=CW(M);return{id:W,strategy:q,urls:HW(W,q)}},[M,W]);return nW(E.Provider,{value:H,children:C})}function vW(){let W=qW(E);if(!W)throw Error("useTenant() must be used within a TenantProvider");return W}function cW(){return qW(E)??void 0}export{vW as useTenant,RW as useSSOContext,cW as useOptionalTenant,k as useOptionalSSOContext,G as useOptionalCIAMContext,t as useCIAMProviders,IW as useCIAMContext,_M as silentLogger,YW as logoutCustomer,VW as logout,XW as getCustomer,VM as defaultLogger,HW as createTenantUrls,uW as TenantProvider,TW as SignedOut,UW as SignedIn,bW as SignInLoading,jW as SSOProvider,GW as CIAMProviderList,BW as CIAMProvider};
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enterprisestandard/react",
|
|
3
|
-
"version": "0.0.20
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "Enterprise Standard React Components",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "enterprisestandard",
|
|
7
7
|
"license": "proprietary",
|
|
8
8
|
"type": "module",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=20.6"
|
|
11
|
+
},
|
|
9
12
|
"files": [
|
|
10
13
|
"dist"
|
|
11
14
|
],
|
|
@@ -21,10 +24,13 @@
|
|
|
21
24
|
"./package.json": "./package.json"
|
|
22
25
|
},
|
|
23
26
|
"dependencies": {
|
|
24
|
-
"@enterprisestandard/core": "0.0.20
|
|
27
|
+
"@enterprisestandard/core": "^0.0.20"
|
|
25
28
|
},
|
|
26
29
|
"peerDependencies": {
|
|
27
30
|
"react": "^18.0.0 || ^19.0.0",
|
|
28
31
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/react": "^19.2.17"
|
|
29
35
|
}
|
|
30
36
|
}
|