@amaster.ai/auth-client 1.0.0-alpha.2
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/LICENSE +21 -0
- package/README.md +633 -0
- package/dist/auth.d.cts +196 -0
- package/dist/auth.d.ts +196 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +69 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/oauth.d.cts +76 -0
- package/dist/oauth.d.ts +76 -0
- package/dist/permissions.d.cts +100 -0
- package/dist/permissions.d.ts +100 -0
- package/dist/sessions.d.cts +96 -0
- package/dist/sessions.d.ts +96 -0
- package/dist/types-BhHE_geU.d.cts +481 -0
- package/dist/types-BhHE_geU.d.ts +481 -0
- package/dist/user.d.cts +82 -0
- package/dist/user.d.ts +82 -0
- package/package.json +72 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* @amaster.ai/auth-client - Type Definitions
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* π€ AI NAVIGATION - Read these files based on your task:
|
|
7
|
+
*
|
|
8
|
+
* 1. Need LOGIN/REGISTER/LOGOUT? β Read: ./auth.d.ts
|
|
9
|
+
* 2. Need PERMISSION checks? β Read: ./permissions.d.ts
|
|
10
|
+
* 3. Need USER profile management? β Read: ./user.d.ts
|
|
11
|
+
* 4. Need OAUTH binding? β Read: ./oauth.d.ts
|
|
12
|
+
* 5. Need SESSION management? β Read: ./sessions.d.ts
|
|
13
|
+
*
|
|
14
|
+
* ============================================================================
|
|
15
|
+
*/
|
|
16
|
+
import { HttpClient, ClientResult } from '@amaster.ai/http-client';
|
|
17
|
+
import { o as Session, p as SuccessResponse, k as RevokeAllSessionsResponse } from './types-BhHE_geU.cjs';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Sessions Module
|
|
21
|
+
*
|
|
22
|
+
* @module sessions
|
|
23
|
+
* @category Sessions
|
|
24
|
+
*
|
|
25
|
+
* Handles multi-device session management:
|
|
26
|
+
* - View all active sessions
|
|
27
|
+
* - Revoke specific session
|
|
28
|
+
* - Revoke all other sessions
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
interface SessionsModuleDeps {
|
|
32
|
+
http: HttpClient;
|
|
33
|
+
storage: {
|
|
34
|
+
getItem: (key: string) => string | null;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
declare function createSessionsModule(deps: SessionsModuleDeps): {
|
|
38
|
+
/**
|
|
39
|
+
* Get current session information
|
|
40
|
+
*
|
|
41
|
+
* @category Sessions
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const result = await sessions.getSession();
|
|
45
|
+
* if (result.data) {
|
|
46
|
+
* console.log("Session ID:", result.data.id);
|
|
47
|
+
* console.log("Device:", result.data.sessionName);
|
|
48
|
+
* console.log("IP address:", result.data.ipAddress);
|
|
49
|
+
* console.log("Location:", result.data.location);
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
getSession(): Promise<ClientResult<Session>>;
|
|
54
|
+
/**
|
|
55
|
+
* Get all active sessions for current user
|
|
56
|
+
*
|
|
57
|
+
* @category Sessions
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const result = await sessions.getSessions();
|
|
61
|
+
* if (result.data) {
|
|
62
|
+
* result.data.forEach(session => {
|
|
63
|
+
* const status = session.isCurrent ? "Current" : "Other";
|
|
64
|
+
* console.log(`${session.sessionName} - ${session.ipAddress} - ${status}`);
|
|
65
|
+
* });
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
getSessions(): Promise<ClientResult<Session[]>>;
|
|
70
|
+
/**
|
|
71
|
+
* Revoke a specific session
|
|
72
|
+
*
|
|
73
|
+
* @category Sessions
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* await sessions.revokeSession("session-id-123");
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
revokeSession(sessionId: string): Promise<ClientResult<SuccessResponse>>;
|
|
80
|
+
/**
|
|
81
|
+
* Revoke all sessions except current one
|
|
82
|
+
*
|
|
83
|
+
* @category Sessions
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const result = await sessions.revokeAllSessions();
|
|
87
|
+
* if (result.data) {
|
|
88
|
+
* console.log(`Revoked ${result.data.revokedCount} sessions`);
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
revokeAllSessions(): Promise<ClientResult<RevokeAllSessionsResponse>>;
|
|
93
|
+
};
|
|
94
|
+
type SessionsModule = ReturnType<typeof createSessionsModule>;
|
|
95
|
+
|
|
96
|
+
export { type SessionsModule, type SessionsModuleDeps, createSessionsModule };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* @amaster.ai/auth-client - Type Definitions
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* π€ AI NAVIGATION - Read these files based on your task:
|
|
7
|
+
*
|
|
8
|
+
* 1. Need LOGIN/REGISTER/LOGOUT? β Read: ./auth.d.ts
|
|
9
|
+
* 2. Need PERMISSION checks? β Read: ./permissions.d.ts
|
|
10
|
+
* 3. Need USER profile management? β Read: ./user.d.ts
|
|
11
|
+
* 4. Need OAUTH binding? β Read: ./oauth.d.ts
|
|
12
|
+
* 5. Need SESSION management? β Read: ./sessions.d.ts
|
|
13
|
+
*
|
|
14
|
+
* ============================================================================
|
|
15
|
+
*/
|
|
16
|
+
import { HttpClient, ClientResult } from '@amaster.ai/http-client';
|
|
17
|
+
import { o as Session, p as SuccessResponse, k as RevokeAllSessionsResponse } from './types-BhHE_geU.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Sessions Module
|
|
21
|
+
*
|
|
22
|
+
* @module sessions
|
|
23
|
+
* @category Sessions
|
|
24
|
+
*
|
|
25
|
+
* Handles multi-device session management:
|
|
26
|
+
* - View all active sessions
|
|
27
|
+
* - Revoke specific session
|
|
28
|
+
* - Revoke all other sessions
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
interface SessionsModuleDeps {
|
|
32
|
+
http: HttpClient;
|
|
33
|
+
storage: {
|
|
34
|
+
getItem: (key: string) => string | null;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
declare function createSessionsModule(deps: SessionsModuleDeps): {
|
|
38
|
+
/**
|
|
39
|
+
* Get current session information
|
|
40
|
+
*
|
|
41
|
+
* @category Sessions
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const result = await sessions.getSession();
|
|
45
|
+
* if (result.data) {
|
|
46
|
+
* console.log("Session ID:", result.data.id);
|
|
47
|
+
* console.log("Device:", result.data.sessionName);
|
|
48
|
+
* console.log("IP address:", result.data.ipAddress);
|
|
49
|
+
* console.log("Location:", result.data.location);
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
getSession(): Promise<ClientResult<Session>>;
|
|
54
|
+
/**
|
|
55
|
+
* Get all active sessions for current user
|
|
56
|
+
*
|
|
57
|
+
* @category Sessions
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const result = await sessions.getSessions();
|
|
61
|
+
* if (result.data) {
|
|
62
|
+
* result.data.forEach(session => {
|
|
63
|
+
* const status = session.isCurrent ? "Current" : "Other";
|
|
64
|
+
* console.log(`${session.sessionName} - ${session.ipAddress} - ${status}`);
|
|
65
|
+
* });
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
getSessions(): Promise<ClientResult<Session[]>>;
|
|
70
|
+
/**
|
|
71
|
+
* Revoke a specific session
|
|
72
|
+
*
|
|
73
|
+
* @category Sessions
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* await sessions.revokeSession("session-id-123");
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
revokeSession(sessionId: string): Promise<ClientResult<SuccessResponse>>;
|
|
80
|
+
/**
|
|
81
|
+
* Revoke all sessions except current one
|
|
82
|
+
*
|
|
83
|
+
* @category Sessions
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const result = await sessions.revokeAllSessions();
|
|
87
|
+
* if (result.data) {
|
|
88
|
+
* console.log(`Revoked ${result.data.revokedCount} sessions`);
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
revokeAllSessions(): Promise<ClientResult<RevokeAllSessionsResponse>>;
|
|
93
|
+
};
|
|
94
|
+
type SessionsModule = ReturnType<typeof createSessionsModule>;
|
|
95
|
+
|
|
96
|
+
export { type SessionsModule, type SessionsModuleDeps, createSessionsModule };
|
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* @amaster.ai/auth-client - Type Definitions
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* π€ AI NAVIGATION - Read these files based on your task:
|
|
7
|
+
*
|
|
8
|
+
* 1. Need LOGIN/REGISTER/LOGOUT? β Read: ./auth.d.ts
|
|
9
|
+
* 2. Need PERMISSION checks? β Read: ./permissions.d.ts
|
|
10
|
+
* 3. Need USER profile management? β Read: ./user.d.ts
|
|
11
|
+
* 4. Need OAUTH binding? β Read: ./oauth.d.ts
|
|
12
|
+
* 5. Need SESSION management? β Read: ./sessions.d.ts
|
|
13
|
+
*
|
|
14
|
+
* ============================================================================
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Authentication SDK Types
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Authentication client configuration options
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* Minimal configuration (recommended):
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const authClient = createAuthClient();
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* With callbacks:
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const authClient = createAuthClient({
|
|
32
|
+
* onTokenExpired: () => window.location.href = "/login",
|
|
33
|
+
* onUnauthorized: () => alert("Session expired"),
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* With custom base URL:
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const authClient = createAuthClient({
|
|
41
|
+
* baseURL: "https://api.example.com",
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
interface AuthClientOptions {
|
|
46
|
+
/**
|
|
47
|
+
* API base URL (defaults to window.location.origin)
|
|
48
|
+
* @example "https://api.example.com"
|
|
49
|
+
*/
|
|
50
|
+
baseURL?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Default headers to include in all requests
|
|
53
|
+
* Useful for adding tenant IDs, API keys, or other common headers
|
|
54
|
+
* @example { "x-tenant-id": "tenant123", "x-api-key": "key123" }
|
|
55
|
+
*/
|
|
56
|
+
headers?: Record<string, string>;
|
|
57
|
+
/**
|
|
58
|
+
* Callback when token expires
|
|
59
|
+
* @example () => window.location.href = "/login"
|
|
60
|
+
*/
|
|
61
|
+
onTokenExpired?: () => void;
|
|
62
|
+
/**
|
|
63
|
+
* Callback when server returns 401 Unauthorized
|
|
64
|
+
* @example () => alert("Session expired")
|
|
65
|
+
*/
|
|
66
|
+
onUnauthorized?: () => void;
|
|
67
|
+
/**
|
|
68
|
+
* Automatically handle OAuth callback on initialization
|
|
69
|
+
* When enabled, the client will automatically detect and process OAuth callback URLs with #access_token
|
|
70
|
+
* @default true
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* // Enable auto-handling (default)
|
|
74
|
+
* const authClient = createAuthClient({
|
|
75
|
+
* autoHandleOAuthCallback: true,
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* // Disable if you want to handle OAuth callback manually
|
|
79
|
+
* const authClient = createAuthClient({
|
|
80
|
+
* autoHandleOAuthCallback: false,
|
|
81
|
+
* });
|
|
82
|
+
* await authClient.handleOAuthCallback(); // Call manually when needed
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
autoHandleOAuthCallback?: boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* User information with roles and permissions
|
|
89
|
+
*
|
|
90
|
+
* Note: This is an optimized format for client-side use.
|
|
91
|
+
* - roles: Only role codes (e.g., ["admin", "user"])
|
|
92
|
+
* - permissions: Only permission names (e.g., ["user.read", "user.write"])
|
|
93
|
+
* - dataScopes: Not included
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const user: User = {
|
|
98
|
+
* uid: "123",
|
|
99
|
+
* email: "user@example.com",
|
|
100
|
+
* displayName: "John Doe",
|
|
101
|
+
* roles: ["admin", "user"],
|
|
102
|
+
* permissions: ["user.read", "user.write", "order.read"],
|
|
103
|
+
* // ... other fields
|
|
104
|
+
* };
|
|
105
|
+
*
|
|
106
|
+
* // Check permissions
|
|
107
|
+
* if (user.permissions.includes("user.delete")) {
|
|
108
|
+
* // Can delete users
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
interface User {
|
|
113
|
+
/** Unique user ID */
|
|
114
|
+
uid: string;
|
|
115
|
+
/** Username (null if not set) */
|
|
116
|
+
username: string | null;
|
|
117
|
+
/** Email address (null if not set) */
|
|
118
|
+
email: string | null;
|
|
119
|
+
/** Phone number (null if not set) */
|
|
120
|
+
phone: string | null;
|
|
121
|
+
/** Display name for UI */
|
|
122
|
+
displayName: string | null;
|
|
123
|
+
/** Avatar image URL */
|
|
124
|
+
avatarUrl: string | null;
|
|
125
|
+
/** Whether account is active */
|
|
126
|
+
isActive: boolean;
|
|
127
|
+
/** Whether email is verified */
|
|
128
|
+
emailVerified: boolean;
|
|
129
|
+
/** Whether phone is verified */
|
|
130
|
+
phoneVerified: boolean;
|
|
131
|
+
/** Email verification timestamp */
|
|
132
|
+
emailVerifiedAt: string | null;
|
|
133
|
+
/** Phone verification timestamp */
|
|
134
|
+
phoneVerifiedAt: string | null;
|
|
135
|
+
/**
|
|
136
|
+
* Role codes assigned to user
|
|
137
|
+
* @example ["admin", "user", "manager"]
|
|
138
|
+
*/
|
|
139
|
+
roles: string[];
|
|
140
|
+
/**
|
|
141
|
+
* Permission names granted to user
|
|
142
|
+
* @example ["user:read", "user:write", "order:read"]
|
|
143
|
+
*/
|
|
144
|
+
permissions: string[];
|
|
145
|
+
/** Account creation timestamp */
|
|
146
|
+
createdAt: string;
|
|
147
|
+
/** Last update timestamp */
|
|
148
|
+
updatedAt: string;
|
|
149
|
+
}
|
|
150
|
+
/** Detailed role information (for admin/management use) */
|
|
151
|
+
interface RoleDetail {
|
|
152
|
+
id: number;
|
|
153
|
+
code: string;
|
|
154
|
+
displayName: string;
|
|
155
|
+
description?: string;
|
|
156
|
+
isSystem: boolean;
|
|
157
|
+
}
|
|
158
|
+
/** Detailed permission information (for admin/management use) */
|
|
159
|
+
interface PermissionDetail {
|
|
160
|
+
id: number;
|
|
161
|
+
name: string;
|
|
162
|
+
resource: string;
|
|
163
|
+
action: string;
|
|
164
|
+
description?: string;
|
|
165
|
+
sourceType: "system" | "role" | "direct";
|
|
166
|
+
}
|
|
167
|
+
/** @deprecated Use string[] for roles in User type */
|
|
168
|
+
interface Role {
|
|
169
|
+
id: number;
|
|
170
|
+
code: string;
|
|
171
|
+
displayName: string;
|
|
172
|
+
description?: string;
|
|
173
|
+
isSystem: boolean;
|
|
174
|
+
}
|
|
175
|
+
/** @deprecated Use string[] for permissions in User type */
|
|
176
|
+
interface Permission {
|
|
177
|
+
id: number;
|
|
178
|
+
name: string;
|
|
179
|
+
resource: string;
|
|
180
|
+
action: string;
|
|
181
|
+
description?: string;
|
|
182
|
+
sourceType: "system" | "role" | "direct";
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* User registration parameters
|
|
186
|
+
* At least one of username/email/phone must be provided
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* Register with email:
|
|
190
|
+
* ```typescript
|
|
191
|
+
* const params: RegisterParams = {
|
|
192
|
+
* email: "user@example.com",
|
|
193
|
+
* password: "Password@123",
|
|
194
|
+
* displayName: "John Doe",
|
|
195
|
+
* };
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* Register with captcha:
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const captcha = await authClient.getCaptcha();
|
|
202
|
+
* const userInput = "AB12"; // User enters this
|
|
203
|
+
* const params: RegisterParams = {
|
|
204
|
+
* email: "user@example.com",
|
|
205
|
+
* password: "Password@123",
|
|
206
|
+
* captcha: `${captcha.data.captchaId}:${userInput}`,
|
|
207
|
+
* };
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
interface RegisterParams {
|
|
211
|
+
/** Username (optional, at least one of username/email/phone required) */
|
|
212
|
+
username?: string;
|
|
213
|
+
/** Email address (optional, at least one of username/email/phone required) */
|
|
214
|
+
email?: string;
|
|
215
|
+
/** Phone number (optional, at least one of username/email/phone required) */
|
|
216
|
+
phone?: string;
|
|
217
|
+
/**
|
|
218
|
+
* Password (required)
|
|
219
|
+
* @example "Password@123"
|
|
220
|
+
*/
|
|
221
|
+
password: string;
|
|
222
|
+
/**
|
|
223
|
+
* Display name for UI
|
|
224
|
+
* @example "John Doe"
|
|
225
|
+
*/
|
|
226
|
+
displayName?: string;
|
|
227
|
+
/**
|
|
228
|
+
* Captcha verification (optional)
|
|
229
|
+
* Format: "captchaId:userInput"
|
|
230
|
+
* @example "uuid-123:AB12"
|
|
231
|
+
*/
|
|
232
|
+
captcha?: string;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Login type: username, email, or phone
|
|
236
|
+
*/
|
|
237
|
+
type LoginType = "username" | "email" | "phone";
|
|
238
|
+
/**
|
|
239
|
+
* Login parameters for password-based authentication
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* Login with email (auto-detect loginType):
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const params: LoginParams = {
|
|
245
|
+
* email: "user@example.com",
|
|
246
|
+
* password: "Password@123",
|
|
247
|
+
* };
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* Login with username (explicit loginType):
|
|
252
|
+
* ```typescript
|
|
253
|
+
* const params: LoginParams = {
|
|
254
|
+
* loginType: "username",
|
|
255
|
+
* username: "john_doe",
|
|
256
|
+
* password: "Password@123",
|
|
257
|
+
* };
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
interface LoginParams {
|
|
261
|
+
/**
|
|
262
|
+
* Login method: "username" | "email" | "phone"
|
|
263
|
+
* Optional: Will be auto-detected based on provided fields
|
|
264
|
+
*/
|
|
265
|
+
loginType?: LoginType;
|
|
266
|
+
/** Username (required if loginType="username") */
|
|
267
|
+
username?: string;
|
|
268
|
+
/** Email (required if loginType="email") */
|
|
269
|
+
email?: string;
|
|
270
|
+
/** Phone (required if loginType="phone") */
|
|
271
|
+
phone?: string;
|
|
272
|
+
/** Password (always required) */
|
|
273
|
+
password: string;
|
|
274
|
+
}
|
|
275
|
+
type CodeLoginType = "email" | "phone";
|
|
276
|
+
/**
|
|
277
|
+
* Code login parameters
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* Login with email code (auto-detect loginType):
|
|
281
|
+
* ```typescript
|
|
282
|
+
* const params: CodeLoginParams = {
|
|
283
|
+
* email: "user@example.com",
|
|
284
|
+
* code: "123456",
|
|
285
|
+
* };
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
interface CodeLoginParams {
|
|
289
|
+
/**
|
|
290
|
+
* Login method: "email" | "phone"
|
|
291
|
+
* Optional: Will be auto-detected based on provided fields
|
|
292
|
+
*/
|
|
293
|
+
loginType?: CodeLoginType;
|
|
294
|
+
email?: string;
|
|
295
|
+
phone?: string;
|
|
296
|
+
code: string;
|
|
297
|
+
}
|
|
298
|
+
type SendCodeType = "email" | "phone";
|
|
299
|
+
interface SendCodeParams {
|
|
300
|
+
type: SendCodeType;
|
|
301
|
+
email?: string;
|
|
302
|
+
phone?: string;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Login response with user info and access token
|
|
306
|
+
* Both user and accessToken are required for successful login
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```typescript
|
|
310
|
+
* const result = await authClient.login({ ... });
|
|
311
|
+
* if (result.data) {
|
|
312
|
+
* const { user, accessToken } = result.data;
|
|
313
|
+
* console.log(`Welcome ${user.displayName}`);
|
|
314
|
+
* console.log(`Token: ${accessToken}`);
|
|
315
|
+
* }
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
interface LoginResponse {
|
|
319
|
+
/** User information with roles and permissions */
|
|
320
|
+
user: User;
|
|
321
|
+
/** Access token (JWT) for API authentication */
|
|
322
|
+
accessToken: string;
|
|
323
|
+
/** Token expiration time in seconds */
|
|
324
|
+
expiresIn?: number;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Register response - user and accessToken are optional
|
|
328
|
+
* depending on backend configuration:
|
|
329
|
+
* - Both returned: Auto-login after registration
|
|
330
|
+
* - Only user: Registration successful but requires email verification
|
|
331
|
+
* - Neither: Registration successful, user must login separately
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* const result = await authClient.register({ ... });
|
|
336
|
+
* if (result.data?.user && result.data?.accessToken) {
|
|
337
|
+
* console.log("Registered and logged in:", result.data.user);
|
|
338
|
+
* } else {
|
|
339
|
+
* console.log("Registered, please verify email or login manually");
|
|
340
|
+
* }
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
interface RegisterResponse {
|
|
344
|
+
/** User information with roles and permissions (optional) */
|
|
345
|
+
user?: User;
|
|
346
|
+
/** Access token (JWT) for API authentication (optional) */
|
|
347
|
+
accessToken?: string;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Captcha response with image and verification ID
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* ```typescript
|
|
354
|
+
* const result = await authClient.getCaptcha();
|
|
355
|
+
* if (result.data) {
|
|
356
|
+
* // Display image to user
|
|
357
|
+
* document.getElementById("img").src = result.data.captchaImage;
|
|
358
|
+
*
|
|
359
|
+
* // After user inputs code, verify with:
|
|
360
|
+
* const captcha = `${result.data.captchaId}:${userInputCode}`;
|
|
361
|
+
* }
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
interface CaptchaResponse {
|
|
365
|
+
/** Unique captcha ID for verification */
|
|
366
|
+
captchaId: string;
|
|
367
|
+
/** Base64 encoded captcha image (data:image/png;base64,...) */
|
|
368
|
+
captchaImage: string;
|
|
369
|
+
/** Expiration time in seconds (typically 300 = 5 minutes) */
|
|
370
|
+
expiresIn: number;
|
|
371
|
+
}
|
|
372
|
+
interface RefreshTokenResponse {
|
|
373
|
+
accessToken: string;
|
|
374
|
+
}
|
|
375
|
+
interface UpdateMeParams {
|
|
376
|
+
displayName?: string;
|
|
377
|
+
avatarUrl?: string;
|
|
378
|
+
}
|
|
379
|
+
interface ChangePasswordParams {
|
|
380
|
+
oldPassword: string;
|
|
381
|
+
newPassword: string;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* OAuth provider types
|
|
385
|
+
* - google: Google OAuth
|
|
386
|
+
* - github: GitHub OAuth
|
|
387
|
+
* - wechat: WeChat Open Platform OAuth (for web/mobile apps)
|
|
388
|
+
* - wechat_mini: WeChat Mini Program login
|
|
389
|
+
* - platform: AMaster Platform OAuth
|
|
390
|
+
*/
|
|
391
|
+
type OAuthProvider = "google" | "github" | "wechat" | "wechat_mini" | "platform";
|
|
392
|
+
interface OAuthBinding {
|
|
393
|
+
provider: OAuthProvider;
|
|
394
|
+
providerId: string;
|
|
395
|
+
email: string;
|
|
396
|
+
displayName: string;
|
|
397
|
+
avatarUrl: string | null;
|
|
398
|
+
createdAt: string;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* WeChat Mini Program phone number response
|
|
402
|
+
*/
|
|
403
|
+
interface MiniProgramPhoneResponse {
|
|
404
|
+
/** Phone number with country code (e.g., "+8613800138000") */
|
|
405
|
+
phone: string;
|
|
406
|
+
/** Whether the phone number is verified by WeChat */
|
|
407
|
+
phoneVerified: boolean;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Session information for multi-device management
|
|
411
|
+
*
|
|
412
|
+
* @example
|
|
413
|
+
* ```typescript
|
|
414
|
+
* {
|
|
415
|
+
* id: 241,
|
|
416
|
+
* sessionName: "Chrome on MacOS",
|
|
417
|
+
* ipAddress: "175.22.9.4",
|
|
418
|
+
* location: "Beijing, China",
|
|
419
|
+
* userAgent: "Mozilla/5.0...",
|
|
420
|
+
* lastUsedAt: "2024-01-01T12:00:00Z",
|
|
421
|
+
* createdAt: "2024-01-01T00:00:00Z",
|
|
422
|
+
* isCurrent: true
|
|
423
|
+
* }
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
interface Session {
|
|
427
|
+
/** Session ID (numeric) */
|
|
428
|
+
id: number;
|
|
429
|
+
/** Session name (e.g., "Chrome on MacOS") - optional */
|
|
430
|
+
sessionName?: string;
|
|
431
|
+
/** IP address - optional */
|
|
432
|
+
ipAddress?: string;
|
|
433
|
+
/** Login location (e.g., "Beijing, China") - optional */
|
|
434
|
+
location?: string;
|
|
435
|
+
/** User agent string - optional */
|
|
436
|
+
userAgent?: string;
|
|
437
|
+
/** Last used timestamp - optional */
|
|
438
|
+
lastUsedAt?: string;
|
|
439
|
+
/** Session creation timestamp */
|
|
440
|
+
createdAt: string;
|
|
441
|
+
/** Whether this is the current session */
|
|
442
|
+
isCurrent: boolean;
|
|
443
|
+
}
|
|
444
|
+
type AuthEvent = "login" | "logout" | "tokenExpired" | "tokenRefreshed" | "unauthorized";
|
|
445
|
+
type EventHandler = (...args: any[]) => void;
|
|
446
|
+
/**
|
|
447
|
+
* Standard success response from backend
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* {
|
|
451
|
+
* statusCode: 200,
|
|
452
|
+
* message: "ζδ½ζε",
|
|
453
|
+
* timestamp: "2026-02-02T08:17:11.045072301Z"
|
|
454
|
+
* }
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
interface SuccessResponse {
|
|
458
|
+
statusCode: number;
|
|
459
|
+
message?: string;
|
|
460
|
+
timestamp?: string;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Revoke all sessions response
|
|
464
|
+
* @example
|
|
465
|
+
* ```typescript
|
|
466
|
+
* {
|
|
467
|
+
* statusCode: 200,
|
|
468
|
+
* message: "ε·²ζ€ιζζδΌθ―",
|
|
469
|
+
* timestamp: "2026-02-02T08:17:11.045072301Z",
|
|
470
|
+
* revokedCount: 3
|
|
471
|
+
* }
|
|
472
|
+
* ```
|
|
473
|
+
*/
|
|
474
|
+
interface RevokeAllSessionsResponse {
|
|
475
|
+
statusCode: number;
|
|
476
|
+
message?: string;
|
|
477
|
+
timestamp?: string;
|
|
478
|
+
revokedCount: number;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export type { AuthClientOptions as A, ChangePasswordParams as C, EventHandler as E, LoginParams as L, MiniProgramPhoneResponse as M, OAuthBinding as O, Permission as P, RefreshTokenResponse as R, SendCodeParams as S, UpdateMeParams as U, AuthEvent as a, CaptchaResponse as b, CodeLoginParams as c, CodeLoginType as d, LoginResponse as e, LoginType as f, OAuthProvider as g, PermissionDetail as h, RegisterParams as i, RegisterResponse as j, RevokeAllSessionsResponse as k, Role as l, RoleDetail as m, SendCodeType as n, Session as o, SuccessResponse as p, User as q };
|