@ionite/react 0.0.24-beta.20260922.9 → 0.0.24-beta.20260927.12
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 +40 -4
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -90,6 +90,42 @@ type CIAMProviderListProps = {
|
|
|
90
90
|
* `limit` (first N + "show more") that preserves order by default.
|
|
91
91
|
*/
|
|
92
92
|
declare function CIAMProviderList({ providersUrl, limit, theme, renderProvider, loadingFallback, emptyFallback, errorFallback, moreLabel, className, log }: CIAMProviderListProps): React.ReactNode3;
|
|
93
|
+
import { DisplayUser } from "@ionite/core";
|
|
94
|
+
import { ReactNode as ReactNode4 } from "react";
|
|
95
|
+
type SessionsStatus = "loading" | "cookies" | "verified" | "unauthenticated" | "unavailable";
|
|
96
|
+
type SessionsVerify = "auto" | "always" | "never";
|
|
97
|
+
type SessionsTenant = {
|
|
98
|
+
tenantId: string;
|
|
99
|
+
authType?: "sso" | "ciam";
|
|
100
|
+
source?: "session" | "owner" | "discovered";
|
|
101
|
+
user: DisplayUser;
|
|
102
|
+
tenantName?: string;
|
|
103
|
+
expiresAt?: string;
|
|
104
|
+
};
|
|
105
|
+
type SessionsContextValue = {
|
|
106
|
+
status: SessionsStatus;
|
|
107
|
+
tenants: SessionsTenant[];
|
|
108
|
+
refresh: () => Promise<void>;
|
|
109
|
+
};
|
|
110
|
+
type SessionsProviderProps = {
|
|
111
|
+
/** App endpoint that returns `{ tenants }` from `getSessionEntries`. */
|
|
112
|
+
sessionsUrl: string;
|
|
113
|
+
/**
|
|
114
|
+
* `auto` fetches only when no display cookies exist, or the current tenant has none.
|
|
115
|
+
* `always` verifies after painting cookies. `never` stays on cookies.
|
|
116
|
+
* @default 'auto'
|
|
117
|
+
*/
|
|
118
|
+
verify?: SessionsVerify;
|
|
119
|
+
/** Defaults to `TenantProvider`'s id when that provider is an ancestor. */
|
|
120
|
+
currentTenantId?: string;
|
|
121
|
+
/** Keep referentially stable (module constant or `useMemo`); a new object per render refetches. */
|
|
122
|
+
fetchInit?: RequestInit;
|
|
123
|
+
children: ReactNode4;
|
|
124
|
+
};
|
|
125
|
+
declare function SessionsProvider({ sessionsUrl, verify, currentTenantId, fetchInit, children }: SessionsProviderProps): React.ReactNode4;
|
|
126
|
+
declare function useTenants(): SessionsContextValue;
|
|
127
|
+
/** Alias of {@link useTenants}. */
|
|
128
|
+
declare function useSessions(): SessionsContextValue;
|
|
93
129
|
import { PropsWithChildren } from "react";
|
|
94
130
|
type Audience = "workforce" | "customer";
|
|
95
131
|
declare function SignInLoading({ complete, audience, children }: {
|
|
@@ -107,7 +143,7 @@ declare function SignedOut({ audience, children }: {
|
|
|
107
143
|
audience?: Audience3;
|
|
108
144
|
} & PropsWithChildren3): React.ReactNode;
|
|
109
145
|
import { Logger as Logger4, WorkforceUser } from "@ionite/core";
|
|
110
|
-
import { ReactNode as
|
|
146
|
+
import { ReactNode as ReactNode5 } from "react";
|
|
111
147
|
interface SSOProviderProps {
|
|
112
148
|
userUrl: string;
|
|
113
149
|
/** Optional storage key. When provided, this key is used for localStorage/sessionStorage; otherwise `'ion.sso.user'` is used. */
|
|
@@ -117,7 +153,7 @@ interface SSOProviderProps {
|
|
|
117
153
|
/** Extra fetch options for `userUrl` (e.g. `{ credentials: 'include' }` when it is cross-origin). Keep it stable/memoized. */
|
|
118
154
|
fetchInit?: RequestInit;
|
|
119
155
|
log?: Logger4;
|
|
120
|
-
children:
|
|
156
|
+
children: ReactNode5;
|
|
121
157
|
}
|
|
122
158
|
interface SSOContext {
|
|
123
159
|
user: WorkforceUser | null;
|
|
@@ -126,7 +162,7 @@ interface SSOContext {
|
|
|
126
162
|
/** Set when the last user fetch failed for a non-auth reason (network/5xx). Null on success or 401 (signed out). */
|
|
127
163
|
error: Error | null;
|
|
128
164
|
}
|
|
129
|
-
declare function SSOProvider({ storageKey: storageKeyProp, userUrl, storage, disableListener, fetchInit, log, children }: SSOProviderProps): React.
|
|
165
|
+
declare function SSOProvider({ storageKey: storageKeyProp, userUrl, storage, disableListener, fetchInit, log, children }: SSOProviderProps): React.ReactNode5;
|
|
130
166
|
declare function useSSOContext(): SSOContext;
|
|
131
167
|
/** Non-throwing variant; returns undefined when no SSOProvider is present. */
|
|
132
168
|
declare function useOptionalSSOContext(): SSOContext | undefined;
|
|
@@ -159,4 +195,4 @@ declare function TenantProvider({ id, strategy, children }: TenantProviderProps)
|
|
|
159
195
|
declare function useTenant(): TenantContextValue;
|
|
160
196
|
/** Non-throwing variant; returns undefined when no TenantProvider is present (parity with `useOptionalSSOContext`). */
|
|
161
197
|
declare function useOptionalTenant(): TenantContextValue | undefined;
|
|
162
|
-
export { AuthenticatedUser, CIAMProvider, CIAMProviderBranding, CIAMProviderColors, CIAMProviderDescriptor3 as CIAMProviderDescriptor, CIAMProviderList, CIAMProviderListProps, CIAMProviderType, Customer2 as Customer, IdTokenClaims, Logger5 as Logger, SSOProvider, SignInLoading, SignedIn, SignedOut, TenantContextValue, TenantPathNamespace, TenantProvider, TenantProviderProps, TenantRoutingStrategy2 as TenantRoutingStrategy, TenantUrls, UseCIAMProvidersResult, WorkforceUser2 as WorkforceUser, createTenantUrls, defaultLogger, getCustomer, logout, logoutCustomer, silentLogger, useCIAMContext, useCIAMProviders, useOptionalCIAMContext, useOptionalSSOContext, useOptionalTenant, useSSOContext, useTenant };
|
|
198
|
+
export { AuthenticatedUser, CIAMProvider, CIAMProviderBranding, CIAMProviderColors, CIAMProviderDescriptor3 as CIAMProviderDescriptor, CIAMProviderList, CIAMProviderListProps, CIAMProviderType, Customer2 as Customer, IdTokenClaims, Logger5 as Logger, SSOProvider, SessionsContextValue, SessionsProvider, SessionsProviderProps, SessionsStatus, SessionsTenant, SessionsVerify, SignInLoading, SignedIn, SignedOut, TenantContextValue, TenantPathNamespace, TenantProvider, TenantProviderProps, TenantRoutingStrategy2 as TenantRoutingStrategy, TenantUrls, UseCIAMProvidersResult, WorkforceUser2 as WorkforceUser, createTenantUrls, defaultLogger, getCustomer, logout, logoutCustomer, silentLogger, useCIAMContext, useCIAMProviders, useOptionalCIAMContext, useOptionalSSOContext, useOptionalTenant, useSSOContext, useSessions, useTenant, useTenants };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defaultLogger as Pr,silentLogger as Er}from"@ionite/core";import{silentLogger as ue}from"@ionite/core";import{createContext as ce,useContext as X,useMemo as le}from"react";import{silentLogger as b}from"@ionite/core";import{useCallback as I,useEffect as W,useRef as q,useState as k}from"react";var ie=/^[a-zA-Z0-9._-]{1,1024}$/;function ae(e,r){if(!e.trim())throw Error(`${r} storageKey must be a non-empty string.`);if(!ie.test(e))throw Error(`${r} storageKey must be 1-1024 characters and contain only letters, numbers, dots, underscores, and hyphens.`)}function x(e,r,t){if(r===void 0||r==="")return e;return ae(r,t),r}function z(e,r,t,n=b){if(typeof window>"u")return null;try{let o=e==="local"?localStorage:sessionStorage,s=o.getItem(r);if(!s)return null;let i=JSON.parse(s),a=t.validate(i);if(!a)return o.removeItem(r),null;let u=t.revive(a);if(t.isExpired(u))return o.removeItem(r),null;return u}catch(o){return n.error("Error loading auth record from storage:",o),null}}async function B(e,r,t,n=b){try{let o=await fetch(e,t);if(o.status===401)return{kind:"unauthenticated"};if(!o.ok){let a=Error(`Failed to fetch auth record: ${o.status} ${o.statusText}`);return n.error("Error fetching auth record from URL:",a),{kind:"error",error:a}}let s=await o.json(),i=r.validate(s);if(!i){let a=Error("Auth record from server failed validation.");return n.error("Error validating auth record from URL:",a),{kind:"error",error:a}}return{kind:"ok",value:r.revive(i)}}catch(o){let s=o instanceof Error?o:Error(String(o));return n.error("Error fetching auth record from URL:",s),{kind:"error",error:s}}}function R(e){let{url:r,storage:t,storageKey:n,disableListener:o,logoutEventName:s,codec:i}=e,[a,u]=k(null),[d,c]=k(!!r),[g,p]=k(null),T=q(e.fetchInit);T.current=e.fetchInit;let m=q(e.log);m.current=e.log;let v=I((l)=>{if(t==="memory"||typeof window>"u")return;try{let C=t==="local"?localStorage:sessionStorage;if(l===null)C.removeItem(n);else C.setItem(n,JSON.stringify(l))}catch(C){m.current.error("Error saving auth record to storage:",C)}},[t,n]),S=I((l)=>{u(l),v(l)},[v]),A=I(()=>{if(t==="memory")return null;return z(t,n,i,m.current)},[t,n,i]),f=I(async()=>{if(!r)return;c(!0);try{let l=await B(r,i,T.current,m.current);if(l.kind==="ok")u(l.value),p(null),v(l.value);else if(l.kind==="unauthenticated")u(null),p(null),v(null);else p(l.error)}finally{c(!1)}},[r,i,v]);return W(()=>{let l=A();if(l)u(l);if(r)f();else c(!1)},[A,r,f]),W(()=>{if(o||t==="memory")return;let l=(L)=>{if(L.key!==n)return;if(L.newValue===null){u(null);return}try{let w=JSON.parse(L.newValue),_=i.validate(w);if(!_)return;let F=i.revive(_);if(i.isExpired(F)){u(null);return}u(F)}catch(w){m.current.error("Error parsing auth record from storage event:",w)}},C=()=>{u(null),p(null)};return window.addEventListener("storage",l),window.addEventListener(s,C),()=>{window.removeEventListener("storage",l),window.removeEventListener(s,C)}},[o,t,n,s,i]),{value:a,setValue:S,isLoading:d,error:g}}async function G(e,r,t){let{storageKey:n,storage:o,fetchInit:s,log:i=b}=t;if(o==="local"||o==="session"){let a=z(o,n,r,i);if(a)return a}if(e){let a=await B(e,r,s,i);if(a.kind==="ok")return a.value}return}async function P(e,r,t){try{let n=await fetch(e,{...t?.fetchInit,headers:{Accept:"application/json",...t?.fetchInit?.headers}});if(!n.ok)return{success:!1,error:`HTTP ${n.status}`};let o=await n.json();if(!o.success)return{success:!1,error:o.message||"Logout failed"};let s=typeof o.redirect==="string"?o.redirect:void 0;if(typeof window<"u"){let i=x(r.defaultStorageKey,t?.storageKey,r.providerLabel);if(localStorage.removeItem(i),sessionStorage.removeItem(i),window.dispatchEvent(new CustomEvent(r.logoutEventName)),s&&t?.navigate!==!1)window.location.assign(s)}return{success:!0,redirect:s}}catch(n){return{success:!1,error:n instanceof Error?n.message:"Network error"}}}import{jsx as me}from"react/jsx-runtime";var O="ion.ciam.customer",J="ion-ciam-logout",M="CIAMProvider",Y={validate(e){if(!e||typeof e!=="object")return null;let r=e;if(typeof r.userName!=="string"||typeof r.name!=="string"||typeof r.email!=="string")return null;return e},revive(e){if(e.ciam?.expires)e.ciam.expires=new Date(e.ciam.expires);return e},isExpired(e){let r=e.ciam?.expires;if(!r)return!1;let t=r instanceof Date?r.getTime():new Date(r).getTime();return Number.isFinite(t)&&t<=Date.now()}},N=ce(void 0);function de({storageKey:e,customerUrl:r,storage:t="memory",disableListener:n=!1,fetchInit:o,log:s=ue,children:i}){let a=x(O,e,M),{value:u,setValue:d,isLoading:c,error:g}=R({url:r,storage:t,storageKey:a,disableListener:n,logoutEventName:J,codec:Y,fetchInit:o,log:s}),p=le(()=>({customer:u,setCustomer:d,isLoading:c,error:g}),[u,d,c,g]);return me(N.Provider,{value:p,children:i})}function ge(){let e=X(N);if(e===void 0)throw Error("useCIAMContext must be used within a CIAMProvider");return e}function y(){return X(N)}async function fe(e,r){return G(e,Y,{storageKey:x(O,r?.storageKey,M),storage:r?.storage??"memory",fetchInit:r?.fetchInit,log:r?.log})}async function pe(e,r){return P(e,{defaultStorageKey:O,logoutEventName:J,providerLabel:M},r)}import{silentLogger as H}from"@ionite/core";import{useCallback as ve,useEffect as Ce,useState as E}from"react";import{jsx as U,jsxs as D}from"react/jsx-runtime";function Z(e,r=H){let[t,n]=E([]),[o,s]=E(Boolean(e)),[i,a]=E(null),u=ve(()=>{if(!e)return;let d=!1;return s(!0),a(null),fetch(e,{headers:{Accept:"application/json"}}).then(async(c)=>{if(!c.ok)throw Error(`Failed to fetch CIAM providers: ${c.status} ${c.statusText}`);let g=await c.json();if(!d)n(Array.isArray(g.providers)?g.providers:[])}).catch((c)=>{let g=c instanceof Error?c:Error(String(c));if(r.error("Error fetching CIAM providers:",g),!d)n([]),a(g)}).finally(()=>{if(!d)s(!1)}),()=>{d=!0}},[e,r]);return Ce(()=>u(),[u]),{providers:t,isLoading:o,error:i,refresh:u}}function ye(e,r){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:(r==="dark"?e.colors?.dark:e.colors?.light)??(r==="dark"?"#1f1f1f":"#ffffff"),color:r==="dark"?"#ffffff":"#111111",textDecoration:"none",font:"inherit",cursor:"pointer"}}function he({providersUrl:e,limit:r,theme:t="light",renderProvider:n,loadingFallback:o,emptyFallback:s,errorFallback:i,moreLabel:a="Show more",className:u,log:d=H}){let{providers:c,isLoading:g,error:p,refresh:T}=Z(e,d),[m,v]=E(!1);if(g)return o??null;if(p)return i?i(p,T):s??null;if(c.length===0)return s??null;let S=!m&&typeof r==="number"&&r>0?c.slice(0,r):c,A=S.length<c.length;return D("div",{className:u,style:{display:"flex",flexDirection:"column",gap:"0.5rem"},"data-ion-ciam-providers":"",children:[S.map((f)=>n?U("span",{children:n(f)},f.name):D("a",{href:f.loginUrl,style:ye(f,t),"data-ion-ciam-provider":f.name,children:[f.iconUrl?U("img",{src:f.iconUrl,alt:"",width:20,height:20,"aria-hidden":"true"}):null,D("span",{children:["Continue with ",f.displayName]})]},f.name)),A?U("button",{type:"button",onClick:()=>v(!0),"data-ion-ciam-show-more":"",children:a}):null]})}import{silentLogger as xe}from"@ionite/core";import{createContext as Te,useContext as j,useMemo as Se}from"react";import{jsx as Ee}from"react/jsx-runtime";var Q="ion.sso.user",ee="ion-sso-logout",re="SSOProvider",Ae={validate(e){if(!e||typeof e!=="object")return null;let r=e;if(typeof r.userName!=="string"||typeof r.name!=="string"||typeof r.email!=="string")return null;return e},revive(e){if(e.sso?.expires)e.sso.expires=new Date(e.sso.expires);return e},isExpired(e){let r=e.sso?.expires;if(!r)return!1;let t=r instanceof Date?r.getTime():new Date(r).getTime();return Number.isFinite(t)&&t<=Date.now()}},K=Te(void 0);function Ie({storageKey:e,userUrl:r,storage:t="memory",disableListener:n=!1,fetchInit:o,log:s=xe,children:i}){let a=x(Q,e,re),{value:u,setValue:d,isLoading:c,error:g}=R({url:r,storage:t,storageKey:a,disableListener:n,logoutEventName:ee,codec:Ae,fetchInit:o,log:s}),p=Se(()=>({user:u,setUser:d,isLoading:c,error:g}),[u,d,c,g]);return Ee(K.Provider,{value:p,children:i})}function Re(){let e=j(K);if(e===void 0)throw Error("useSSOContext must be used within a SSOProvider");return e}function h(){return j(K)}async function Pe(e,r){return P(e,{defaultStorageKey:Q,logoutEventName:ee,providerLabel:re},r)}import{jsx as ke,Fragment as we}from"react/jsx-runtime";function Le({complete:e=!1,audience:r="workforce",children:t}){let n=h(),o=y();if((r==="customer"?!!o?.isLoading:!!n?.isLoading)&&!e)return ke(we,{children:t});return null}import{jsx as Me,Fragment as Oe}from"react/jsx-runtime";function be({audience:e="workforce",children:r}){let t=h(),n=y();if(e==="customer"?!!n?.customer:!!t?.user)return Me(Oe,{children:r});return null}import{jsx as De,Fragment as Ue}from"react/jsx-runtime";function Ne({audience:e="workforce",children:r}){let t=h(),n=y(),o=e==="customer"?!!n?.customer:!!t?.user,s=e==="customer"?!!n?.isLoading:!!t?.isLoading;if(o||s)return null;return De(Ue,{children:r})}import{buildTenantPath as te,DEFAULT_TENANT_API_NAMESPACE as Ke,DEFAULT_TENANT_UI_NAMESPACE as Ve,normalizeTenantRoutingStrategy as oe}from"@ionite/core";import{createContext as _e,useContext as ne,useMemo as Fe}from"react";import{jsx as ze}from"react/jsx-runtime";var V=_e(null);function se(e,r){let t=oe(r),n=t.ui??Ve,o=t.api??Ke;return{ui:(s="/")=>te(e,s,n),api:(s="/")=>te(e,s,o)}}function We({id:e,strategy:r,children:t}){let n=Fe(()=>{let o=oe(r);return{id:e,strategy:o,urls:se(e,o)}},[r,e]);return ze(V.Provider,{value:n,children:t})}function qe(){let e=ne(V);if(!e)throw Error("useTenant() must be used within a TenantProvider");return e}function $e(){return ne(V)??void 0}export{de as CIAMProvider,he as CIAMProviderList,Ie as SSOProvider,Le as SignInLoading,be as SignedIn,Ne as SignedOut,We as TenantProvider,se as createTenantUrls,Pr as defaultLogger,fe as getCustomer,Pe as logout,pe as logoutCustomer,Er as silentLogger,ge as useCIAMContext,Z as useCIAMProviders,y as useOptionalCIAMContext,h as useOptionalSSOContext,$e as useOptionalTenant,Re as useSSOContext,qe as useTenant};
|
|
1
|
+
import{defaultLogger as Ht,silentLogger as Xt}from"@ionite/core";import{silentLogger as me}from"@ionite/core";import{createContext as ve,useContext as X,useMemo as ye}from"react";import{JSON_MEDIA_TYPE as B,readJsonResponse as z,silentLogger as b}from"@ionite/core";import{useCallback as P,useEffect as q,useRef as J,useState as k}from"react";var ge=/^[a-zA-Z0-9._-]{1,1024}$/;function pe(e,t){if(!e.trim())throw Error(`${t} storageKey must be a non-empty string.`);if(!ge.test(e))throw Error(`${t} storageKey must be 1-1024 characters and contain only letters, numbers, dots, underscores, and hyphens.`)}function A(e,t,r){if(t===void 0||t==="")return e;return pe(t,r),t}function G(e,t,r,o=b){if(typeof window>"u")return null;try{let n=e==="local"?localStorage:sessionStorage,s=n.getItem(t);if(!s)return null;let a=JSON.parse(s),c=r.validate(a);if(!c)return n.removeItem(t),null;let i=r.revive(c);if(r.isExpired(i))return n.removeItem(t),null;return i}catch(n){return o.error("Error loading auth record from storage:",n),null}}async function Y(e,t,r,o=b){try{let n=new Headers(r?.headers);if(!n.has("Accept"))n.set("Accept",B);let s=await fetch(e,{...r,headers:n});if(s.status===401)return{kind:"unauthenticated"};if(!s.ok){let i=Error(`Failed to fetch auth record: ${s.status} ${s.statusText}`);return o.error("Error fetching auth record from URL:",i),{kind:"error",error:i}}let a=await z(s,{log:o,operation:"react.auth_resource.fetch"}),c=t.validate(a);if(!c){let i=Error("Auth record from server failed validation.");return o.error("Error validating auth record from URL:",i),{kind:"error",error:i}}return{kind:"ok",value:t.revive(c)}}catch(n){let s=n instanceof Error?n:Error(String(n));return o.error("Error fetching auth record from URL:",s),{kind:"error",error:s}}}function R(e){let{url:t,storage:r,storageKey:o,disableListener:n,logoutEventName:s,codec:a}=e,[c,i]=k(null),[f,u]=k(!!t),[d,m]=k(null),x=J(e.fetchInit);x.current=e.fetchInit;let y=J(e.log);y.current=e.log;let p=P((l)=>{if(r==="memory"||typeof window>"u")return;try{let v=r==="local"?localStorage:sessionStorage;if(l===null)v.removeItem(o);else v.setItem(o,JSON.stringify(l))}catch(v){y.current.error("Error saving auth record to storage:",v)}},[r,o]),T=P((l)=>{i(l),p(l)},[p]),h=P(()=>{if(r==="memory")return null;return G(r,o,a,y.current)},[r,o,a]),g=P(async()=>{if(!t)return;u(!0);try{let l=await Y(t,a,x.current,y.current);if(l.kind==="ok")i(l.value),m(null),p(l.value);else if(l.kind==="unauthenticated")i(null),m(null),p(null);else m(l.error)}finally{u(!1)}},[t,a,p]);return q(()=>{let l=h();if(l)i(l);if(t)g();else u(!1)},[h,t,g]),q(()=>{if(n||r==="memory")return;let l=(I)=>{if(I.key!==o)return;if(I.newValue===null){i(null);return}try{let L=JSON.parse(I.newValue),F=a.validate(L);if(!F)return;let W=a.revive(F);if(a.isExpired(W)){i(null);return}i(W)}catch(L){y.current.error("Error parsing auth record from storage event:",L)}},v=()=>{i(null),m(null)};return window.addEventListener("storage",l),window.addEventListener(s,v),()=>{window.removeEventListener("storage",l),window.removeEventListener(s,v)}},[n,r,o,s,a]),{value:c,setValue:T,isLoading:f,error:d}}async function H(e,t,r){let{storageKey:o,storage:n,fetchInit:s,log:a=b}=r;if(n==="local"||n==="session"){let c=G(n,o,t,a);if(c)return c}if(e){let c=await Y(e,t,s,a);if(c.kind==="ok")return c.value}return}async function w(e,t,r){try{let o=new Headers(r?.fetchInit?.headers);if(!o.has("Accept"))o.set("Accept",B);let n=await fetch(e,{...r?.fetchInit,headers:o});if(!n.ok)return{success:!1,error:`HTTP ${n.status}`};let s=await z(n);if(!s.success)return{success:!1,error:s.message||"Logout failed"};let a=typeof s.redirect==="string"?s.redirect:void 0;if(typeof window<"u"){let c=A(t.defaultStorageKey,r?.storageKey,t.providerLabel);if(localStorage.removeItem(c),sessionStorage.removeItem(c),window.dispatchEvent(new CustomEvent(t.logoutEventName)),a&&r?.navigate!==!1)window.location.assign(a)}return{success:!0,redirect:a}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Network error"}}}import{jsx as Te}from"react/jsx-runtime";var O="ion.ciam.customer",Z="ion-ciam-logout",M="CIAMProvider",Q={validate(e){if(!e||typeof e!=="object")return null;let t=e;if(typeof t.userName!=="string"||typeof t.name!=="string"||typeof t.email!=="string")return null;return e},revive(e){if(e.ciam?.expires)e.ciam.expires=new Date(e.ciam.expires);return e},isExpired(e){let t=e.ciam?.expires;if(!t)return!1;let r=t instanceof Date?t.getTime():new Date(t).getTime();return Number.isFinite(r)&&r<=Date.now()}},N=ve(void 0);function he({storageKey:e,customerUrl:t,storage:r="memory",disableListener:o=!1,fetchInit:n,log:s=me,children:a}){let c=A(O,e,M),{value:i,setValue:f,isLoading:u,error:d}=R({url:t,storage:r,storageKey:c,disableListener:o,logoutEventName:Z,codec:Q,fetchInit:n,log:s}),m=ye(()=>({customer:i,setCustomer:f,isLoading:u,error:d}),[i,f,u,d]);return Te(N.Provider,{value:m,children:a})}function Ce(){let e=X(N);if(e===void 0)throw Error("useCIAMContext must be used within a CIAMProvider");return e}function C(){return X(N)}async function Se(e,t){return H(e,Q,{storageKey:A(O,t?.storageKey,M),storage:t?.storage??"memory",fetchInit:t?.fetchInit,log:t?.log})}async function xe(e,t){return w(e,{defaultStorageKey:O,logoutEventName:Z,providerLabel:M},t)}import{ACCEPT_JSON as Ie,readJsonResponse as Ae,silentLogger as j}from"@ionite/core";import{useCallback as Pe,useEffect as Re,useState as E}from"react";import{jsx as D,jsxs as U}from"react/jsx-runtime";function ee(e,t=j){let[r,o]=E([]),[n,s]=E(Boolean(e)),[a,c]=E(null),i=Pe(()=>{if(!e)return;let f=!1;return s(!0),c(null),fetch(e,{headers:Ie}).then(async(u)=>{if(!u.ok)throw Error(`Failed to fetch CIAM providers: ${u.status} ${u.statusText}`);let d=await Ae(u,{log:t,operation:"react.ciam.providers"});if(!f)o(Array.isArray(d.providers)?d.providers:[])}).catch((u)=>{let d=u instanceof Error?u:Error(String(u));if(t.error("Error fetching CIAM providers:",d),!f)o([]),c(d)}).finally(()=>{if(!f)s(!1)}),()=>{f=!0}},[e,t]);return Re(()=>i(),[i]),{providers:r,isLoading:n,error:a,refresh:i}}function we(e,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"?e.colors?.dark:e.colors?.light)??(t==="dark"?"#1f1f1f":"#ffffff"),color:t==="dark"?"#ffffff":"#111111",textDecoration:"none",font:"inherit",cursor:"pointer"}}function Ee({providersUrl:e,limit:t,theme:r="light",renderProvider:o,loadingFallback:n,emptyFallback:s,errorFallback:a,moreLabel:c="Show more",className:i,log:f=j}){let{providers:u,isLoading:d,error:m,refresh:x}=ee(e,f),[y,p]=E(!1);if(d)return n??null;if(m)return a?a(m,x):s??null;if(u.length===0)return s??null;let T=!y&&typeof t==="number"&&t>0?u.slice(0,t):u,h=T.length<u.length;return U("div",{className:i,style:{display:"flex",flexDirection:"column",gap:"0.5rem"},"data-ion-ciam-providers":"",children:[T.map((g)=>o?D("span",{children:o(g)},g.name):U("a",{href:g.loginUrl,style:we(g,r),"data-ion-ciam-provider":g.name,children:[g.iconUrl?D("img",{src:g.iconUrl,alt:"",width:20,height:20,"aria-hidden":"true"}):null,U("span",{children:["Continue with ",g.displayName]})]},g.name)),h?D("button",{type:"button",onClick:()=>p(!0),"data-ion-ciam-show-more":"",children:c}):null]})}import{compareDisplayExpiryDesc as Ne,JSON_MEDIA_TYPE as De,readDisplayCookies as Ue,readJsonResponse as Ve}from"@ionite/core";import{createContext as Ke,useCallback as se,useContext as _e,useEffect as Fe,useMemo as We,useState as ie}from"react";import{buildTenantUrl as te,normalizeTenantRoutingStrategy as re}from"@ionite/core";import{createContext as Le,useContext as oe,useMemo as ke}from"react";import{jsx as Me}from"react/jsx-runtime";var V=Le(null);function ne(e,t){let r=re(t);return{ui:(o="/")=>te(e,o,r,"ui"),api:(o="/")=>te(e,o,r,"api")}}function be({id:e,strategy:t,children:r}){let o=ke(()=>{let n=re(t);return{id:e,strategy:n,urls:ne(e,n)}},[t,e]);return Me(V.Provider,{value:o,children:r})}function Oe(){let e=oe(V);if(!e)throw Error("useTenant() must be used within a TenantProvider");return e}function K(){return oe(V)??void 0}import{jsx as Be}from"react/jsx-runtime";var ae=Ke(void 0);function qe(){if(typeof document>"u")return[];return Ue(document.cookie).filter(({envelope:e})=>Date.parse(e.expiresAt)>Date.now()).sort((e,t)=>{let r=e.envelope.kind==="discovered",o=t.envelope.kind==="discovered";if(r!==o)return r?1:-1;return Ne(e.envelope.expiresAt,t.envelope.expiresAt)}).flatMap(({envelope:e})=>e.tenantId?[{tenantId:e.tenantId,authType:e.authType,source:e.kind==="discovered"?"discovered":"session",user:e.user,expiresAt:e.expiresAt,...e.tenantName?{tenantName:e.tenantName}:{}}]:[]).filter((e,t,r)=>r.findIndex((o)=>o.tenantId===e.tenantId)===t)}function Je({sessionsUrl:e,verify:t="auto",currentTenantId:r,fetchInit:o,children:n}){let s=K(),a=r??s?.id,[c,i]=ie("loading"),[f,u]=ie([]),d=se(async(y)=>{let p=qe(),T=Boolean(a)&&!p.some((g)=>g.tenantId===a),h=y||t==="always"||t==="auto"&&(p.length===0||T);if(p.length>0)u(p),i("cookies");else if(!h){u([]),i("unauthenticated");return}if(!h)return;try{let g=new Headers(o?.headers);if(!g.has("Accept"))g.set("Accept",De);let l=await fetch(e,{credentials:"same-origin",...o,headers:g});if(l.status===404){if(p.length===0)u([]),i("unavailable");return}if(l.status===401){if(p.length===0)u([]),i("unauthenticated");return}if(!l.ok){if(p.length===0)u([]),i("unavailable");return}let v=await Ve(l),I=Array.isArray(v.tenants)?v.tenants:[];u(I),i(I.length>0?"verified":"unauthenticated")}catch{if(p.length===0)u([]),i("unavailable")}},[a,o,e,t]);Fe(()=>{if(typeof document>"u")return;d(!1)},[d]);let m=se(()=>d(!0),[d]),x=We(()=>({status:c,tenants:f,refresh:m}),[c,f,m]);return Be(ae.Provider,{value:x,children:n})}function ue(){let e=_e(ae);if(!e)throw Error("useTenants() must be used within a SessionsProvider");return e}function $e(){return ue()}import{silentLogger as ze}from"@ionite/core";import{createContext as Ge,useContext as ce,useMemo as Ye}from"react";import{jsx as je}from"react/jsx-runtime";var le="ion.sso.user",de="ion-sso-logout",fe="SSOProvider",He={validate(e){if(!e||typeof e!=="object")return null;let t=e;if(typeof t.userName!=="string"||typeof t.name!=="string"||typeof t.email!=="string")return null;return e},revive(e){if(e.sso?.expires)e.sso.expires=new Date(e.sso.expires);return e},isExpired(e){let t=e.sso?.expires;if(!t)return!1;let r=t instanceof Date?t.getTime():new Date(t).getTime();return Number.isFinite(r)&&r<=Date.now()}},_=Ge(void 0);function Xe({storageKey:e,userUrl:t,storage:r="memory",disableListener:o=!1,fetchInit:n,log:s=ze,children:a}){let c=A(le,e,fe),{value:i,setValue:f,isLoading:u,error:d}=R({url:t,storage:r,storageKey:c,disableListener:o,logoutEventName:de,codec:He,fetchInit:n,log:s}),m=Ye(()=>({user:i,setUser:f,isLoading:u,error:d}),[i,f,u,d]);return je(_.Provider,{value:m,children:a})}function Ze(){let e=ce(_);if(e===void 0)throw Error("useSSOContext must be used within a SSOProvider");return e}function S(){return ce(_)}async function Qe(e,t){return w(e,{defaultStorageKey:le,logoutEventName:de,providerLabel:fe},t)}import{jsx as rt,Fragment as tt}from"react/jsx-runtime";function et({complete:e=!1,audience:t="workforce",children:r}){let o=S(),n=C();if((t==="customer"?!!n?.isLoading:!!o?.isLoading)&&!e)return rt(tt,{children:r});return null}import{jsx as st,Fragment as nt}from"react/jsx-runtime";function ot({audience:e="workforce",children:t}){let r=S(),o=C();if(e==="customer"?!!o?.customer:!!r?.user)return st(nt,{children:t});return null}import{jsx as ut,Fragment as at}from"react/jsx-runtime";function it({audience:e="workforce",children:t}){let r=S(),o=C(),n=e==="customer"?!!o?.customer:!!r?.user,s=e==="customer"?!!o?.isLoading:!!r?.isLoading;if(n||s)return null;return ut(at,{children:t})}export{he as CIAMProvider,Ee as CIAMProviderList,Xe as SSOProvider,Je as SessionsProvider,et as SignInLoading,ot as SignedIn,it as SignedOut,be as TenantProvider,ne as createTenantUrls,Ht as defaultLogger,Se as getCustomer,Qe as logout,xe as logoutCustomer,Xt as silentLogger,Ce as useCIAMContext,ee as useCIAMProviders,C as useOptionalCIAMContext,S as useOptionalSSOContext,K as useOptionalTenant,Ze as useSSOContext,$e as useSessions,Oe as useTenant,ue as useTenants};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ionite/react",
|
|
3
|
-
"version": "0.0.24-beta.
|
|
3
|
+
"version": "0.0.24-beta.20260927.12",
|
|
4
4
|
"description": "ionite React Components",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "ionite",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"./package.json": "./package.json"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@ionite/core": "0.0.24-beta.
|
|
27
|
+
"@ionite/core": "0.0.24-beta.20260927.12"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"react": "^18.0.0 || ^19.0.0",
|