@amaster.ai/auth-client 1.1.60-beta.1 → 1.1.61-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/dist/auth.d.cts +12 -1
- package/dist/auth.d.ts +12 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/oauth.d.cts +1 -1
- package/dist/oauth.d.ts +1 -1
- package/dist/permissions.d.cts +1 -1
- package/dist/permissions.d.ts +1 -1
- package/dist/sessions.d.cts +1 -1
- package/dist/sessions.d.ts +1 -1
- package/dist/{types-DRTmNpY7.d.cts → types-CFVDTREm.d.cts} +12 -2
- package/dist/{types-DRTmNpY7.d.ts → types-CFVDTREm.d.ts} +12 -2
- package/dist/user.d.cts +1 -1
- package/dist/user.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -196,6 +196,34 @@ include `result.data.redirectHandled === true` and `result.data.redirectTarget`.
|
|
|
196
196
|
Applications that still run their own post-login navigation should short-circuit
|
|
197
197
|
on that flag to avoid double redirects.
|
|
198
198
|
|
|
199
|
+
**Application-scoped Feishu login:**
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// The SDK uses requestAccess in the Feishu client and regular OAuth elsewhere.
|
|
203
|
+
// Pass a local path to restore the page that initiated login.
|
|
204
|
+
const result = await authClient.loginWithFeishu("/dashboard");
|
|
205
|
+
|
|
206
|
+
// Browser OAuth returns null because navigation has started. The callback page
|
|
207
|
+
// exchanges the short-lived, one-time login_ticket automatically.
|
|
208
|
+
if (result?.error) {
|
|
209
|
+
console.error(result.error.message);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// /auth/callback
|
|
213
|
+
const callbackResult = await authClient.handleOAuthCallback();
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
The Feishu App ID and App Secret belong to the current application environment,
|
|
217
|
+
not to the Platform process. The SDK only receives the public App ID. The App
|
|
218
|
+
Secret stays in Runtime, and a browser callback carries a 60-second one-time
|
|
219
|
+
ticket instead of an application access token. If a Feishu client does not
|
|
220
|
+
support `requestAccess`, the SDK falls back to `requestAuthCode`.
|
|
221
|
+
|
|
222
|
+
Applications that already obtain a Feishu code may call
|
|
223
|
+
`loginWithFeishuCode(code, returnUrl)`. A callback can also explicitly call
|
|
224
|
+
`exchangeOAuthLoginTicket(ticket)`, although `handleOAuthCallback()` normally
|
|
225
|
+
handles this automatically.
|
|
226
|
+
|
|
199
227
|
**Popup window:**
|
|
200
228
|
|
|
201
229
|
```typescript
|
package/dist/auth.d.cts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* ============================================================================
|
|
15
15
|
*/
|
|
16
16
|
import { HttpClient, ClientResult } from '@amaster.ai/http-client';
|
|
17
|
-
import {
|
|
17
|
+
import { x as User, R as RefreshTokenResponse, p as RegisterParams, e as LoginResponse, L as LoginParams, c as CodeLoginParams, S as SendCodeParams, w as SuccessResponse, b as CaptchaResponse, n as OAuthProvider, i as MiniProgramLoginParams, h as MiniLoginParams, k as MiniProgramPhoneParams, l as MiniProgramPhoneResponse, g as MiniGetPhoneParams } from './types-CFVDTREm.cjs';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Authentication Module
|
|
@@ -31,6 +31,7 @@ import { w as User, R as RefreshTokenResponse, o as RegisterParams, e as LoginRe
|
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
33
|
declare const browserNavigation: {
|
|
34
|
+
assign(url: string): void;
|
|
34
35
|
replace(url: string): void;
|
|
35
36
|
};
|
|
36
37
|
interface AuthModuleDeps {
|
|
@@ -41,6 +42,7 @@ interface AuthModuleDeps {
|
|
|
41
42
|
storage: {
|
|
42
43
|
getItem: (key: string) => string | null;
|
|
43
44
|
setItem: (key: string, value: string) => void;
|
|
45
|
+
removeItem: (key: string) => void;
|
|
44
46
|
};
|
|
45
47
|
clearAuth: () => void;
|
|
46
48
|
onRefreshFailure?: (result: ClientResult<RefreshTokenResponse>) => void;
|
|
@@ -129,6 +131,15 @@ declare function createAuthModule(deps: AuthModuleDeps): {
|
|
|
129
131
|
* ```
|
|
130
132
|
*/
|
|
131
133
|
loginWithOAuth(provider: OAuthProvider, redirectUrl?: string): void;
|
|
134
|
+
/**
|
|
135
|
+
* Log in with the Feishu application configured for the current AMaster app.
|
|
136
|
+
* Uses requestAccess inside Feishu and browser OAuth elsewhere.
|
|
137
|
+
*/
|
|
138
|
+
loginWithFeishu(returnUrl?: string): Promise<ClientResult<LoginResponse> | null>;
|
|
139
|
+
/** Submit an existing requestAccess/requestAuthCode code. */
|
|
140
|
+
loginWithFeishuCode(code: string, returnUrl?: string): Promise<ClientResult<LoginResponse>>;
|
|
141
|
+
/** Exchange a short-lived, one-time application OAuth login ticket. */
|
|
142
|
+
exchangeOAuthLoginTicket(ticket: string): Promise<ClientResult<LoginResponse>>;
|
|
132
143
|
/**
|
|
133
144
|
* Handle OAuth callback
|
|
134
145
|
*
|
package/dist/auth.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* ============================================================================
|
|
15
15
|
*/
|
|
16
16
|
import { HttpClient, ClientResult } from '@amaster.ai/http-client';
|
|
17
|
-
import {
|
|
17
|
+
import { x as User, R as RefreshTokenResponse, p as RegisterParams, e as LoginResponse, L as LoginParams, c as CodeLoginParams, S as SendCodeParams, w as SuccessResponse, b as CaptchaResponse, n as OAuthProvider, i as MiniProgramLoginParams, h as MiniLoginParams, k as MiniProgramPhoneParams, l as MiniProgramPhoneResponse, g as MiniGetPhoneParams } from './types-CFVDTREm.js';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Authentication Module
|
|
@@ -31,6 +31,7 @@ import { w as User, R as RefreshTokenResponse, o as RegisterParams, e as LoginRe
|
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
33
|
declare const browserNavigation: {
|
|
34
|
+
assign(url: string): void;
|
|
34
35
|
replace(url: string): void;
|
|
35
36
|
};
|
|
36
37
|
interface AuthModuleDeps {
|
|
@@ -41,6 +42,7 @@ interface AuthModuleDeps {
|
|
|
41
42
|
storage: {
|
|
42
43
|
getItem: (key: string) => string | null;
|
|
43
44
|
setItem: (key: string, value: string) => void;
|
|
45
|
+
removeItem: (key: string) => void;
|
|
44
46
|
};
|
|
45
47
|
clearAuth: () => void;
|
|
46
48
|
onRefreshFailure?: (result: ClientResult<RefreshTokenResponse>) => void;
|
|
@@ -129,6 +131,15 @@ declare function createAuthModule(deps: AuthModuleDeps): {
|
|
|
129
131
|
* ```
|
|
130
132
|
*/
|
|
131
133
|
loginWithOAuth(provider: OAuthProvider, redirectUrl?: string): void;
|
|
134
|
+
/**
|
|
135
|
+
* Log in with the Feishu application configured for the current AMaster app.
|
|
136
|
+
* Uses requestAccess inside Feishu and browser OAuth elsewhere.
|
|
137
|
+
*/
|
|
138
|
+
loginWithFeishu(returnUrl?: string): Promise<ClientResult<LoginResponse> | null>;
|
|
139
|
+
/** Submit an existing requestAccess/requestAuthCode code. */
|
|
140
|
+
loginWithFeishuCode(code: string, returnUrl?: string): Promise<ClientResult<LoginResponse>>;
|
|
141
|
+
/** Exchange a short-lived, one-time application OAuth login ticket. */
|
|
142
|
+
exchangeOAuthLoginTicket(ticket: string): Promise<ClientResult<LoginResponse>>;
|
|
132
143
|
/**
|
|
133
144
|
* Handle OAuth callback
|
|
134
145
|
*
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
'use strict';var httpClient=require('@amaster.ai/http-client');var C=class{constructor(){this.events={};}on(e,r){this.events[e]||(this.events[e]=[]),this.events[e].push(r);}off(e,r){this.events[e]&&(this.events[e]=this.events[e].filter(n=>n!==r));}emit(e,...r){this.events[e]&&this.events[e].forEach(n=>{try{n(...r);}catch(a){console.error(`[AuthClient] Error in event handler for "${e}":`,a);}});}removeAllListeners(){this.events={};}};var h={ACCESS_TOKEN:"amaster_access_token",REFRESH_TOKEN:"amaster_refresh_token",USER:"amaster_user"};function Y(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;try{return Function("return this")()}catch{return}}function w(t){return Y()?.[t]}function Q(){let t=w("wx"),e=w("tt");return t?.getStorageSync&&t?.setStorageSync&&t?.removeStorageSync?"wechat-miniprogram":e?.getStorageSync&&e?.setStorageSync&&e?.removeStorageSync?"douyin-miniprogram":typeof window<"u"&&typeof window.localStorage<"u"?"browser":"node"}function L(){switch(Q()){case "wechat-miniprogram":return U(w("wx"),"WeChat");case "douyin-miniprogram":return U(w("tt"),"Douyin");case "browser":return V();case "node":return X()}}function V(){let t=window.localStorage;return {getItem(e){try{return t.getItem(e)}catch(r){return console.error("[AuthClient] Failed to get item from localStorage:",r),null}},setItem(e,r){try{t.setItem(e,r);}catch(n){console.error("[AuthClient] Failed to set item in localStorage:",n);}},removeItem(e){try{t.removeItem(e);}catch(r){console.error("[AuthClient] Failed to remove item from localStorage:",r);}},clear(){try{t.removeItem(h.ACCESS_TOKEN),t.removeItem(h.REFRESH_TOKEN),t.removeItem(h.USER);}catch(e){console.error("[AuthClient] Failed to clear localStorage:",e);}}}}function U(t,e){return {getItem(r){try{return t.getStorageSync(r)||null}catch(n){return console.error(`[AuthClient] Failed to get item from ${e} storage:`,n),null}},setItem(r,n){try{t.setStorageSync(r,n);}catch(a){console.error(`[AuthClient] Failed to set item in ${e} storage:`,a);}},removeItem(r){try{t.removeStorageSync(r);}catch(n){console.error(`[AuthClient] Failed to remove item from ${e} storage:`,n);}},clear(){try{t.removeStorageSync(h.ACCESS_TOKEN),t.removeStorageSync(h.REFRESH_TOKEN),t.removeStorageSync(h.USER);}catch(r){console.error(`[AuthClient] Failed to clear ${e} storage:`,r);}}}}function X(){let t=new Map;return {getItem(e){return t.get(e)??null},setItem(e,r){t.set(e,r);},removeItem(e){t.delete(e);},clear(){t.clear();}}}function Z(t){try{let e=t.split(".");if(e.length!==3)return null;let n=(e[1]||"").replace(/-/g,"+").replace(/_/g,"/");if(typeof atob<"u"){let a=decodeURIComponent(atob(n).split("").map(c=>"%"+("00"+c.charCodeAt(0).toString(16)).slice(-2)).join(""));return JSON.parse(a)}if(typeof Buffer<"u"){let a=Buffer.from(n,"base64").toString("utf-8");return JSON.parse(a)}return null}catch(e){return console.error("[AuthClient] Failed to parse JWT token:",e),null}}var k=class{constructor(){this.refreshTimer=null;this.isRefreshing=false;this.refreshCallback=null;}setRefreshCallback(e){this.refreshCallback=e;}scheduleRefresh(e){this.clearSchedule(),!(e<=0)&&(this.refreshTimer=setTimeout(()=>{this.refresh();},e));}scheduleRefreshFromToken(e,r=300){let n=Z(e);if(!n||!n.exp){console.warn("[AuthClient] Cannot schedule refresh: invalid token or missing exp claim");return}let a=n.exp*1e3,c=Date.now(),m=a-c-r*1e3;m<=0?(console.warn("[AuthClient] Token already expired or expiring soon, refreshing immediately"),this.refresh()):this.scheduleRefresh(m);}async refresh(){if(!this.isRefreshing){if(!this.refreshCallback){console.error("[AuthClient] No refresh callback set");return}this.isRefreshing=true;try{await this.refreshCallback();}catch(e){console.error("[AuthClient] Token refresh failed:",e);}finally{this.isRefreshing=false;}}}clearSchedule(){this.refreshTimer&&(clearTimeout(this.refreshTimer),this.refreshTimer=null);}isCurrentlyRefreshing(){return this.isRefreshing}destroy(){this.clearSchedule(),this.refreshCallback=null,this.isRefreshing=false;}};function I(t){return t&&typeof t=="object"&&("statusCode"in t||"status"in t)&&"data"in t?t.data:t}var E={transformResponse:I,logErrors:true};function re(t){if(t.email)return "email";if(t.username)return "username";if(t.phone)return "phone"}function ne(t){if(t.email)return "email";if(t.phone)return "phone"}function M(t){return t||(httpClient.detectMiniProgramPlatform()??"wechat")}function O(t){return typeof t=="string"?{code:t,platform:M()}:{code:t.code,platform:M(t.platform)}}function x(t,e){return e==="douyin"?`/api/auth/miniprogram/douyin/${t}`:`/api/auth/miniprogram/${t}`}async function oe(t){let e=M(t),r=httpClient.getMiniProgramLogin(e),n=async a=>await new Promise((c,g)=>{let m=false,o=u=>{if(!m){if(m=true,typeof u?.code=="string"&&u.code){c(u.code);return}g(new Error("Mini Program login failed: missing code"));}},s=u=>{m||(m=true,g(new Error(`Mini Program login failed: ${u instanceof Error?u.message:String(u)}`)));};try{let u=a({success:o,fail:s});if(u&&typeof u.then=="function"){u.then(o,s);return}u&&typeof u=="object"&&"code"in u&&o(u);}catch(u){s(u);}});if(typeof r!="function")throw new Error(`Mini Program login API is not available for platform '${e}'`);return {code:await n(r),platform:e}}function se(t){if(typeof t=="string")return O(t);let e="detail"in t&&t.detail&&typeof t.detail=="object"?t.detail:null,r=typeof e?.code=="string"&&e.code?e.code:typeof t.code=="string"&&t.code?t.code:void 0;return r?{code:r,platform:M(t.platform)}:null}function ie(t){let e=new URLSearchParams(t);return e.get("access_token")||e.get("accessToken")}function ae(t){return new URLSearchParams(t).get("user")}function ue(){if(typeof window>"u")return null;try{let t=new URLSearchParams(window.location.search).get("redirect");if(!t)return null;let e=new URL(t,window.location.origin);return e.origin!==window.location.origin?(console.warn("[AuthClient] Ignored cross-origin redirect target:",t),null):`${e.pathname}${e.search}${e.hash}`}catch(t){return console.warn("[AuthClient] Failed to resolve redirect target:",t),null}}var le={replace(t){window.location.replace(t);}};function R(t,e){return e.handled?{...t,redirectHandled:true,redirectTarget:e.target}:t}function S(t){if(!t||typeof window>"u"||window.opener)return {handled:false};let e=ue();return e?(le.replace(e),{handled:true,target:e}):{handled:false}}function _(t){let{http:e,onLoginSuccess:r,onLogout:n,autoRedirectAfterLogin:a,storage:c,clearAuth:g,onRefreshFailure:m}=t;return {async register(o){let s=await e.request({url:"/api/auth/register",method:"post",headers:{"Content-Type":"application/json"},data:o});if(s.data?.user&&s.data?.accessToken){r(s.data.user,s.data.accessToken);let u=S(a);s.data=R(s.data,u);}return s},async login(o){let s=o.loginType||re(o);if(!s)return {data:null,error:{message:"Unable to determine login type. Please provide email, username, or phone.",status:400},status:400};let u={...o,loginType:s},l=await e.request({url:"/api/auth/login",method:"post",headers:{"Content-Type":"application/json"},data:u});if(l.data?.user&&l.data?.accessToken){r(l.data.user,l.data.accessToken);let d=S(a);l.data=R(l.data,d);}return l},async loginWithCode(o){let s=o.loginType||ne(o);if(!s)return {data:null,error:{message:"Unable to determine login type. Please provide email or phone.",status:400},status:400};let u={...o,loginType:s},l=await e.request({url:"/api/auth/login-with-code",method:"post",headers:{"Content-Type":"application/json"},data:u});if(l.data?.user&&l.data?.accessToken){r(l.data.user,l.data.accessToken);let d=S(a);l.data=R(l.data,d);}return l},async sendCode(o){return e.request({url:"/api/auth/send-code",method:"post",headers:{"Content-Type":"application/json"},data:o})},async getCaptcha(){return e.request({url:"/api/auth/captcha",method:"get"})},loginWithOAuth(o,s){if(typeof window>"u"){console.error("[AuthClient] OAuth login is only available in browser environment");return}let u=s?`/api/auth/oauth/${o}?redirect_url=${encodeURIComponent(s)}`:`/api/auth/oauth/${o}`;window.location.href=u;},async handleOAuthCallback(){if(typeof window>"u")return {data:null,error:{message:"OAuth callback is only available in browser environment",status:400},status:400};try{let o=window.location.hash.substring(1),s=ie(o),u=ae(o);if(!s)return {data:null,error:{message:"OAuth callback failed: missing access token",status:400},status:400};let l;if(u)l=JSON.parse(decodeURIComponent(u));else {c.setItem(h.ACCESS_TOKEN,s);let p=await e.request({url:"/api/auth/me",method:"get",headers:{Authorization:`Bearer ${s}`}});if(!p.data)return {data:null,error:{message:"OAuth callback failed: unable to fetch user info",status:p.status||500},status:p.status||500};l=p.data;}if(r(l,s),window.history&&window.history.replaceState){let p=window.location.pathname+window.location.search;window.history.replaceState(null,"",p);}else window.location.hash="";let d=S(a);return {data:R({user:l,accessToken:s},d),error:null,status:200}}catch(o){return {data:null,error:{message:`OAuth callback failed: ${o instanceof Error?o.message:String(o)}`,status:400},status:400}}},async loginWithMiniProgram(o){let{code:s,platform:u}=O(o),l=await e.request({url:x("login",u),method:"post",headers:{"Content-Type":"application/json"},data:{code:s}});if(l.data?.user&&l.data?.accessToken){r(l.data.user,l.data.accessToken);let d=S(a);l.data=R(l.data,d);}return l},async miniLogin(o={}){try{let s=await oe(o.platform);return await this.loginWithMiniProgram(s)}catch(s){return {data:null,error:{message:s instanceof Error?s.message:String(s),status:400},status:400}}},async getMiniProgramPhoneNumber(o){let{code:s,platform:u}=O(o),l=c.getItem(h.ACCESS_TOKEN);return l?e.request({url:x("phone",u),method:"post",headers:{"Content-Type":"application/json",Authorization:`Bearer ${l}`},data:{code:s}}):{data:null,error:{message:"Not authenticated",status:401},status:401}},async miniGetPhone(o){let s=se(o);return s?this.getMiniProgramPhoneNumber(s):{data:null,error:{message:"Unable to resolve mini-program phone code from input",status:400},status:400}},async logout(){let o=c.getItem("amaster_access_token"),s=await e.request({url:"/api/auth/logout",method:"post",headers:o?{Authorization:`Bearer ${o}`}:void 0});return g(),n(),s},async refreshToken(){let o=await e.request({url:"/api/auth/refresh",method:"post"});return o.data?.accessToken?c.setItem("amaster_access_token",o.data.accessToken):(o.status===401||o.status===403)&&m?.(o),o}}}function H(t){let{getCurrentUser:e}=t;return {hasRole(r){let n=e();return n?.isSuperAdmin?true:!n||!n.roles?false:n.roles.includes(r)},hasPermission(r,n){let a=e();if(a?.isSuperAdmin)return true;if(!a||!a.permissions)return false;let c=`${r}.${n}`;return a.permissions.includes(c)},hasAnyPermission(r){return r.some(({resource:n,action:a})=>this.hasPermission(n,a))},hasAllPermissions(r){return r.every(({resource:n,action:a})=>this.hasPermission(n,a))}}}function $(t){let{http:e,storage:r,onUserUpdate:n,onAuthFailure:a}=t;return {async getMe(){let c=r.getItem("amaster_access_token");if(!c)return {data:null,error:{message:"Not authenticated",status:401},status:401};let g=await e.request({url:"/api/auth/me",method:"get",headers:{Authorization:`Bearer ${c}`}});return g.data?n(g.data):(g.status===401||g.status===403)&&a?.(g),g},async updateMe(c){let g=r.getItem("amaster_access_token");if(!g)return {data:null,error:{message:"Not authenticated",status:401},status:401};let m=await e.request({url:"/api/auth/me",method:"put",headers:{Authorization:`Bearer ${g}`,"Content-Type":"application/json"},data:c});return m.data&&n(m.data),m},async changePassword(c){let g=r.getItem("amaster_access_token");return g?e.request({url:"/api/auth/change-password",method:"post",headers:{Authorization:`Bearer ${g}`,"Content-Type":"application/json"},data:c}):{data:null,error:{message:"Not authenticated",status:401},status:401}}}}function N(t){let{http:e,storage:r}=t;return {async getOAuthBindings(){let n=r.getItem("amaster_access_token");return n?e.request({url:"/api/auth/oauth-bindings",method:"get",headers:{Authorization:`Bearer ${n}`}}):{data:null,error:{message:"Not authenticated",status:401},status:401}},bindOAuth(n){if(typeof window>"u"){console.error("[AuthClient] OAuth binding is only available in browser environment");return}window.location.href=`/api/auth/oauth/${n}/bind`;},async unbindOAuth(n){let a=r.getItem("amaster_access_token");return a?e.request({url:`/api/auth/oauth/${n}/unbind`,method:"delete",headers:{Authorization:`Bearer ${a}`}}):{data:null,error:{message:"Not authenticated",status:401},status:401}}}}function F(t){let{http:e,storage:r}=t;return {async getSession(){let n=r.getItem("amaster_access_token");return n?e.request({url:"/api/auth/sessions/current",method:"get",headers:{Authorization:`Bearer ${n}`}}):{data:null,error:{message:"Not authenticated",status:401},status:401}},async getSessions(){let n=r.getItem("amaster_access_token");return n?e.request({url:"/api/auth/sessions",method:"get",headers:{Authorization:`Bearer ${n}`}}):{data:null,error:{message:"Not authenticated",status:401},status:401}},async revokeSession(n){let a=r.getItem("amaster_access_token");return a?n?e.request({url:`/api/auth/sessions/${n}`,method:"delete",headers:{Authorization:`Bearer ${a}`}}):{data:null,error:{message:"Session ID is required",status:400},status:400}:{data:null,error:{message:"Not authenticated",status:401},status:401}},async revokeAllSessions(){let n=r.getItem("amaster_access_token");return n?e.request({url:"/api/auth/sessions",method:"delete",headers:{Authorization:`Bearer ${n}`}}):{data:null,error:{message:"Not authenticated",status:401},status:401}}}}function ge(t={},e){let{baseURL:r,headers:n,onTokenExpired:a,onUnauthorized:c,autoHandleOAuthCallback:g=true,autoRedirectAfterLogin:m=true,runtime:o}=t;o&&httpClient.setMiniProgramRuntime(o);let s=e||httpClient.createHttpClient({...E,baseURL:r,headers:n,runtime:o}),l=300,d=L(),p=new C,A=new k,P=null,v=false;try{let i=d.getItem(h.USER);i&&(P=JSON.parse(i));}catch(i){console.error("[AuthClient] Failed to load user from storage:",i);}let y;function T(i,f){v||(v=true,b(),i==="tokenExpired"&&(p.emit("tokenExpired",f?.error),a?.()),p.emit("unauthorized",f?.error),p.emit("logout"));}A.setRefreshCallback(async()=>{let i=await y.refreshToken();if(i.data){if((await y.getMe()).error)return;p.emit("tokenRefreshed",i.data.accessToken);}else T("tokenExpired",i);});function G(i,f){v=false,d.setItem(h.ACCESS_TOKEN,f),d.setItem(h.USER,JSON.stringify(i)),P=i,A.scheduleRefreshFromToken(f,l),p.emit("login",i);}function q(i){P=i,d.setItem(h.USER,JSON.stringify(i));}function B(){p.emit("logout");}function b(){d.clear(),P=null,A.clearSchedule();}function z(){return P}let K=_({http:s,onLoginSuccess:G,onLogout:B,autoRedirectAfterLogin:m,storage:d,clearAuth:b,onRefreshFailure:i=>T("tokenExpired",i)}),j=H({getCurrentUser:z}),D=$({http:s,storage:d,onUserUpdate:q,onAuthFailure:i=>T("unauthorized",i)}),J=N({http:s,storage:d}),W=F({http:s,storage:d});if(y={...K,...j,...D,...J,...W,on(i,f){p.on(i,f);},off(i,f){p.off(i,f);},isAuthenticated(){return !!d.getItem(h.ACCESS_TOKEN)},getAccessToken(){return d.getItem(h.ACCESS_TOKEN)},setAccessToken(i){v=false,d.setItem(h.ACCESS_TOKEN,i),A.scheduleRefreshFromToken(i,l);},clearAuth:b},y.on("unauthorized",()=>{c?.();}),y.isAuthenticated()&&y.getMe().then(i=>{i.error&&console.warn("[AuthClient] Failed to sync user info on init:",i.error);}).catch(i=>{console.warn("[AuthClient] Failed to sync user info on init:",i);}),g&&typeof window<"u"){let i=window.location.hash;i&&(i.includes("access_token")||i.includes("accessToken"))&&y.handleOAuthCallback().then(f=>{f.error&&console.error("[AuthClient] Auto OAuth callback failed:",f.error);}).catch(f=>{console.error("[AuthClient] Auto OAuth callback error:",f);});}return y}exports.createAuthClient=ge;exports.defaultHttpClientOptions=E;exports.transformAmasterResponse=I;//# sourceMappingURL=index.cjs.map
|
|
1
|
+
'use strict';var httpClient=require('@amaster.ai/http-client');var T=class{constructor(){this.events={};}on(e,r){this.events[e]||(this.events[e]=[]),this.events[e].push(r);}off(e,r){this.events[e]&&(this.events[e]=this.events[e].filter(o=>o!==r));}emit(e,...r){this.events[e]&&this.events[e].forEach(o=>{try{o(...r);}catch(i){console.error(`[AuthClient] Error in event handler for "${e}":`,i);}});}removeAllListeners(){this.events={};}};var h={ACCESS_TOKEN:"amaster_access_token",REFRESH_TOKEN:"amaster_refresh_token",USER:"amaster_user"};function oe(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;try{return Function("return this")()}catch{return}}function M(t){return oe()?.[t]}function se(){let t=M("wx"),e=M("tt");return t?.getStorageSync&&t?.setStorageSync&&t?.removeStorageSync?"wechat-miniprogram":e?.getStorageSync&&e?.setStorageSync&&e?.removeStorageSync?"douyin-miniprogram":typeof window<"u"&&typeof window.localStorage<"u"?"browser":"node"}function _(){switch(se()){case "wechat-miniprogram":return F(M("wx"),"WeChat");case "douyin-miniprogram":return F(M("tt"),"Douyin");case "browser":return ie();case "node":return ae()}}function ie(){let t=window.localStorage;return {getItem(e){try{return t.getItem(e)}catch(r){return console.error("[AuthClient] Failed to get item from localStorage:",r),null}},setItem(e,r){try{t.setItem(e,r);}catch(o){console.error("[AuthClient] Failed to set item in localStorage:",o);}},removeItem(e){try{t.removeItem(e);}catch(r){console.error("[AuthClient] Failed to remove item from localStorage:",r);}},clear(){try{t.removeItem(h.ACCESS_TOKEN),t.removeItem(h.REFRESH_TOKEN),t.removeItem(h.USER);}catch(e){console.error("[AuthClient] Failed to clear localStorage:",e);}}}}function F(t,e){return {getItem(r){try{return t.getStorageSync(r)||null}catch(o){return console.error(`[AuthClient] Failed to get item from ${e} storage:`,o),null}},setItem(r,o){try{t.setStorageSync(r,o);}catch(i){console.error(`[AuthClient] Failed to set item in ${e} storage:`,i);}},removeItem(r){try{t.removeStorageSync(r);}catch(o){console.error(`[AuthClient] Failed to remove item from ${e} storage:`,o);}},clear(){try{t.removeStorageSync(h.ACCESS_TOKEN),t.removeStorageSync(h.REFRESH_TOKEN),t.removeStorageSync(h.USER);}catch(r){console.error(`[AuthClient] Failed to clear ${e} storage:`,r);}}}}function ae(){let t=new Map;return {getItem(e){return t.get(e)??null},setItem(e,r){t.set(e,r);},removeItem(e){t.delete(e);},clear(){t.clear();}}}function ue(t){try{let e=t.split(".");if(e.length!==3)return null;let o=(e[1]||"").replace(/-/g,"+").replace(/_/g,"/");if(typeof atob<"u"){let i=decodeURIComponent(atob(o).split("").map(c=>"%"+("00"+c.charCodeAt(0).toString(16)).slice(-2)).join(""));return JSON.parse(i)}if(typeof Buffer<"u"){let i=Buffer.from(o,"base64").toString("utf-8");return JSON.parse(i)}return null}catch(e){return console.error("[AuthClient] Failed to parse JWT token:",e),null}}var b=class{constructor(){this.refreshTimer=null;this.isRefreshing=false;this.refreshCallback=null;}setRefreshCallback(e){this.refreshCallback=e;}scheduleRefresh(e){this.clearSchedule(),!(e<=0)&&(this.refreshTimer=setTimeout(()=>{this.refresh();},e));}scheduleRefreshFromToken(e,r=300){let o=ue(e);if(!o||!o.exp){console.warn("[AuthClient] Cannot schedule refresh: invalid token or missing exp claim");return}let i=o.exp*1e3,c=Date.now(),p=i-c-r*1e3;p<=0?(console.warn("[AuthClient] Token already expired or expiring soon, refreshing immediately"),this.refresh()):this.scheduleRefresh(p);}async refresh(){if(!this.isRefreshing){if(!this.refreshCallback){console.error("[AuthClient] No refresh callback set");return}this.isRefreshing=true;try{await this.refreshCallback();}catch(e){console.error("[AuthClient] Token refresh failed:",e);}finally{this.isRefreshing=false;}}}clearSchedule(){this.refreshTimer&&(clearTimeout(this.refreshTimer),this.refreshTimer=null);}isCurrentlyRefreshing(){return this.isRefreshing}destroy(){this.clearSchedule(),this.refreshCallback=null,this.isRefreshing=false;}};function x(t){return t&&typeof t=="object"&&("statusCode"in t||"status"in t)&&"data"in t?t.data:t}var U={transformResponse:x,logErrors:true};var le="https://lf-scm-cn.feishucdn.com/lark/op/h5-js-sdk-1.5.44.js",H="amaster-feishu-h5-sdk";function E(){if(!(typeof window>"u"))return window.tt}function $(){return typeof navigator>"u"?false:!!E()||/Feishu|Lark/i.test(navigator.userAgent||"")}async function ce(){let t=E();if(t)return t;if(typeof document>"u")throw new Error("Feishu H5 SDK is only available in a browser environment");let e=document.getElementById(H);e||(e=document.createElement("script"),e.id=H,e.src=le,e.async=true,document.head.appendChild(e)),await new Promise((o,i)=>{if(E()){o();return}e?.addEventListener("load",()=>o(),{once:true}),e?.addEventListener("error",()=>i(new Error("Failed to load Feishu H5 SDK")),{once:true});});let r=E();if(!r)throw new Error("Feishu H5 SDK loaded without exposing the tt bridge");return r}function N(t){return t.errString||t.message||`Feishu authorization failed${t.errno?` (${t.errno})`:""}`}function q(t,e){return typeof t.requestAuthCode!="function"?Promise.reject(new Error("The current Feishu client does not support requestAuthCode")):new Promise((r,o)=>{t.requestAuthCode?.({appId:e,success:i=>{i.code?r(i.code):o(new Error("Feishu requestAuthCode returned no code"));},fail:i=>o(new Error(N(i)))});})}async function B(t){let e=await ce();return typeof e.requestAccess!="function"?q(e,t):new Promise((r,o)=>{e.requestAccess?.({appID:t,scopeList:[],success:i=>{i.code?r(i.code):o(new Error("Feishu requestAccess returned no code"));},fail:i=>{if(i.errno===103){q(e,t).then(r,o);return}o(new Error(N(i)));}});})}function he(t){if(t.email)return "email";if(t.username)return "username";if(t.phone)return "phone"}function me(t){if(t.email)return "email";if(t.phone)return "phone"}function L(t){return t||(httpClient.detectMiniProgramPlatform()??"wechat")}function I(t){return typeof t=="string"?{code:t,platform:L()}:{code:t.code,platform:L(t.platform)}}function G(t,e){return e==="douyin"?`/api/auth/miniprogram/douyin/${t}`:`/api/auth/miniprogram/${t}`}async function pe(t){let e=L(t),r=httpClient.getMiniProgramLogin(e),o=async i=>await new Promise((c,m)=>{let p=false,S=g=>{if(!p){if(p=true,typeof g?.code=="string"&&g.code){c(g.code);return}m(new Error("Mini Program login failed: missing code"));}},P=g=>{p||(p=true,m(new Error(`Mini Program login failed: ${g instanceof Error?g.message:String(g)}`)));};try{let g=i({success:S,fail:P});if(g&&typeof g.then=="function"){g.then(S,P);return}g&&typeof g=="object"&&"code"in g&&S(g);}catch(g){P(g);}});if(typeof r!="function")throw new Error(`Mini Program login API is not available for platform '${e}'`);return {code:await o(r),platform:e}}function fe(t){if(typeof t=="string")return I(t);let e="detail"in t&&t.detail&&typeof t.detail=="object"?t.detail:null,r=typeof e?.code=="string"&&e.code?e.code:typeof t.code=="string"&&t.code?t.code:void 0;return r?{code:r,platform:L(t.platform)}:null}function ye(t){let e=new URLSearchParams(t);return e.get("access_token")||e.get("accessToken")}function Pe(t){return new URLSearchParams(t).get("user")}function K(t){if(typeof window>"u")return null;try{let e=t||new URLSearchParams(window.location.search).get("redirect");if(!e)return null;let r=new URL(e,window.location.origin);return r.origin!==window.location.origin?(console.warn("[AuthClient] Ignored cross-origin redirect target:",e),null):`${r.pathname}${r.search}${r.hash}`}catch(e){return console.warn("[AuthClient] Failed to resolve redirect target:",e),null}}var D={assign(t){window.location.assign(t);},replace(t){window.location.replace(t);}};function A(t,e){return e.handled?{...t,redirectHandled:true,redirectTarget:e.target}:t}function v(t,e){if(!t||typeof window>"u"||window.opener)return {handled:false};let r=K(e);return r?(D.replace(r),{handled:true,target:r}):{handled:false}}function z(t){let{http:e,onLoginSuccess:r,onLogout:o,autoRedirectAfterLogin:i,storage:c,clearAuth:m,onRefreshFailure:p}=t,S=async s=>{let n=await e.request({url:"/api/auth/oauth/ticket",method:"post",headers:{"Content-Type":"application/json"},data:{ticket:s}});if(!n.data?.accessToken)return {data:null,error:n.error||{message:"OAuth login ticket is invalid, expired, or already used",status:n.status||400},status:n.status||400};let a=c.getItem(h.ACCESS_TOKEN),u=n.data.accessToken;c.setItem(h.ACCESS_TOKEN,u);let d=await e.request({url:"/api/auth/me",method:"get",headers:{Authorization:`Bearer ${u}`}});if(!d.data)return a?c.setItem(h.ACCESS_TOKEN,a):c.removeItem(h.ACCESS_TOKEN),{data:null,error:d.error||{message:"OAuth login succeeded but user information could not be loaded",status:d.status||500},status:d.status||500};r(d.data,u);let C=v(i,n.data.returnUrl);return {data:A({user:d.data,accessToken:u},C),error:null,status:200}},P=s=>{if(typeof window>"u")return;let n=K(s)||"/",a=new URLSearchParams({return_url:n,callback_url:"/auth/callback"});D.assign(`/api/auth/oauth/feishu?${a.toString()}`);},g=async(s,n)=>{let a=await e.request({url:"/api/auth/oauth/feishu/code",method:"post",headers:{"Content-Type":"application/json"},data:{code:s}});if(a.data?.user&&a.data?.accessToken){r(a.data.user,a.data.accessToken);let u=v(i,n);a.data=A(a.data,u);}return a};return {async register(s){let n=await e.request({url:"/api/auth/register",method:"post",headers:{"Content-Type":"application/json"},data:s});if(n.data?.user&&n.data?.accessToken){r(n.data.user,n.data.accessToken);let a=v(i);n.data=A(n.data,a);}return n},async login(s){let n=s.loginType||he(s);if(!n)return {data:null,error:{message:"Unable to determine login type. Please provide email, username, or phone.",status:400},status:400};let a={...s,loginType:n},u=await e.request({url:"/api/auth/login",method:"post",headers:{"Content-Type":"application/json"},data:a});if(u.data?.user&&u.data?.accessToken){r(u.data.user,u.data.accessToken);let d=v(i);u.data=A(u.data,d);}return u},async loginWithCode(s){let n=s.loginType||me(s);if(!n)return {data:null,error:{message:"Unable to determine login type. Please provide email or phone.",status:400},status:400};let a={...s,loginType:n},u=await e.request({url:"/api/auth/login-with-code",method:"post",headers:{"Content-Type":"application/json"},data:a});if(u.data?.user&&u.data?.accessToken){r(u.data.user,u.data.accessToken);let d=v(i);u.data=A(u.data,d);}return u},async sendCode(s){return e.request({url:"/api/auth/send-code",method:"post",headers:{"Content-Type":"application/json"},data:s})},async getCaptcha(){return e.request({url:"/api/auth/captcha",method:"get"})},loginWithOAuth(s,n){if(typeof window>"u"){console.error("[AuthClient] OAuth login is only available in browser environment");return}if(s==="feishu"){P(n);return}let a=n?`/api/auth/oauth/${s}?redirect_url=${encodeURIComponent(n)}`:`/api/auth/oauth/${s}`;window.location.href=a;},async loginWithFeishu(s){if(typeof window>"u")return {data:null,error:{message:"Feishu login is only available in a browser environment",status:400},status:400};if(!$())return P(s),null;let n=await e.request({url:"/api/auth/oauth/feishu/config",method:"get"});if(!n.data?.enabled||!n.data.appId)return {data:null,error:n.error||{message:"Feishu login is not configured for this application",status:n.status||400},status:n.status||400};try{let a=await B(n.data.appId);return await g(a,s)}catch(a){return {data:null,error:{message:a instanceof Error?a.message:String(a),status:400},status:400}}},async loginWithFeishuCode(s,n){return g(s,n)},async exchangeOAuthLoginTicket(s){return S(s)},async handleOAuthCallback(){if(typeof window>"u")return {data:null,error:{message:"OAuth callback is only available in browser environment",status:400},status:400};try{let s=new URLSearchParams(window.location.search),n=s.get("oauth_error");if(n)return {data:null,error:{message:s.get("error_description")||`OAuth callback failed: ${n}`,status:400},status:400};let a=s.get("login_ticket");if(a){s.delete("login_ticket");let R=s.toString();return window.history.replaceState(null,"",`${window.location.pathname}${R?`?${R}`:""}${window.location.hash}`),S(a)}let u=window.location.hash.substring(1),d=ye(u),C=Pe(u);if(!d)return {data:null,error:{message:"OAuth callback failed: missing access token",status:400},status:400};let f;if(C)f=JSON.parse(decodeURIComponent(C));else {c.setItem(h.ACCESS_TOKEN,d);let R=await e.request({url:"/api/auth/me",method:"get",headers:{Authorization:`Bearer ${d}`}});if(!R.data)return {data:null,error:{message:"OAuth callback failed: unable to fetch user info",status:R.status||500},status:R.status||500};f=R.data;}if(r(f,d),window.history&&window.history.replaceState){let R=window.location.pathname+window.location.search;window.history.replaceState(null,"",R);}else window.location.hash="";let w=v(i);return {data:A({user:f,accessToken:d},w),error:null,status:200}}catch(s){return {data:null,error:{message:`OAuth callback failed: ${s instanceof Error?s.message:String(s)}`,status:400},status:400}}},async loginWithMiniProgram(s){let{code:n,platform:a}=I(s),u=await e.request({url:G("login",a),method:"post",headers:{"Content-Type":"application/json"},data:{code:n}});if(u.data?.user&&u.data?.accessToken){r(u.data.user,u.data.accessToken);let d=v(i);u.data=A(u.data,d);}return u},async miniLogin(s={}){try{let n=await pe(s.platform);return await this.loginWithMiniProgram(n)}catch(n){return {data:null,error:{message:n instanceof Error?n.message:String(n),status:400},status:400}}},async getMiniProgramPhoneNumber(s){let{code:n,platform:a}=I(s),u=c.getItem(h.ACCESS_TOKEN);return u?e.request({url:G("phone",a),method:"post",headers:{"Content-Type":"application/json",Authorization:`Bearer ${u}`},data:{code:n}}):{data:null,error:{message:"Not authenticated",status:401},status:401}},async miniGetPhone(s){let n=fe(s);return n?this.getMiniProgramPhoneNumber(n):{data:null,error:{message:"Unable to resolve mini-program phone code from input",status:400},status:400}},async logout(){let s=c.getItem("amaster_access_token"),n=await e.request({url:"/api/auth/logout",method:"post",headers:s?{Authorization:`Bearer ${s}`}:void 0});return m(),o(),n},async refreshToken(){let s=await e.request({url:"/api/auth/refresh",method:"post"});return s.data?.accessToken?c.setItem("amaster_access_token",s.data.accessToken):(s.status===401||s.status===403)&&p?.(s),s}}}function j(t){let{getCurrentUser:e}=t;return {hasRole(r){let o=e();return o?.isSuperAdmin?true:!o||!o.roles?false:o.roles.includes(r)},hasPermission(r,o){let i=e();if(i?.isSuperAdmin)return true;if(!i||!i.permissions)return false;let c=`${r}.${o}`;return i.permissions.includes(c)},hasAnyPermission(r){return r.some(({resource:o,action:i})=>this.hasPermission(o,i))},hasAllPermissions(r){return r.every(({resource:o,action:i})=>this.hasPermission(o,i))}}}function J(t){let{http:e,storage:r,onUserUpdate:o,onAuthFailure:i}=t;return {async getMe(){let c=r.getItem("amaster_access_token");if(!c)return {data:null,error:{message:"Not authenticated",status:401},status:401};let m=await e.request({url:"/api/auth/me",method:"get",headers:{Authorization:`Bearer ${c}`}});return m.data?o(m.data):(m.status===401||m.status===403)&&i?.(m),m},async updateMe(c){let m=r.getItem("amaster_access_token");if(!m)return {data:null,error:{message:"Not authenticated",status:401},status:401};let p=await e.request({url:"/api/auth/me",method:"put",headers:{Authorization:`Bearer ${m}`,"Content-Type":"application/json"},data:c});return p.data&&o(p.data),p},async changePassword(c){let m=r.getItem("amaster_access_token");return m?e.request({url:"/api/auth/change-password",method:"post",headers:{Authorization:`Bearer ${m}`,"Content-Type":"application/json"},data:c}):{data:null,error:{message:"Not authenticated",status:401},status:401}}}}function W(t){let{http:e,storage:r}=t;return {async getOAuthBindings(){let o=r.getItem("amaster_access_token");return o?e.request({url:"/api/auth/oauth-bindings",method:"get",headers:{Authorization:`Bearer ${o}`}}):{data:null,error:{message:"Not authenticated",status:401},status:401}},bindOAuth(o){if(typeof window>"u"){console.error("[AuthClient] OAuth binding is only available in browser environment");return}window.location.href=`/api/auth/oauth/${o}/bind`;},async unbindOAuth(o){let i=r.getItem("amaster_access_token");return i?e.request({url:`/api/auth/oauth/${o}/unbind`,method:"delete",headers:{Authorization:`Bearer ${i}`}}):{data:null,error:{message:"Not authenticated",status:401},status:401}}}}function Y(t){let{http:e,storage:r}=t;return {async getSession(){let o=r.getItem("amaster_access_token");return o?e.request({url:"/api/auth/sessions/current",method:"get",headers:{Authorization:`Bearer ${o}`}}):{data:null,error:{message:"Not authenticated",status:401},status:401}},async getSessions(){let o=r.getItem("amaster_access_token");return o?e.request({url:"/api/auth/sessions",method:"get",headers:{Authorization:`Bearer ${o}`}}):{data:null,error:{message:"Not authenticated",status:401},status:401}},async revokeSession(o){let i=r.getItem("amaster_access_token");return i?o?e.request({url:`/api/auth/sessions/${o}`,method:"delete",headers:{Authorization:`Bearer ${i}`}}):{data:null,error:{message:"Session ID is required",status:400},status:400}:{data:null,error:{message:"Not authenticated",status:401},status:401}},async revokeAllSessions(){let o=r.getItem("amaster_access_token");return o?e.request({url:"/api/auth/sessions",method:"delete",headers:{Authorization:`Bearer ${o}`}}):{data:null,error:{message:"Not authenticated",status:401},status:401}}}}function Ce(t={},e){let{baseURL:r,headers:o,onTokenExpired:i,onUnauthorized:c,autoHandleOAuthCallback:m=true,autoRedirectAfterLogin:p=true,runtime:S}=t;S&&httpClient.setMiniProgramRuntime(S);let P=e||httpClient.createHttpClient({...U,baseURL:r,headers:o,runtime:S}),s=300,n=_(),a=new T,u=new b,d=null,C=false;try{let l=n.getItem(h.USER);l&&(d=JSON.parse(l));}catch(l){console.error("[AuthClient] Failed to load user from storage:",l);}let f;function w(l,y){C||(C=true,O(),l==="tokenExpired"&&(a.emit("tokenExpired",y?.error),i?.()),a.emit("unauthorized",y?.error),a.emit("logout"));}u.setRefreshCallback(async()=>{let l=await f.refreshToken();if(l.data){if((await f.getMe()).error)return;a.emit("tokenRefreshed",l.data.accessToken);}else w("tokenExpired",l);});function R(l,y){C=false,n.setItem(h.ACCESS_TOKEN,y),n.setItem(h.USER,JSON.stringify(l)),d=l,u.scheduleRefreshFromToken(y,s),a.emit("login",l);}function Q(l){d=l,n.setItem(h.USER,JSON.stringify(l));}function V(){a.emit("logout");}function O(){n.clear(),d=null,u.clearSchedule();}function X(){return d}let Z=z({http:P,onLoginSuccess:R,onLogout:V,autoRedirectAfterLogin:p,storage:n,clearAuth:O,onRefreshFailure:l=>w("tokenExpired",l)}),ee=j({getCurrentUser:X}),te=J({http:P,storage:n,onUserUpdate:Q,onAuthFailure:l=>w("unauthorized",l)}),re=W({http:P,storage:n}),ne=Y({http:P,storage:n});if(f={...Z,...ee,...te,...re,...ne,on(l,y){a.on(l,y);},off(l,y){a.off(l,y);},isAuthenticated(){return !!n.getItem(h.ACCESS_TOKEN)},getAccessToken(){return n.getItem(h.ACCESS_TOKEN)},setAccessToken(l){C=false,n.setItem(h.ACCESS_TOKEN,l),u.scheduleRefreshFromToken(l,s);},clearAuth:O},f.on("unauthorized",()=>{c?.();}),f.isAuthenticated()&&f.getMe().then(l=>{l.error&&console.warn("[AuthClient] Failed to sync user info on init:",l.error);}).catch(l=>{console.warn("[AuthClient] Failed to sync user info on init:",l);}),m&&typeof window<"u"){let l=window.location.hash,y=new URLSearchParams(window.location.search);(y.has("login_ticket")||y.has("oauth_error")||l&&(l.includes("access_token")||l.includes("accessToken")))&&f.handleOAuthCallback().then(k=>{k.error&&console.error("[AuthClient] Auto OAuth callback failed:",k.error);}).catch(k=>{console.error("[AuthClient] Auto OAuth callback error:",k);});}return f}
|
|
2
|
+
exports.createAuthClient=Ce;exports.defaultHttpClientOptions=U;exports.transformAmasterResponse=x;//# sourceMappingURL=index.cjs.map
|
|
2
3
|
//# sourceMappingURL=index.cjs.map
|