@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.
- package/dist/auth/authClient.d.ts.map +1 -1
- package/dist/auth.cjs +1 -1
- package/dist/auth.mjs +101 -105
- package/package.json +1 -1
- package/sdk/auth/authClient.ts +15 -21
|
@@ -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;
|
|
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,
|
|
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
|
|
2
|
-
var
|
|
3
|
-
var N = (e, t,
|
|
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
|
|
6
|
-
import { useQueryClient as
|
|
7
|
-
import { c as
|
|
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
|
|
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 = { ...
|
|
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
|
|
46
|
+
function E() {
|
|
47
47
|
return { ...d };
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
return d.baseUrl ||
|
|
49
|
+
function $() {
|
|
50
|
+
return d.baseUrl || ne() || (typeof window < "u" ? window.location.origin : "");
|
|
51
51
|
}
|
|
52
|
-
function
|
|
52
|
+
function M(e) {
|
|
53
53
|
return d.providers[e];
|
|
54
54
|
}
|
|
55
55
|
function we() {
|
|
56
|
-
d = { ...
|
|
56
|
+
d = { ...H };
|
|
57
57
|
}
|
|
58
58
|
class x extends Error {
|
|
59
|
-
constructor(
|
|
60
|
-
super(
|
|
59
|
+
constructor(n, r) {
|
|
60
|
+
super(n);
|
|
61
61
|
N(this, "statusCode");
|
|
62
|
-
this.name = "AuthenticationError", this.statusCode =
|
|
62
|
+
this.name = "AuthenticationError", this.statusCode = r;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
async function ae() {
|
|
66
|
-
const e =
|
|
66
|
+
const e = E(), t = $(), n = oe(), r = await fetch(`${t}${e.sessionEndpoint}`, {
|
|
67
67
|
method: "GET",
|
|
68
|
-
headers:
|
|
68
|
+
headers: n,
|
|
69
69
|
credentials: "include"
|
|
70
70
|
});
|
|
71
|
-
if (!
|
|
72
|
-
throw
|
|
73
|
-
`Session check failed: ${
|
|
74
|
-
|
|
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
|
|
76
|
+
return await r.json();
|
|
77
77
|
}
|
|
78
78
|
function Y(e, t) {
|
|
79
79
|
return new Promise(() => {
|
|
80
|
-
const
|
|
81
|
-
if (!
|
|
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
|
|
86
|
-
if (!
|
|
87
|
-
const w = Object.keys(
|
|
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 "${
|
|
89
|
+
`Auth provider "${s}" is not configured. Available providers: ${w}`
|
|
90
90
|
);
|
|
91
91
|
}
|
|
92
|
-
if (!
|
|
92
|
+
if (!u.loginPath)
|
|
93
93
|
throw new Error(
|
|
94
|
-
`Login path not configured for provider "${
|
|
94
|
+
`Login path not configured for provider "${s}". Configure it with: configureAuth({ providers: { ${s}: { loginPath: '/api/auth/...' } } })`
|
|
95
95
|
);
|
|
96
|
-
let
|
|
96
|
+
let g;
|
|
97
97
|
try {
|
|
98
|
-
|
|
98
|
+
g = new URL(`${r}${u.loginPath}`);
|
|
99
99
|
} catch {
|
|
100
100
|
throw new Error(
|
|
101
|
-
`Failed to construct login URL. Base URL: "${
|
|
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 ||
|
|
104
|
+
(t != null && t.callbackUrl || n.callbackUrl) && g.searchParams.set(
|
|
105
105
|
"callbackUrl",
|
|
106
|
-
(t == null ? void 0 : t.callbackUrl) ||
|
|
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
|
-
|
|
109
|
-
}), window.open(
|
|
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 =
|
|
114
|
-
if (
|
|
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(`${
|
|
117
|
-
|
|
118
|
-
|
|
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
|
|
122
|
+
const V = D(null), G = ["auth", "session"];
|
|
127
123
|
function ye({
|
|
128
124
|
children: e,
|
|
129
125
|
config: t,
|
|
130
|
-
onAuthChange:
|
|
131
|
-
onError:
|
|
132
|
-
loadingComponent:
|
|
133
|
-
unauthenticatedComponent:
|
|
134
|
-
skipInitialCheck:
|
|
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 =
|
|
134
|
+
const A = te(), c = E(), {
|
|
139
135
|
data: i,
|
|
140
|
-
isLoading:
|
|
136
|
+
isLoading: h,
|
|
141
137
|
error: U,
|
|
142
138
|
refetch: v,
|
|
143
139
|
isFetching: m
|
|
144
|
-
} =
|
|
140
|
+
} = re({
|
|
145
141
|
queryKey: G,
|
|
146
142
|
queryFn: ae,
|
|
147
|
-
enabled: !
|
|
148
|
-
retry: (o, y) => y instanceof x && (y.statusCode === 401 || y.statusCode === 403) ? !1 : o <
|
|
149
|
-
retryDelay:
|
|
150
|
-
staleTime:
|
|
151
|
-
gcTime:
|
|
152
|
-
refetchOnWindowFocus:
|
|
153
|
-
refetchOnReconnect:
|
|
154
|
-
refetchInterval:
|
|
155
|
-
}), [
|
|
156
|
-
b.current =
|
|
157
|
-
const R = p(
|
|
158
|
-
R.current =
|
|
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
|
-
|
|
161
|
-
}, [l,
|
|
156
|
+
h || (o = b.current) == null || o.call(b, l, a);
|
|
157
|
+
}, [l, a, h]), L(() => {
|
|
162
158
|
var o;
|
|
163
|
-
U && (
|
|
159
|
+
U && (P(U), (o = R.current) == null || o.call(R, U));
|
|
164
160
|
}, [U]), L(() => {
|
|
165
|
-
l === "unauthenticated" &&
|
|
166
|
-
}, [l,
|
|
167
|
-
const
|
|
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
|
-
),
|
|
168
|
+
), T = f(
|
|
173
169
|
async (o) => {
|
|
174
170
|
A.removeQueries({ queryKey: G }), await se(o);
|
|
175
171
|
},
|
|
176
172
|
[A]
|
|
177
|
-
), j =
|
|
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
|
|
179
|
+
return P(o), null;
|
|
184
180
|
}
|
|
185
|
-
}, [v, m, i]), q =
|
|
186
|
-
(o) => (
|
|
187
|
-
[
|
|
188
|
-
), Q =
|
|
189
|
-
(o) => o.includes((
|
|
190
|
-
[
|
|
191
|
-
), _ =
|
|
192
|
-
|
|
193
|
-
}, []), K =
|
|
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]),
|
|
191
|
+
}, [v]), z = k(
|
|
196
192
|
() => ({
|
|
197
|
-
user:
|
|
198
|
-
staticBaseUrl:
|
|
199
|
-
buildId:
|
|
193
|
+
user: a,
|
|
194
|
+
staticBaseUrl: B,
|
|
195
|
+
buildId: I,
|
|
200
196
|
status: l,
|
|
201
|
-
isAuthenticated:
|
|
202
|
-
isLoading:
|
|
203
|
-
login:
|
|
204
|
-
logout:
|
|
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
|
-
|
|
214
|
-
O,
|
|
209
|
+
a,
|
|
215
210
|
B,
|
|
216
|
-
l,
|
|
217
211
|
I,
|
|
218
|
-
|
|
219
|
-
|
|
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" &&
|
|
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 =
|
|
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
|
-
|
|
279
|
-
|
|
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
package/sdk/auth/authClient.ts
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
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
|
-
|
|
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(),
|
|
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(
|
|
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
|
}
|