@ram_28/kf-ai-sdk 2.0.18 → 2.0.19

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.
@@ -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;AAQjB;;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,CA0DhB;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyB9E"}
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,CAoBf"}
package/dist/auth.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var J=Object.defineProperty;var X=(e,t,n)=>t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var M=(e,t,n)=>X(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),r=require("react"),N=require("@tanstack/react-query"),L=require("./client-D5k4SYuw.cjs"),W=require("./constants-DEmYwKfC.cjs"),H={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={...H};function Y(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||L.getApiBaseUrl()||(typeof window<"u"?window.location.origin:"")}function G(e){return h.providers[e]}function D(){h={...H}}class E extends Error{constructor(n,o){super(n);M(this,"statusCode");this.name="AuthenticationError",this.statusCode=o}}async function ee(){const e=b(),t=k(),n=L.getDefaultHeaders(),o=await fetch(`${t}${e.sessionEndpoint}`,{method:"GET",headers:n,credentials:"include"});if(!o.ok)throw o.status===401||o.status===403?new E("Not authenticated",o.status):new E(`Session check failed: ${o.statusText}`,o.status);return await o.json()}function _(e,t){return new Promise(()=>{const n=b(),o=k();if(!o)throw new Error('Auth base URL is not configured. Call setApiBaseUrl("https://...") or configureAuth({ baseUrl: "https://..." }) first.');const u=e||n.defaultProvider,c=G(u);if(!c){const A=Object.keys(n.providers||{}).join(", ")||"none";throw new Error(`Auth provider "${u}" is not configured. Available providers: ${A}`)}if(!c.loginPath)throw new Error(`Login path not configured for provider "${u}". Configure it with: configureAuth({ providers: { ${u}: { loginPath: '/api/auth/...' } } })`);let f;try{f=new URL(`${o}${c.loginPath}`)}catch{throw new Error(`Failed to construct login URL. Base URL: "${o}", Login path: "${c.loginPath}". Ensure baseUrl is a valid URL (e.g., "https://example.com").`)}(t!=null&&t.callbackUrl||n.callbackUrl)&&f.searchParams.set("callbackUrl",(t==null?void 0:t.callbackUrl)||n.callbackUrl||window.location.href),t!=null&&t.params&&Object.entries(t.params).forEach(([A,v])=>{f.searchParams.set(A,v)}),window.open(f.toString(),"_blank")})}async function te(e){const t=b(),n=k(),o=L.getDefaultHeaders(),u=G(t.defaultProvider),c=u==null?void 0:u.logoutPath;if(c&&(e==null?void 0:e.callLogoutEndpoint)!==!1)try{await fetch(`${n}${c}`,{method:"POST",headers:o,credentials:"include"})}catch(f){console.warn("Logout endpoint call failed:",f)}e!=null&&e.redirectUrl?window.location.href=e.redirectUrl:t.loginRedirectUrl&&(window.location.href=t.loginRedirectUrl)}const V=r.createContext(null),K=["auth","session"];function re({children:e,config:t,onAuthChange:n,onError:o,loadingComponent:u,unauthenticatedComponent:c,skipInitialCheck:f=!1}){const A=r.useRef(!1);t&&!A.current&&(Y(t),A.current=!0);const v=N.useQueryClient(),l=b(),{data:a,isLoading:g,error:U,refetch:R,isFetching:P}=N.useQuery({queryKey:K,queryFn:ee,enabled:!f,retry:(s,w)=>w instanceof E&&(w.statusCode===401||w.statusCode===403)?!1:s<l.retry.count,retryDelay:l.retry.delay,staleTime:l.staleTime,gcTime:l.staleTime*2,refetchOnWindowFocus:l.refetchOnWindowFocus??!0,refetchOnReconnect:l.refetchOnReconnect??!0,refetchInterval:l.sessionCheckInterval||!1}),[x,S]=r.useState(null),d=r.useMemo(()=>g||P?"loading":Object.keys((a==null?void 0:a.userDetails)||{}).length>0?"authenticated":"unauthenticated",[g,P,a]),i=(a==null?void 0:a.userDetails)||null,$=(a==null?void 0:a.staticBaseUrl)||null,O=(a==null?void 0:a.buildId)||null,j=d==="authenticated",C=r.useRef(n);C.current=n;const m=r.useRef(o);m.current=o,r.useEffect(()=>{var s;g||(s=C.current)==null||s.call(C,d,i)},[d,i,g]),r.useEffect(()=>{var s;U&&(S(U),(s=m.current)==null||s.call(m,U))},[U]),r.useEffect(()=>{d==="unauthenticated"&&l.autoRedirect&&!g&&_()},[d,g,l.autoRedirect]);const p=r.useCallback((s,w)=>{_(s,w)},[]),q=r.useCallback(async s=>{v.removeQueries({queryKey:K}),await te(s)},[v]),B=r.useCallback(async()=>{if(P)return a||null;try{return(await R()).data||null}catch(s){return S(s),null}},[R,P,a]),I=r.useCallback(s=>(i==null?void 0:i.Role)===s,[i]),T=r.useCallback(s=>s.includes((i==null?void 0:i.Role)||""),[i]),F=r.useCallback(()=>{S(null)},[]),Q=r.useCallback(()=>{R()},[R]),z=r.useMemo(()=>({user:i,staticBaseUrl:$,buildId:O,status:d,isAuthenticated:j,isLoading:g,login:p,logout:q,refreshSession:B,hasRole:I,hasAnyRole:T,error:x,clearError:F,_forceCheck:Q}),[i,$,O,d,j,g,p,q,B,I,T,x,F,Q]);return d==="loading"&&u?y.jsx(y.Fragment,{children:u}):d==="unauthenticated"&&!l.autoRedirect&&c?y.jsx(y.Fragment,{children:c}):y.jsx(V.Provider,{value:z,children:e})}function ne(){const e=r.useContext(V);if(!e)throw new Error("useAuth must be used within an AuthProvider");return e}function oe(){const e=ne();return r.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=Y;exports.getAuthBaseUrl=k;exports.getAuthConfig=b;exports.resetAuthConfig=D;exports.setAuthProvider=Z;exports.useAuth=oe;
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 m 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 m("Not authenticated",r.status):new m(`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 A=Object.keys(o.providers||{}).join(", ")||"none";throw new Error(`Auth provider "${i}" is not configured. Available providers: ${A}`)}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(([A,v])=>{g.searchParams.set(A,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}`)}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)}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 A=n.useRef(!1);t&&!A.current&&(G(t),A.current=!0);const v=M.useQueryClient(),c=b(),{data:u,isLoading:f,error:U,refetch:R,isFetching:C}=M.useQuery({queryKey:_,queryFn:ee,enabled:!g,retry:(s,w)=>w instanceof m&&(w.statusCode===401||w.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}),[S,L]=n.useState(null),d=n.useMemo(()=>f||C?"loading":Object.keys((u==null?void 0:u.userDetails)||{}).length>0?"authenticated":"unauthenticated",[f,C,u]),a=(u==null?void 0:u.userDetails)||null,x=(u==null?void 0:u.staticBaseUrl)||null,$=(u==null?void 0:u.buildId)||null,j=d==="authenticated",P=n.useRef(o);P.current=o;const E=n.useRef(r);E.current=r,n.useEffect(()=>{var s;f||(s=P.current)==null||s.call(P,d,a)},[d,a,f]),n.useEffect(()=>{var s;U&&(L(U),(s=E.current)==null||s.call(E,U))},[U]),n.useEffect(()=>{d==="unauthenticated"&&c.autoRedirect&&!f&&N()},[d,f,c.autoRedirect]);const p=n.useCallback((s,w)=>{N(s,w)},[]),q=n.useCallback(async s=>{v.removeQueries({queryKey:_}),await te(s)},[v]),B=n.useCallback(async()=>{if(C)return u||null;try{return(await R()).data||null}catch(s){return L(s),null}},[R,C,u]),O=n.useCallback(s=>(a==null?void 0:a.Role)===s,[a]),I=n.useCallback(s=>s.includes((a==null?void 0:a.Role)||""),[a]),F=n.useCallback(()=>{L(null)},[]),T=n.useCallback(()=>{R()},[R]),z=n.useMemo(()=>({user:a,staticBaseUrl:x,buildId:$,status:d,isAuthenticated:j,isLoading:f,login:p,logout:q,refreshSession:B,hasRole:O,hasAnyRole:I,error:S,clearError:F,_forceCheck:T}),[a,x,$,d,j,f,p,q,B,O,I,S,F,T]);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=m;exports.configureAuth=G;exports.getAuthBaseUrl=k;exports.getAuthConfig=b;exports.resetAuthConfig=D;exports.setAuthProvider=Z;exports.useAuth=oe;
package/dist/auth.mjs CHANGED
@@ -1,12 +1,12 @@
1
- var X = Object.defineProperty;
2
- var Z = (e, t, r) => t in e ? X(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var N = (e, t, r) => Z(e, typeof t != "symbol" ? t + "" : t, r);
1
+ var J = Object.defineProperty;
2
+ var X = (e, t, n) => t in e ? J(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var N = (e, t, n) => X(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  import { jsx as C, Fragment as W } from "react/jsx-runtime";
5
- import { useRef as p, useState as D, useMemo as k, useEffect as L, useCallback as g, createContext as ee, useContext as te } from "react";
6
- import { useQueryClient as re, useQuery as ne } from "@tanstack/react-query";
7
- import { c as oe, g as H } from "./client-_ayziI1d.js";
5
+ import { useRef as p, useState as Z, useMemo as k, useEffect as L, useCallback as f, createContext as D, useContext as ee } from "react";
6
+ import { useQueryClient as te, useQuery as re } from "@tanstack/react-query";
7
+ import { c as ne, g as oe } from "./client-_ayziI1d.js";
8
8
  import { c as me, A as be } from "./constants-Cyi942Yr.js";
9
- const M = {
9
+ const H = {
10
10
  sessionEndpoint: "/api/id",
11
11
  providers: {
12
12
  google: {
@@ -25,7 +25,7 @@ const M = {
25
25
  refetchOnWindowFocus: !1,
26
26
  refetchOnReconnect: !0
27
27
  };
28
- let d = { ...M };
28
+ let d = { ...H };
29
29
  function ie(e) {
30
30
  d = {
31
31
  ...d,
@@ -43,193 +43,189 @@ function ie(e) {
43
43
  function ge(e, t) {
44
44
  d.providers[e] = t;
45
45
  }
46
- function P() {
46
+ function E() {
47
47
  return { ...d };
48
48
  }
49
- function S() {
50
- return d.baseUrl || oe() || (typeof window < "u" ? window.location.origin : "");
49
+ function $() {
50
+ return d.baseUrl || ne() || (typeof window < "u" ? window.location.origin : "");
51
51
  }
52
- function V(e) {
52
+ function M(e) {
53
53
  return d.providers[e];
54
54
  }
55
55
  function we() {
56
- d = { ...M };
56
+ d = { ...H };
57
57
  }
58
58
  class x extends Error {
59
- constructor(r, n) {
60
- super(r);
59
+ constructor(n, r) {
60
+ super(n);
61
61
  N(this, "statusCode");
62
- this.name = "AuthenticationError", this.statusCode = n;
62
+ this.name = "AuthenticationError", this.statusCode = r;
63
63
  }
64
64
  }
65
65
  async function ae() {
66
- const e = P(), t = S(), r = H(), n = await fetch(`${t}${e.sessionEndpoint}`, {
66
+ const e = E(), t = $(), n = oe(), r = await fetch(`${t}${e.sessionEndpoint}`, {
67
67
  method: "GET",
68
- headers: r,
68
+ headers: n,
69
69
  credentials: "include"
70
70
  });
71
- if (!n.ok)
72
- throw n.status === 401 || n.status === 403 ? new x("Not authenticated", n.status) : new x(
73
- `Session check failed: ${n.statusText}`,
74
- n.status
71
+ if (!r.ok)
72
+ throw r.status === 401 || r.status === 403 ? new x("Not authenticated", r.status) : new x(
73
+ `Session check failed: ${r.statusText}`,
74
+ r.status
75
75
  );
76
- return await n.json();
76
+ return await r.json();
77
77
  }
78
78
  function Y(e, t) {
79
79
  return new Promise(() => {
80
- const r = P(), n = S();
81
- if (!n)
80
+ const n = E(), r = $();
81
+ if (!r)
82
82
  throw new Error(
83
83
  'Auth base URL is not configured. Call setApiBaseUrl("https://...") or configureAuth({ baseUrl: "https://..." }) first.'
84
84
  );
85
- const a = e || r.defaultProvider, c = V(a);
86
- if (!c) {
87
- const w = Object.keys(r.providers || {}).join(", ") || "none";
85
+ const s = e || n.defaultProvider, u = M(s);
86
+ if (!u) {
87
+ const w = Object.keys(n.providers || {}).join(", ") || "none";
88
88
  throw new Error(
89
- `Auth provider "${a}" is not configured. Available providers: ${w}`
89
+ `Auth provider "${s}" is not configured. Available providers: ${w}`
90
90
  );
91
91
  }
92
- if (!c.loginPath)
92
+ if (!u.loginPath)
93
93
  throw new Error(
94
- `Login path not configured for provider "${a}". Configure it with: configureAuth({ providers: { ${a}: { loginPath: '/api/auth/...' } } })`
94
+ `Login path not configured for provider "${s}". Configure it with: configureAuth({ providers: { ${s}: { loginPath: '/api/auth/...' } } })`
95
95
  );
96
- let h;
96
+ let g;
97
97
  try {
98
- h = new URL(`${n}${c.loginPath}`);
98
+ g = new URL(`${r}${u.loginPath}`);
99
99
  } catch {
100
100
  throw new Error(
101
- `Failed to construct login URL. Base URL: "${n}", Login path: "${c.loginPath}". Ensure baseUrl is a valid URL (e.g., "https://example.com").`
101
+ `Failed to construct login URL. Base URL: "${r}", Login path: "${u.loginPath}". Ensure baseUrl is a valid URL (e.g., "https://example.com").`
102
102
  );
103
103
  }
104
- (t != null && t.callbackUrl || r.callbackUrl) && h.searchParams.set(
104
+ (t != null && t.callbackUrl || n.callbackUrl) && g.searchParams.set(
105
105
  "callbackUrl",
106
- (t == null ? void 0 : t.callbackUrl) || r.callbackUrl || window.location.href
106
+ (t == null ? void 0 : t.callbackUrl) || n.callbackUrl || window.location.href
107
107
  ), t != null && t.params && Object.entries(t.params).forEach(([w, A]) => {
108
- h.searchParams.set(w, A);
109
- }), window.open(h.toString(), "_blank");
108
+ g.searchParams.set(w, A);
109
+ }), window.open(g.toString(), "_blank");
110
110
  });
111
111
  }
112
112
  async function se(e) {
113
- const t = P(), r = S(), n = H(), a = V(t.defaultProvider), c = a == null ? void 0 : a.logoutPath;
114
- if (c && (e == null ? void 0 : e.callLogoutEndpoint) !== !1)
113
+ const t = E(), n = $(), r = M(t.defaultProvider), s = r == null ? void 0 : r.logoutPath;
114
+ if (s && (e == null ? void 0 : e.callLogoutEndpoint) !== !1)
115
115
  try {
116
- await fetch(`${r}${c}`, {
117
- method: "POST",
118
- headers: n,
119
- credentials: "include"
120
- });
121
- } catch (h) {
122
- console.warn("Logout endpoint call failed:", h);
116
+ await fetch(`${n}${s}`);
117
+ } catch (u) {
118
+ console.warn("Logout endpoint call failed:", u);
123
119
  }
124
120
  e != null && e.redirectUrl ? window.location.href = e.redirectUrl : t.loginRedirectUrl && (window.location.href = t.loginRedirectUrl);
125
121
  }
126
- const z = ee(null), G = ["auth", "session"];
122
+ const V = D(null), G = ["auth", "session"];
127
123
  function ye({
128
124
  children: e,
129
125
  config: t,
130
- onAuthChange: r,
131
- onError: n,
132
- loadingComponent: a,
133
- unauthenticatedComponent: c,
134
- skipInitialCheck: h = !1
126
+ onAuthChange: n,
127
+ onError: r,
128
+ loadingComponent: s,
129
+ unauthenticatedComponent: u,
130
+ skipInitialCheck: g = !1
135
131
  }) {
136
132
  const w = p(!1);
137
133
  t && !w.current && (ie(t), w.current = !0);
138
- const A = re(), u = P(), {
134
+ const A = te(), c = E(), {
139
135
  data: i,
140
- isLoading: f,
136
+ isLoading: h,
141
137
  error: U,
142
138
  refetch: v,
143
139
  isFetching: m
144
- } = ne({
140
+ } = re({
145
141
  queryKey: G,
146
142
  queryFn: ae,
147
- enabled: !h,
148
- retry: (o, y) => y instanceof x && (y.statusCode === 401 || y.statusCode === 403) ? !1 : o < u.retry.count,
149
- retryDelay: u.retry.delay,
150
- staleTime: u.staleTime,
151
- gcTime: u.staleTime * 2,
152
- refetchOnWindowFocus: u.refetchOnWindowFocus ?? !0,
153
- refetchOnReconnect: u.refetchOnReconnect ?? !0,
154
- refetchInterval: u.sessionCheckInterval || !1
155
- }), [$, E] = D(null), l = k(() => f || m ? "loading" : Object.keys((i == null ? void 0 : i.userDetails) || {}).length > 0 ? "authenticated" : "unauthenticated", [f, m, i]), s = (i == null ? void 0 : i.userDetails) || null, O = (i == null ? void 0 : i.staticBaseUrl) || null, B = (i == null ? void 0 : i.buildId) || null, I = l === "authenticated", b = p(r);
156
- b.current = r;
157
- const R = p(n);
158
- R.current = n, L(() => {
143
+ enabled: !g,
144
+ retry: (o, y) => y instanceof x && (y.statusCode === 401 || y.statusCode === 403) ? !1 : o < c.retry.count,
145
+ retryDelay: c.retry.delay,
146
+ staleTime: c.staleTime,
147
+ gcTime: c.staleTime * 2,
148
+ refetchOnWindowFocus: c.refetchOnWindowFocus ?? !0,
149
+ refetchOnReconnect: c.refetchOnReconnect ?? !0,
150
+ refetchInterval: c.sessionCheckInterval || !1
151
+ }), [S, P] = Z(null), l = k(() => h || m ? "loading" : Object.keys((i == null ? void 0 : i.userDetails) || {}).length > 0 ? "authenticated" : "unauthenticated", [h, m, i]), a = (i == null ? void 0 : i.userDetails) || null, B = (i == null ? void 0 : i.staticBaseUrl) || null, I = (i == null ? void 0 : i.buildId) || null, O = l === "authenticated", b = p(n);
152
+ b.current = n;
153
+ const R = p(r);
154
+ R.current = r, L(() => {
159
155
  var o;
160
- f || (o = b.current) == null || o.call(b, l, s);
161
- }, [l, s, f]), L(() => {
156
+ h || (o = b.current) == null || o.call(b, l, a);
157
+ }, [l, a, h]), L(() => {
162
158
  var o;
163
- U && (E(U), (o = R.current) == null || o.call(R, U));
159
+ U && (P(U), (o = R.current) == null || o.call(R, U));
164
160
  }, [U]), L(() => {
165
- l === "unauthenticated" && u.autoRedirect && !f && Y();
166
- }, [l, f, u.autoRedirect]);
167
- const T = g(
161
+ l === "unauthenticated" && c.autoRedirect && !h && Y();
162
+ }, [l, h, c.autoRedirect]);
163
+ const F = f(
168
164
  (o, y) => {
169
165
  Y(o, y);
170
166
  },
171
167
  []
172
- ), F = g(
168
+ ), T = f(
173
169
  async (o) => {
174
170
  A.removeQueries({ queryKey: G }), await se(o);
175
171
  },
176
172
  [A]
177
- ), j = g(async () => {
173
+ ), j = f(async () => {
178
174
  if (m)
179
175
  return i || null;
180
176
  try {
181
177
  return (await v()).data || null;
182
178
  } catch (o) {
183
- return E(o), null;
179
+ return P(o), null;
184
180
  }
185
- }, [v, m, i]), q = g(
186
- (o) => (s == null ? void 0 : s.Role) === o,
187
- [s]
188
- ), Q = g(
189
- (o) => o.includes((s == null ? void 0 : s.Role) || ""),
190
- [s]
191
- ), _ = g(() => {
192
- E(null);
193
- }, []), K = g(() => {
181
+ }, [v, m, i]), q = f(
182
+ (o) => (a == null ? void 0 : a.Role) === o,
183
+ [a]
184
+ ), Q = f(
185
+ (o) => o.includes((a == null ? void 0 : a.Role) || ""),
186
+ [a]
187
+ ), _ = f(() => {
188
+ P(null);
189
+ }, []), K = f(() => {
194
190
  v();
195
- }, [v]), J = k(
191
+ }, [v]), z = k(
196
192
  () => ({
197
- user: s,
198
- staticBaseUrl: O,
199
- buildId: B,
193
+ user: a,
194
+ staticBaseUrl: B,
195
+ buildId: I,
200
196
  status: l,
201
- isAuthenticated: I,
202
- isLoading: f,
203
- login: T,
204
- logout: F,
197
+ isAuthenticated: O,
198
+ isLoading: h,
199
+ login: F,
200
+ logout: T,
205
201
  refreshSession: j,
206
202
  hasRole: q,
207
203
  hasAnyRole: Q,
208
- error: $,
204
+ error: S,
209
205
  clearError: _,
210
206
  _forceCheck: K
211
207
  }),
212
208
  [
213
- s,
214
- O,
209
+ a,
215
210
  B,
216
- l,
217
211
  I,
218
- f,
219
- T,
212
+ l,
213
+ O,
214
+ h,
220
215
  F,
216
+ T,
221
217
  j,
222
218
  q,
223
219
  Q,
224
- $,
220
+ S,
225
221
  _,
226
222
  K
227
223
  ]
228
224
  );
229
- return l === "loading" && a ? /* @__PURE__ */ C(W, { children: a }) : l === "unauthenticated" && !u.autoRedirect && c ? /* @__PURE__ */ C(W, { children: c }) : /* @__PURE__ */ C(z.Provider, { value: J, children: e });
225
+ return l === "loading" && s ? /* @__PURE__ */ C(W, { children: s }) : l === "unauthenticated" && !c.autoRedirect && u ? /* @__PURE__ */ C(W, { children: u }) : /* @__PURE__ */ C(V.Provider, { value: z, children: e });
230
226
  }
231
227
  function ce() {
232
- const e = te(z);
228
+ const e = ee(V);
233
229
  if (!e)
234
230
  throw new Error("useAuth must be used within an AuthProvider");
235
231
  return e;
@@ -275,8 +271,8 @@ export {
275
271
  be as AuthStatus,
276
272
  x as AuthenticationError,
277
273
  ie as configureAuth,
278
- S as getAuthBaseUrl,
279
- P as getAuthConfig,
274
+ $ as getAuthBaseUrl,
275
+ E as getAuthConfig,
280
276
  we as resetAuthConfig,
281
277
  ge as setAuthProvider,
282
278
  Ae as useAuth
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ram_28/kf-ai-sdk",
3
- "version": "2.0.18",
3
+ "version": "2.0.19",
4
4
  "description": "Type-safe, AI-driven SDK for building modern web applications with role-based access control",
5
5
  "author": "Ramprasad",
6
6
  "license": "MIT",
@@ -9,11 +9,7 @@ import type {
9
9
  LoginOptionsType,
10
10
  LogoutOptionsType,
11
11
  } from "./types";
12
- import {
13
- getAuthBaseUrl,
14
- getAuthConfig,
15
- getProviderConfig,
16
- } from "./authConfig";
12
+ import { getAuthBaseUrl, getAuthConfig, getProviderConfig } from "./authConfig";
17
13
  import { getDefaultHeaders } from "../api/client";
18
14
 
19
15
  /**
@@ -52,7 +48,7 @@ export async function fetchSession(): Promise<SessionResponseType> {
52
48
  }
53
49
  throw new AuthenticationError(
54
50
  `Session check failed: ${response.statusText}`,
55
- response.status
51
+ response.status,
56
52
  );
57
53
  }
58
54
 
@@ -82,7 +78,7 @@ export async function fetchSession(): Promise<SessionResponseType> {
82
78
  */
83
79
  export function initiateLogin(
84
80
  provider?: AuthProviderNameType,
85
- options?: LoginOptionsType
81
+ options?: LoginOptionsType,
86
82
  ): Promise<never> {
87
83
  return new Promise(() => {
88
84
  const config = getAuthConfig();
@@ -91,7 +87,7 @@ export function initiateLogin(
91
87
  // Validate base URL
92
88
  if (!baseUrl) {
93
89
  throw new Error(
94
- 'Auth base URL is not configured. Call setApiBaseUrl("https://...") or configureAuth({ baseUrl: "https://..." }) first.'
90
+ 'Auth base URL is not configured. Call setApiBaseUrl("https://...") or configureAuth({ baseUrl: "https://..." }) first.',
95
91
  );
96
92
  }
97
93
 
@@ -100,9 +96,10 @@ export function initiateLogin(
100
96
 
101
97
  // Validate provider config
102
98
  if (!providerConfig) {
103
- const availableProviders = Object.keys(config.providers || {}).join(", ") || "none";
99
+ const availableProviders =
100
+ Object.keys(config.providers || {}).join(", ") || "none";
104
101
  throw new Error(
105
- `Auth provider "${selectedProvider}" is not configured. Available providers: ${availableProviders}`
102
+ `Auth provider "${selectedProvider}" is not configured. Available providers: ${availableProviders}`,
106
103
  );
107
104
  }
108
105
 
@@ -110,7 +107,7 @@ export function initiateLogin(
110
107
  if (!providerConfig.loginPath) {
111
108
  throw new Error(
112
109
  `Login path not configured for provider "${selectedProvider}". ` +
113
- `Configure it with: configureAuth({ providers: { ${selectedProvider}: { loginPath: '/api/auth/...' } } })`
110
+ `Configure it with: configureAuth({ providers: { ${selectedProvider}: { loginPath: '/api/auth/...' } } })`,
114
111
  );
115
112
  }
116
113
 
@@ -121,14 +118,14 @@ export function initiateLogin(
121
118
  } catch {
122
119
  throw new Error(
123
120
  `Failed to construct login URL. Base URL: "${baseUrl}", Login path: "${providerConfig.loginPath}". ` +
124
- `Ensure baseUrl is a valid URL (e.g., "https://example.com").`
121
+ `Ensure baseUrl is a valid URL (e.g., "https://example.com").`,
125
122
  );
126
123
  }
127
124
 
128
125
  if (options?.callbackUrl || config.callbackUrl) {
129
126
  loginUrl.searchParams.set(
130
127
  "callbackUrl",
131
- options?.callbackUrl || config.callbackUrl || window.location.href
128
+ options?.callbackUrl || config.callbackUrl || window.location.href,
132
129
  );
133
130
  }
134
131
 
@@ -138,7 +135,7 @@ export function initiateLogin(
138
135
  });
139
136
  }
140
137
 
141
- window.open(loginUrl.toString(), '_blank');
138
+ window.open(loginUrl.toString(), "_blank");
142
139
  // Promise never resolves - login opens in new tab
143
140
  });
144
141
  }
@@ -147,21 +144,18 @@ export function initiateLogin(
147
144
  * Logout the current user
148
145
  * Optionally calls the logout endpoint before clearing client state
149
146
  */
150
- export async function performLogout(options?: LogoutOptionsType): Promise<void> {
147
+ export async function performLogout(
148
+ options?: LogoutOptionsType,
149
+ ): Promise<void> {
151
150
  const config = getAuthConfig();
152
151
  const baseUrl = getAuthBaseUrl();
153
- const headers = getDefaultHeaders();
154
152
 
155
153
  const providerConfig = getProviderConfig(config.defaultProvider);
156
154
  const logoutPath = providerConfig?.logoutPath;
157
155
 
158
156
  if (logoutPath && options?.callLogoutEndpoint !== false) {
159
157
  try {
160
- await fetch(`${baseUrl}${logoutPath}`, {
161
- method: "POST",
162
- headers,
163
- credentials: "include",
164
- });
158
+ await fetch(`${baseUrl}${logoutPath}`);
165
159
  } catch (error) {
166
160
  console.warn("Logout endpoint call failed:", error);
167
161
  }