@ram_28/kf-ai-sdk 2.0.24 → 2.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/authClient.d.ts.map +1 -1
- package/dist/auth.cjs +1 -1
- package/dist/auth.mjs +1 -1
- package/package.json +1 -1
- package/sdk/auth/authClient.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authClient.d.ts","sourceRoot":"","sources":["../../sdk/auth/authClient.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAgB,UAAU,EAAE,MAAM,CAAC;gBAEvB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAKhD;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAuBjE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,CAAC,EAAE,oBAAoB,EAC/B,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,KAAK,CAAC,CA2DhB;AAED;;;GAGG;AACH,wBAAsB,aAAa,CACjC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"authClient.d.ts","sourceRoot":"","sources":["../../sdk/auth/authClient.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAgB,UAAU,EAAE,MAAM,CAAC;gBAEvB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAKhD;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAuBjE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,CAAC,EAAE,oBAAoB,EAC/B,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,KAAK,CAAC,CA2DhB;AAED;;;GAGG;AACH,wBAAsB,aAAa,CACjC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAsBf"}
|
package/dist/auth.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var J=Object.defineProperty;var X=(e,t,o)=>t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var Q=(e,t,o)=>X(e,typeof t!="symbol"?t+"":t,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),n=require("react"),M=require("@tanstack/react-query"),K=require("./client-D5k4SYuw.cjs"),W=require("./constants-DEmYwKfC.cjs"),Y={sessionEndpoint:"/api/id",providers:{google:{loginPath:"/api/auth/google/login",logoutPath:"/api/auth/logout"}},defaultProvider:"google",autoRedirect:!1,sessionCheckInterval:0,retry:{count:3,delay:1e3},staleTime:5*60*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!0};let h={...Y};function G(e){h={...h,...e,providers:{...h.providers,...e.providers},retry:{...h.retry,...e.retry}}}function Z(e,t){h.providers[e]=t}function b(){return{...h}}function k(){return h.baseUrl||K.getApiBaseUrl()||(typeof window<"u"?window.location.origin:"")}function H(e){return h.providers[e]}function D(){h={...Y}}class E extends Error{constructor(o,r){super(o);Q(this,"statusCode");this.name="AuthenticationError",this.statusCode=r}}async function ee(){const e=b(),t=k(),o=K.getDefaultHeaders(),r=await fetch(`${t}${e.sessionEndpoint}`,{method:"GET",headers:o,credentials:"include"});if(!r.ok)throw r.status===401||r.status===403?new E("Not authenticated",r.status):new E(`Session check failed: ${r.statusText}`,r.status);return await r.json()}function N(e,t){return new Promise(()=>{const o=b(),r=k();if(!r)throw new Error('Auth base URL is not configured. Call setApiBaseUrl("https://...") or configureAuth({ baseUrl: "https://..." }) first.');const i=e||o.defaultProvider,l=H(i);if(!l){const
|
|
1
|
+
"use strict";var J=Object.defineProperty;var X=(e,t,o)=>t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var Q=(e,t,o)=>X(e,typeof t!="symbol"?t+"":t,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),n=require("react"),M=require("@tanstack/react-query"),K=require("./client-D5k4SYuw.cjs"),W=require("./constants-DEmYwKfC.cjs"),Y={sessionEndpoint:"/api/id",providers:{google:{loginPath:"/api/auth/google/login",logoutPath:"/api/auth/logout"}},defaultProvider:"google",autoRedirect:!1,sessionCheckInterval:0,retry:{count:3,delay:1e3},staleTime:5*60*1e3,refetchOnWindowFocus:!1,refetchOnReconnect:!0};let h={...Y};function G(e){h={...h,...e,providers:{...h.providers,...e.providers},retry:{...h.retry,...e.retry}}}function Z(e,t){h.providers[e]=t}function b(){return{...h}}function k(){return h.baseUrl||K.getApiBaseUrl()||(typeof window<"u"?window.location.origin:"")}function H(e){return h.providers[e]}function D(){h={...Y}}class E extends Error{constructor(o,r){super(o);Q(this,"statusCode");this.name="AuthenticationError",this.statusCode=r}}async function ee(){const e=b(),t=k(),o=K.getDefaultHeaders(),r=await fetch(`${t}${e.sessionEndpoint}`,{method:"GET",headers:o,credentials:"include"});if(!r.ok)throw r.status===401||r.status===403?new E("Not authenticated",r.status):new E(`Session check failed: ${r.statusText}`,r.status);return await r.json()}function N(e,t){return new Promise(()=>{const o=b(),r=k();if(!r)throw new Error('Auth base URL is not configured. Call setApiBaseUrl("https://...") or configureAuth({ baseUrl: "https://..." }) first.');const i=e||o.defaultProvider,l=H(i);if(!l){const w=Object.keys(o.providers||{}).join(", ")||"none";throw new Error(`Auth provider "${i}" is not configured. Available providers: ${w}`)}if(!l.loginPath)throw new Error(`Login path not configured for provider "${i}". Configure it with: configureAuth({ providers: { ${i}: { loginPath: '/api/auth/...' } } })`);let g;try{g=new URL(`${r}${l.loginPath}`)}catch{throw new Error(`Failed to construct login URL. Base URL: "${r}", Login path: "${l.loginPath}". Ensure baseUrl is a valid URL (e.g., "https://example.com").`)}(t!=null&&t.callbackUrl||o.callbackUrl)&&g.searchParams.set("callbackUrl",(t==null?void 0:t.callbackUrl)||o.callbackUrl||window.location.href),t!=null&&t.params&&Object.entries(t.params).forEach(([w,v])=>{g.searchParams.set(w,v)}),window.open(g.toString(),"_blank")})}async function te(e){const t=b(),o=k(),r=H(t.defaultProvider),i=r==null?void 0:r.logoutPath;if(i&&(e==null?void 0:e.callLogoutEndpoint)!==!1)try{await fetch(`${o}${i}`,{method:"POST"})}catch(l){console.warn("Logout endpoint call failed:",l)}e!=null&&e.redirectUrl?window.location.href=e.redirectUrl:t.loginRedirectUrl?window.location.href=t.loginRedirectUrl:window.location.href="/"}const V=n.createContext(null),_=["auth","session"];function re({children:e,config:t,onAuthChange:o,onError:r,loadingComponent:i,unauthenticatedComponent:l,skipInitialCheck:g=!1}){const w=n.useRef(!1);t&&!w.current&&(G(t),w.current=!0);const v=M.useQueryClient(),c=b(),{data:a,isLoading:f,error:U,refetch:R,isFetching:P}=M.useQuery({queryKey:_,queryFn:ee,enabled:!g,retry:(s,A)=>A instanceof E&&(A.statusCode===401||A.statusCode===403)?!1:s<c.retry.count,retryDelay:c.retry.delay,staleTime:c.staleTime,gcTime:c.staleTime*2,refetchOnWindowFocus:c.refetchOnWindowFocus??!0,refetchOnReconnect:c.refetchOnReconnect??!0,refetchInterval:c.sessionCheckInterval||!1}),[L,S]=n.useState(null),d=n.useMemo(()=>f||P?"loading":Object.keys((a==null?void 0:a.userDetails)||{}).length>0?"authenticated":"unauthenticated",[f,P,a]),u=(a==null?void 0:a.userDetails)||null,x=(a==null?void 0:a.staticBaseUrl)||null,$=(a==null?void 0:a.buildId)||null,O=d==="authenticated",C=n.useRef(o);C.current=o;const m=n.useRef(r);m.current=r,n.useEffect(()=>{var s;f||(s=C.current)==null||s.call(C,d,u)},[d,u,f]),n.useEffect(()=>{var s;U&&(S(U),(s=m.current)==null||s.call(m,U))},[U]),n.useEffect(()=>{d==="unauthenticated"&&c.autoRedirect&&!f&&N()},[d,f,c.autoRedirect]);const j=n.useCallback((s,A)=>{N(s,A)},[]),p=n.useCallback(async s=>{v.removeQueries({queryKey:_}),await te(s)},[v]),q=n.useCallback(async()=>{if(P)return a||null;try{return(await R()).data||null}catch(s){return S(s),null}},[R,P,a]),B=n.useCallback(s=>(u==null?void 0:u.Role)===s,[u]),I=n.useCallback(s=>s.includes((u==null?void 0:u.Role)||""),[u]),T=n.useCallback(()=>{S(null)},[]),F=n.useCallback(()=>{R()},[R]),z=n.useMemo(()=>({user:u,staticBaseUrl:x,buildId:$,status:d,isAuthenticated:O,isLoading:f,login:j,logout:p,refreshSession:q,hasRole:B,hasAnyRole:I,error:L,clearError:T,_forceCheck:F}),[u,x,$,d,O,f,j,p,q,B,I,L,T,F]);return d==="loading"&&i?y.jsx(y.Fragment,{children:i}):d==="unauthenticated"&&!c.autoRedirect&&l?y.jsx(y.Fragment,{children:l}):y.jsx(V.Provider,{value:z,children:e})}function ne(){const e=n.useContext(V);if(!e)throw new Error("useAuth must be used within an AuthProvider");return e}function oe(){const e=ne();return n.useMemo(()=>({user:e.user,staticBaseUrl:e.staticBaseUrl,buildId:e.buildId,status:e.status,isAuthenticated:e.isAuthenticated,isLoading:e.isLoading,login:e.login,logout:e.logout,refreshSession:e.refreshSession,hasRole:e.hasRole,hasAnyRole:e.hasAnyRole,error:e.error,clearError:e.clearError}),[e.user,e.staticBaseUrl,e.buildId,e.status,e.isAuthenticated,e.isLoading,e.login,e.logout,e.refreshSession,e.hasRole,e.hasAnyRole,e.error,e.clearError])}exports.AuthProviderName=W.AuthProviderName;exports.AuthStatus=W.AuthStatus;exports.AuthProvider=re;exports.AuthenticationError=E;exports.configureAuth=G;exports.getAuthBaseUrl=k;exports.getAuthConfig=b;exports.resetAuthConfig=D;exports.setAuthProvider=Z;exports.useAuth=oe;
|
package/dist/auth.mjs
CHANGED
|
@@ -117,7 +117,7 @@ async function se(e) {
|
|
|
117
117
|
} catch (u) {
|
|
118
118
|
console.warn("Logout endpoint call failed:", u);
|
|
119
119
|
}
|
|
120
|
-
e != null && e.redirectUrl ? window.location.href = e.redirectUrl : t.loginRedirectUrl
|
|
120
|
+
e != null && e.redirectUrl ? window.location.href = e.redirectUrl : t.loginRedirectUrl ? window.location.href = t.loginRedirectUrl : window.location.href = "/";
|
|
121
121
|
}
|
|
122
122
|
const V = D(null), G = ["auth", "session"];
|
|
123
123
|
function ye({
|
package/package.json
CHANGED
package/sdk/auth/authClient.ts
CHANGED