@amaster.ai/client 1.1.2 → 1.1.3
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/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +11 -11
- package/types/__tests__/type-checks.test-d.ts +8 -24
- package/types/auth/code-auth.d.ts +17 -21
- package/types/auth/index.d.ts +73 -53
- package/types/auth/oauth.d.ts +89 -83
- package/types/auth/password-auth.d.ts +51 -81
- package/types/auth/profile.d.ts +21 -17
- package/types/auth/user.d.ts +21 -65
- package/types/bpm.d.ts +1 -364
- package/types/common.d.ts +41 -23
- package/types/entity.d.ts +7 -7
- package/types/function.d.ts +1 -1
- package/types/index.d.ts +14 -53
- package/types/s3.d.ts +3 -3
- package/types/workflow.d.ts +1 -1
- package/types/auth/permissions.d.ts +0 -46
- package/types/auth/sessions.d.ts +0 -83
package/dist/index.d.cts
CHANGED
|
@@ -9,7 +9,7 @@ export { WorkflowFile, WorkflowInputValue, WorkflowRunRequest, WorkflowRunRespon
|
|
|
9
9
|
import { ASRClientConfig, ASRClient, ASRHttpClientConfig, ASRHttpClient } from '@amaster.ai/asr-client';
|
|
10
10
|
export { ASRClient, ASRClientConfig, ASRHttpClient, ASRHttpClientConfig, ASRLanguage } from '@amaster.ai/asr-client';
|
|
11
11
|
import { CopilotClient } from '@amaster.ai/copilot-client';
|
|
12
|
-
export { Conversation, ConversationController, ConversationControllerOptions, ConversationControllerSnapshot, CopilotClient, Role as CopilotRole, ErrorMessage, FileContent, ImageContent, MessageContent, MessagesItem, TextContent, TextMessage, ThoughtMessage, ToolMessage, UIRenderMessage } from '@amaster.ai/copilot-client';
|
|
12
|
+
export { Conversation, ConversationController, ConversationControllerOptions, ConversationControllerSnapshot, ConversationRequestState, ConversationRuntimeError, CopilotClient, Role as CopilotRole, ErrorMessage, FileContent, ImageContent, MessageContent, MessagesItem, TextContent, TextMessage, ThoughtMessage, ToolMessage, UIRenderMessage } from '@amaster.ai/copilot-client';
|
|
13
13
|
import { FunctionClient } from '@amaster.ai/function-client';
|
|
14
14
|
export { FunctionClient } from '@amaster.ai/function-client';
|
|
15
15
|
import { TTSClientConfig, TTSClient } from '@amaster.ai/tts-client';
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { WorkflowFile, WorkflowInputValue, WorkflowRunRequest, WorkflowRunRespon
|
|
|
9
9
|
import { ASRClientConfig, ASRClient, ASRHttpClientConfig, ASRHttpClient } from '@amaster.ai/asr-client';
|
|
10
10
|
export { ASRClient, ASRClientConfig, ASRHttpClient, ASRHttpClientConfig, ASRLanguage } from '@amaster.ai/asr-client';
|
|
11
11
|
import { CopilotClient } from '@amaster.ai/copilot-client';
|
|
12
|
-
export { Conversation, ConversationController, ConversationControllerOptions, ConversationControllerSnapshot, CopilotClient, Role as CopilotRole, ErrorMessage, FileContent, ImageContent, MessageContent, MessagesItem, TextContent, TextMessage, ThoughtMessage, ToolMessage, UIRenderMessage } from '@amaster.ai/copilot-client';
|
|
12
|
+
export { Conversation, ConversationController, ConversationControllerOptions, ConversationControllerSnapshot, ConversationRequestState, ConversationRuntimeError, CopilotClient, Role as CopilotRole, ErrorMessage, FileContent, ImageContent, MessageContent, MessagesItem, TextContent, TextMessage, ThoughtMessage, ToolMessage, UIRenderMessage } from '@amaster.ai/copilot-client';
|
|
13
13
|
import { FunctionClient } from '@amaster.ai/function-client';
|
|
14
14
|
export { FunctionClient } from '@amaster.ai/function-client';
|
|
15
15
|
import { TTSClientConfig, TTSClient } from '@amaster.ai/tts-client';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amaster.ai/client",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Unified API client for Amaster platform - All services in one package",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -72,16 +72,16 @@
|
|
|
72
72
|
"registry": "https://registry.npmjs.org/"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@amaster.ai/
|
|
76
|
-
"@amaster.ai/auth-client": "1.1.
|
|
77
|
-
"@amaster.ai/
|
|
78
|
-
"@amaster.ai/
|
|
79
|
-
"@amaster.ai/
|
|
80
|
-
"@amaster.ai/
|
|
81
|
-
"@amaster.ai/
|
|
82
|
-
"@amaster.ai/
|
|
83
|
-
"@amaster.ai/
|
|
84
|
-
"@amaster.ai/
|
|
75
|
+
"@amaster.ai/asr-client": "1.1.3",
|
|
76
|
+
"@amaster.ai/auth-client": "1.1.3",
|
|
77
|
+
"@amaster.ai/bpm-client": "1.1.3",
|
|
78
|
+
"@amaster.ai/copilot-client": "1.1.3",
|
|
79
|
+
"@amaster.ai/entity-client": "1.1.3",
|
|
80
|
+
"@amaster.ai/function-client": "1.1.3",
|
|
81
|
+
"@amaster.ai/http-client": "1.1.3",
|
|
82
|
+
"@amaster.ai/s3-client": "1.1.3",
|
|
83
|
+
"@amaster.ai/tts-client": "1.1.3",
|
|
84
|
+
"@amaster.ai/workflow-client": "1.1.3"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"axios": "^1.11.0"
|
|
@@ -27,6 +27,7 @@ describe('Type Tests', () => {
|
|
|
27
27
|
data: { id: number; name: string } | null;
|
|
28
28
|
error: ClientError | null;
|
|
29
29
|
status: number;
|
|
30
|
+
success: boolean;
|
|
30
31
|
}>();
|
|
31
32
|
});
|
|
32
33
|
|
|
@@ -36,15 +37,21 @@ describe('Type Tests', () => {
|
|
|
36
37
|
expectTypeOf<UserResult['data']>().toEqualTypeOf<User | null>();
|
|
37
38
|
});
|
|
38
39
|
|
|
40
|
+
it('should have success field', () => {
|
|
41
|
+
type Result = ClientResult<unknown>;
|
|
42
|
+
|
|
43
|
+
expectTypeOf<Result['success']>().toEqualTypeOf<boolean>();
|
|
44
|
+
});
|
|
39
45
|
});
|
|
40
46
|
|
|
41
47
|
describe('ClientError', () => {
|
|
42
48
|
it('should have all required fields', () => {
|
|
43
49
|
expectTypeOf<ClientError>().toMatchTypeOf<{
|
|
50
|
+
status: number;
|
|
44
51
|
message: string;
|
|
45
|
-
status?: number;
|
|
46
52
|
code?: string;
|
|
47
53
|
details?: unknown;
|
|
54
|
+
timestamp?: string;
|
|
48
55
|
}>();
|
|
49
56
|
});
|
|
50
57
|
});
|
|
@@ -87,29 +94,6 @@ describe('Type Tests', () => {
|
|
|
87
94
|
expectTypeOf<AmasterClient>().toHaveProperty('setAccessToken');
|
|
88
95
|
expectTypeOf<AmasterClient>().toHaveProperty('clearAuth');
|
|
89
96
|
});
|
|
90
|
-
|
|
91
|
-
it('should expose the current auth client methods', () => {
|
|
92
|
-
expectTypeOf<AmasterClient['auth']>().toHaveProperty('getMiniProgramPhoneNumber');
|
|
93
|
-
expectTypeOf<AmasterClient['auth']>().toHaveProperty('loginWithMiniProgram');
|
|
94
|
-
expectTypeOf<AmasterClient['auth']>().toHaveProperty('handleOAuthCallback');
|
|
95
|
-
expectTypeOf<AmasterClient['auth']>().toHaveProperty('updateMe');
|
|
96
|
-
expectTypeOf<AmasterClient['auth']>().toHaveProperty('getSession');
|
|
97
|
-
expectTypeOf<AmasterClient['auth']>().toHaveProperty('getSessions');
|
|
98
|
-
expectTypeOf<AmasterClient['auth']>().toHaveProperty('revokeSession');
|
|
99
|
-
expectTypeOf<AmasterClient['auth']>().toHaveProperty('revokeAllSessions');
|
|
100
|
-
expectTypeOf<AmasterClient['auth']>().toHaveProperty('hasAnyPermission');
|
|
101
|
-
expectTypeOf<AmasterClient['auth']>().toHaveProperty('hasAllPermissions');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should expose the current downstream client methods', () => {
|
|
105
|
-
expectTypeOf<AmasterClient['entity']>().toHaveProperty('bulkUpdate');
|
|
106
|
-
expectTypeOf<AmasterClient['entity']>().toHaveProperty('bulkDelete');
|
|
107
|
-
expectTypeOf<AmasterClient['bpm']>().toHaveProperty('startProcess');
|
|
108
|
-
expectTypeOf<AmasterClient['workflow']>().toHaveProperty('run');
|
|
109
|
-
expectTypeOf<AmasterClient['copilot']>().toHaveProperty('createConversationController');
|
|
110
|
-
expectTypeOf<AmasterClient['function']>().toHaveProperty('invoke');
|
|
111
|
-
expectTypeOf<AmasterClient['s3']>().toHaveProperty('upload');
|
|
112
|
-
});
|
|
113
97
|
});
|
|
114
98
|
|
|
115
99
|
describe('LoginParams', () => {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* - SMS verification code login
|
|
5
5
|
* - Send verification code
|
|
6
6
|
* - Captcha verification
|
|
7
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* @module auth/code-auth
|
|
9
9
|
*/
|
|
10
10
|
|
|
@@ -18,24 +18,20 @@ import type { LoginResponse, SuccessResponse } from './password-auth';
|
|
|
18
18
|
*/
|
|
19
19
|
export type CodeLoginType = 'email' | 'phone';
|
|
20
20
|
|
|
21
|
-
/**
|
|
22
|
-
* Send verification code type
|
|
23
|
-
*/
|
|
24
|
-
export type SendCodeType = 'email' | 'phone';
|
|
25
|
-
|
|
26
21
|
/**
|
|
27
22
|
* Verification code login parameters
|
|
23
|
+
*
|
|
28
24
|
*/
|
|
29
25
|
export interface CodeLoginParams {
|
|
30
26
|
/** Login method (optional, auto-detected) */
|
|
31
27
|
loginType?: CodeLoginType;
|
|
32
|
-
|
|
28
|
+
|
|
33
29
|
/** Email (required if using email code) */
|
|
34
30
|
email?: string;
|
|
35
|
-
|
|
31
|
+
|
|
36
32
|
/** Phone (required if using phone code) */
|
|
37
33
|
phone?: string;
|
|
38
|
-
|
|
34
|
+
|
|
39
35
|
/** Verification code received via email/SMS */
|
|
40
36
|
code: string;
|
|
41
37
|
}
|
|
@@ -45,11 +41,11 @@ export interface CodeLoginParams {
|
|
|
45
41
|
*/
|
|
46
42
|
export interface SendCodeParams {
|
|
47
43
|
/** Delivery method */
|
|
48
|
-
type:
|
|
49
|
-
|
|
44
|
+
type: 'email' | 'phone';
|
|
45
|
+
|
|
50
46
|
/** Email address (required if type='email') */
|
|
51
47
|
email?: string;
|
|
52
|
-
|
|
48
|
+
|
|
53
49
|
/** Phone number (required if type='phone') */
|
|
54
50
|
phone?: string;
|
|
55
51
|
}
|
|
@@ -60,19 +56,16 @@ export interface SendCodeParams {
|
|
|
60
56
|
export interface CaptchaResponse {
|
|
61
57
|
/** Unique captcha identifier */
|
|
62
58
|
captchaId: string;
|
|
63
|
-
|
|
59
|
+
|
|
64
60
|
/** Base64 encoded captcha image */
|
|
65
61
|
captchaImage: string;
|
|
66
|
-
|
|
67
|
-
/** Expiration time in seconds */
|
|
68
|
-
expiresIn: number;
|
|
69
62
|
}
|
|
70
63
|
|
|
71
64
|
// ==================== API ====================
|
|
72
65
|
|
|
73
66
|
/**
|
|
74
67
|
* Verification Code Authentication API
|
|
75
|
-
*
|
|
68
|
+
*
|
|
76
69
|
* Methods for code-based authentication and verification.
|
|
77
70
|
*/
|
|
78
71
|
export interface CodeAuthAPI {
|
|
@@ -83,27 +76,30 @@ export interface CodeAuthAPI {
|
|
|
83
76
|
*
|
|
84
77
|
* @param params - Email/phone and verification code
|
|
85
78
|
* @returns User info and access token
|
|
79
|
+
*
|
|
86
80
|
*/
|
|
87
81
|
loginWithCode(params: CodeLoginParams): Promise<ClientResult<LoginResponse>>;
|
|
88
82
|
|
|
89
83
|
/**
|
|
90
84
|
* Send verification code
|
|
91
|
-
*
|
|
85
|
+
*
|
|
92
86
|
* Sends a verification code to the specified email or phone.
|
|
93
87
|
* Used for code login or account verification.
|
|
94
|
-
*
|
|
88
|
+
*
|
|
95
89
|
* @param params - Email or phone to send code to
|
|
96
90
|
* @returns Success status
|
|
91
|
+
*
|
|
97
92
|
*/
|
|
98
93
|
sendCode(params: SendCodeParams): Promise<ClientResult<SuccessResponse>>;
|
|
99
94
|
|
|
100
95
|
/**
|
|
101
96
|
* Get captcha image
|
|
102
|
-
*
|
|
97
|
+
*
|
|
103
98
|
* Retrieves a captcha challenge for verification.
|
|
104
99
|
* Used during registration or sensitive operations.
|
|
105
|
-
*
|
|
100
|
+
*
|
|
106
101
|
* @returns Captcha ID and image (base64)
|
|
102
|
+
*
|
|
107
103
|
*/
|
|
108
104
|
getCaptcha(): Promise<ClientResult<CaptchaResponse>>;
|
|
109
105
|
}
|
package/types/auth/index.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Authentication module - provides user authentication and management capabilities.
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* This module exports all auth-related types for convenient importing:
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* @example
|
|
7
7
|
* // Import specific types
|
|
8
8
|
* import type { LoginParams, User, OAuthProvider } from '@amaster.ai/client/auth';
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
10
|
* @example
|
|
11
11
|
* // Import multiple types
|
|
12
|
-
* import type {
|
|
13
|
-
* LoginParams,
|
|
12
|
+
* import type {
|
|
13
|
+
* LoginParams,
|
|
14
14
|
* RegisterParams,
|
|
15
15
|
* User,
|
|
16
16
|
* Role,
|
|
17
|
-
* Permission
|
|
17
|
+
* Permission
|
|
18
18
|
* } from '@amaster.ai/client/auth';
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
20
|
* @module auth
|
|
21
21
|
* @since 1.0.0
|
|
22
22
|
*/
|
|
@@ -28,118 +28,138 @@ export * from './user';
|
|
|
28
28
|
export * from './password-auth';
|
|
29
29
|
export * from './code-auth';
|
|
30
30
|
export * from './oauth';
|
|
31
|
-
export * from './permissions';
|
|
32
31
|
export * from './profile';
|
|
33
|
-
export * from './sessions';
|
|
34
32
|
|
|
35
33
|
// Import for unified API
|
|
36
|
-
import type { PasswordAuthAPI
|
|
34
|
+
import type { PasswordAuthAPI } from './password-auth';
|
|
37
35
|
import type { CodeAuthAPI } from './code-auth';
|
|
38
36
|
import type { OAuthAPI } from './oauth';
|
|
39
|
-
import type { PermissionsAPI } from './permissions';
|
|
40
37
|
import type { ProfileAPI } from './profile';
|
|
41
|
-
import type { SessionsAPI } from './sessions';
|
|
42
38
|
|
|
43
|
-
// ====================
|
|
39
|
+
// ==================== Token Management ====================
|
|
44
40
|
|
|
45
41
|
/**
|
|
46
|
-
*
|
|
42
|
+
* Token refresh response
|
|
47
43
|
*/
|
|
48
|
-
export
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
export interface RefreshTokenResponse {
|
|
45
|
+
/** New access token */
|
|
46
|
+
accessToken: string;
|
|
47
|
+
|
|
48
|
+
/** Token expiration time in seconds */
|
|
49
|
+
expiresIn?: number;
|
|
50
|
+
}
|
|
54
51
|
|
|
55
52
|
/**
|
|
56
|
-
*
|
|
53
|
+
* Generic success response
|
|
57
54
|
*/
|
|
58
|
-
export
|
|
55
|
+
export interface SuccessResponse {
|
|
56
|
+
/** Whether operation was successful */
|
|
57
|
+
success: boolean;
|
|
58
|
+
|
|
59
|
+
/** Optional message */
|
|
60
|
+
message?: string;
|
|
61
|
+
}
|
|
59
62
|
|
|
60
63
|
// ==================== Unified Authentication API ====================
|
|
61
64
|
|
|
62
65
|
/**
|
|
63
66
|
* Complete Authentication Client API
|
|
64
|
-
*
|
|
67
|
+
*
|
|
65
68
|
* Combines all authentication capabilities into a single interface.
|
|
66
69
|
* All methods return a `ClientResult<T>` for consistent error handling.
|
|
70
|
+
*
|
|
67
71
|
*/
|
|
68
|
-
export interface AuthClientAPI
|
|
72
|
+
export interface AuthClientAPI
|
|
69
73
|
extends PasswordAuthAPI,
|
|
70
74
|
CodeAuthAPI,
|
|
71
75
|
OAuthAPI,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
SessionsAPI {
|
|
75
|
-
|
|
76
|
+
ProfileAPI {
|
|
77
|
+
|
|
76
78
|
/**
|
|
77
79
|
* Logout current user
|
|
78
|
-
*
|
|
80
|
+
*
|
|
79
81
|
* Invalidates the current session and clears local authentication state.
|
|
80
82
|
* All subsequent requests will be unauthenticated until login again.
|
|
81
|
-
*
|
|
83
|
+
*
|
|
82
84
|
* @returns Success status
|
|
85
|
+
*
|
|
83
86
|
*/
|
|
84
87
|
logout(): Promise<ClientResult<SuccessResponse>>;
|
|
85
88
|
|
|
86
89
|
/**
|
|
87
90
|
* Refresh access token
|
|
88
|
-
*
|
|
91
|
+
*
|
|
89
92
|
* Obtains a new access token using the refresh token.
|
|
90
93
|
* Note: Token refresh is handled automatically by the client.
|
|
91
94
|
* This method is exposed for manual refresh scenarios.
|
|
92
|
-
*
|
|
95
|
+
*
|
|
93
96
|
* @returns New access token
|
|
97
|
+
*
|
|
94
98
|
*/
|
|
95
99
|
refreshToken(): Promise<ClientResult<RefreshTokenResponse>>;
|
|
96
100
|
|
|
101
|
+
// ==================== Event Handling ====================
|
|
102
|
+
|
|
97
103
|
/**
|
|
98
104
|
* Subscribe to authentication events
|
|
99
|
-
*
|
|
105
|
+
*
|
|
100
106
|
* Available events:
|
|
101
107
|
* - `login` - Fired after successful login, receives User object
|
|
102
108
|
* - `logout` - Fired after logout
|
|
103
109
|
* - `tokenExpired` - Fired when access token expires
|
|
104
110
|
* - `tokenRefreshed` - Fired after token refresh, receives new token
|
|
105
111
|
* - `unauthorized` - Fired on 401 response
|
|
106
|
-
*
|
|
112
|
+
*
|
|
107
113
|
* @param event - Event name to subscribe to
|
|
108
114
|
* @param handler - Callback function
|
|
115
|
+
*
|
|
109
116
|
*/
|
|
110
|
-
on(event:
|
|
117
|
+
on(event: "login" | "logout" | "tokenExpired" | "tokenRefreshed" | "unauthorized", handler: (...args: unknown[]) => void): void;
|
|
111
118
|
|
|
112
119
|
/**
|
|
113
120
|
* Unsubscribe from authentication events
|
|
114
|
-
*
|
|
121
|
+
*
|
|
115
122
|
* @param event - Event name to unsubscribe from
|
|
116
123
|
* @param handler - The same callback function that was passed to `on()`
|
|
117
|
-
*/
|
|
118
|
-
off(event: AuthEvent, handler: EventHandler): void;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Check whether the current client has a stored access token.
|
|
122
124
|
*
|
|
123
|
-
* @returns True when authenticated, false otherwise
|
|
124
125
|
*/
|
|
125
|
-
|
|
126
|
+
off(event: "login" | "logout" | "tokenExpired" | "tokenRefreshed" | "unauthorized", handler: (...args: unknown[]) => void): void;
|
|
126
127
|
|
|
128
|
+
// ==================== Permission Checks ====================
|
|
129
|
+
|
|
127
130
|
/**
|
|
128
|
-
*
|
|
131
|
+
* Check if current user has a specific role (local check, fast)
|
|
132
|
+
*
|
|
133
|
+
* Works for both authenticated and anonymous users.
|
|
134
|
+
* Checks against locally cached user roles.
|
|
135
|
+
*
|
|
136
|
+
* @param roleCode - Role code to check (e.g., "admin", "user", "anonymous")
|
|
137
|
+
* @returns True if user has the role
|
|
129
138
|
*
|
|
130
|
-
* @returns Access token string, or null when not authenticated
|
|
131
139
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
hasRole(roleCode: string): boolean;
|
|
141
|
+
|
|
134
142
|
/**
|
|
135
|
-
*
|
|
143
|
+
* Check if current user has a specific permission (local check, fast)
|
|
144
|
+
*
|
|
145
|
+
* Works for both authenticated and anonymous users.
|
|
146
|
+
* Checks against locally cached user permissions.
|
|
147
|
+
*
|
|
148
|
+
* @param resource - Resource name (e.g., "user", "order")
|
|
149
|
+
* @param action - Action name (e.g., "read", "write", "delete")
|
|
150
|
+
* @returns True if user has the permission
|
|
136
151
|
*
|
|
137
|
-
* @param token - JWT access token
|
|
138
152
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
153
|
+
hasPermission(resource: string, action: string): boolean;
|
|
154
|
+
|
|
141
155
|
/**
|
|
142
|
-
*
|
|
156
|
+
* Check if current user is anonymous (not authenticated)
|
|
157
|
+
*
|
|
158
|
+
* Convenience method equivalent to `hasRole('anonymous')`.
|
|
159
|
+
* Returns true if user has the 'anonymous' role.
|
|
160
|
+
*
|
|
161
|
+
* @returns True if user is anonymous
|
|
162
|
+
*
|
|
143
163
|
*/
|
|
144
|
-
|
|
164
|
+
isAnonymous(): boolean;
|
|
145
165
|
}
|
package/types/auth/oauth.d.ts
CHANGED
|
@@ -1,137 +1,143 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* * OAuth and social authentication including:
|
|
3
|
-
* -
|
|
4
|
-
* - OAuth
|
|
5
|
-
* - WeChat Mini Program
|
|
6
|
-
* - OAuth
|
|
7
|
-
*
|
|
3
|
+
* - GitHub OAuth
|
|
4
|
+
* - Google OAuth
|
|
5
|
+
* - WeChat OAuth (Web & Mini Program)
|
|
6
|
+
* - Generic OAuth flow
|
|
7
|
+
*
|
|
8
8
|
* @module auth/oauth
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { ClientResult } from '../common';
|
|
12
|
-
import type { LoginResponse
|
|
12
|
+
import type { LoginResponse } from './password-auth';
|
|
13
13
|
|
|
14
14
|
// ==================== OAuth Providers ====================
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Supported OAuth providers
|
|
18
18
|
*/
|
|
19
|
-
export type OAuthProvider =
|
|
20
|
-
| 'google'
|
|
19
|
+
export type OAuthProvider =
|
|
21
20
|
| 'github'
|
|
21
|
+
| 'google'
|
|
22
22
|
| 'wechat'
|
|
23
|
-
| '
|
|
24
|
-
| '
|
|
23
|
+
| 'wechat-miniprogram'
|
|
24
|
+
| 'gitlab'
|
|
25
|
+
| 'microsoft';
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
|
-
* OAuth
|
|
28
|
+
* OAuth login parameters
|
|
29
|
+
*
|
|
28
30
|
*/
|
|
29
|
-
export interface
|
|
31
|
+
export interface OAuthLoginParams {
|
|
30
32
|
/** OAuth provider */
|
|
31
33
|
provider: OAuthProvider;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/** OAuth
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/** Provider avatar URL */
|
|
43
|
-
avatarUrl: string | null;
|
|
44
|
-
|
|
45
|
-
/** Binding creation timestamp */
|
|
46
|
-
createdAt: string;
|
|
34
|
+
|
|
35
|
+
/** Authorization code from OAuth callback */
|
|
36
|
+
code: string;
|
|
37
|
+
|
|
38
|
+
/** Redirect URI used in the OAuth flow */
|
|
39
|
+
redirectUri?: string;
|
|
40
|
+
|
|
41
|
+
/** State parameter for CSRF protection */
|
|
42
|
+
state?: string;
|
|
47
43
|
}
|
|
48
44
|
|
|
49
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Get OAuth URL parameters
|
|
47
|
+
*/
|
|
48
|
+
export interface GetOAuthUrlParams {
|
|
49
|
+
/** OAuth provider */
|
|
50
|
+
provider: OAuthProvider;
|
|
51
|
+
|
|
52
|
+
/** Redirect URI after OAuth */
|
|
53
|
+
redirectUri: string;
|
|
54
|
+
|
|
55
|
+
/** State parameter for CSRF protection */
|
|
56
|
+
state?: string;
|
|
57
|
+
|
|
58
|
+
/** Additional scopes (provider-specific) */
|
|
59
|
+
scopes?: string[];
|
|
60
|
+
}
|
|
50
61
|
|
|
51
62
|
/**
|
|
52
|
-
*
|
|
63
|
+
* OAuth URL response
|
|
53
64
|
*/
|
|
54
|
-
export interface
|
|
55
|
-
/**
|
|
56
|
-
|
|
65
|
+
export interface OAuthUrlResponse {
|
|
66
|
+
/** Authorization URL to redirect user to */
|
|
67
|
+
authUrl: string;
|
|
68
|
+
|
|
69
|
+
/** State parameter for verification */
|
|
70
|
+
state: string;
|
|
57
71
|
}
|
|
58
72
|
|
|
73
|
+
// ==================== WeChat Specific ====================
|
|
74
|
+
|
|
59
75
|
/**
|
|
60
|
-
* WeChat Mini Program
|
|
76
|
+
* WeChat Mini Program login parameters
|
|
77
|
+
*
|
|
61
78
|
*/
|
|
62
|
-
export interface
|
|
63
|
-
/**
|
|
79
|
+
export interface WeChatMiniProgramLoginParams {
|
|
80
|
+
/** WeChat login code */
|
|
64
81
|
code: string;
|
|
82
|
+
|
|
83
|
+
/** User info from WeChat (optional) */
|
|
84
|
+
userInfo?: {
|
|
85
|
+
/** Encrypted user data */
|
|
86
|
+
encryptedData: string;
|
|
87
|
+
/** IV for decryption */
|
|
88
|
+
iv: string;
|
|
89
|
+
};
|
|
65
90
|
}
|
|
66
91
|
|
|
67
92
|
/**
|
|
68
|
-
* WeChat
|
|
93
|
+
* WeChat web OAuth parameters
|
|
69
94
|
*/
|
|
70
|
-
export interface
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
|
|
95
|
+
export interface WeChatWebLoginParams {
|
|
96
|
+
/** Authorization code from WeChat OAuth */
|
|
97
|
+
code: string;
|
|
98
|
+
|
|
99
|
+
/** State parameter */
|
|
100
|
+
state?: string;
|
|
76
101
|
}
|
|
77
102
|
|
|
78
103
|
// ==================== API ====================
|
|
79
104
|
|
|
80
105
|
/**
|
|
81
106
|
* OAuth & Social Login API
|
|
82
|
-
*
|
|
83
|
-
* Methods for OAuth-based authentication
|
|
107
|
+
*
|
|
108
|
+
* Methods for OAuth-based authentication.
|
|
84
109
|
*/
|
|
85
110
|
export interface OAuthAPI {
|
|
86
111
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Handle OAuth callback on the current browser page
|
|
112
|
+
* Get OAuth authorization URL
|
|
113
|
+
*
|
|
114
|
+
* Generates the URL to redirect users to for OAuth authentication.
|
|
115
|
+
*
|
|
116
|
+
* @param params - OAuth provider and redirect URI
|
|
117
|
+
* @returns Authorization URL and state
|
|
96
118
|
*
|
|
97
|
-
* Parses the callback hash, stores the access token, and returns the current user.
|
|
98
119
|
*/
|
|
99
|
-
|
|
120
|
+
getOAuthUrl(params: GetOAuthUrlParams): Promise<ClientResult<OAuthUrlResponse>>;
|
|
100
121
|
|
|
101
122
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
123
|
+
* Complete OAuth login
|
|
124
|
+
*
|
|
125
|
+
* Exchanges the OAuth authorization code for access token and user info.
|
|
126
|
+
*
|
|
127
|
+
* @param params - OAuth provider and authorization code
|
|
105
128
|
* @returns User info and access token
|
|
106
|
-
*/
|
|
107
|
-
loginWithMiniProgram(code: string): Promise<ClientResult<LoginResponse>>;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Get WeChat Mini Program user phone number
|
|
111
|
-
*
|
|
112
|
-
* Requires the user to authorize via a `getPhoneNumber` button.
|
|
113
|
-
*
|
|
114
|
-
* @param code - Code returned by the Mini Program phone-number event
|
|
115
|
-
* @returns Phone number info
|
|
116
|
-
*/
|
|
117
|
-
getMiniProgramPhoneNumber(code: string): Promise<ClientResult<MiniProgramPhoneResponse>>;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Get OAuth accounts currently bound to the logged-in user
|
|
121
|
-
*/
|
|
122
|
-
getOAuthBindings(): Promise<ClientResult<OAuthBinding[]>>;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Redirect to provider binding flow for the current user
|
|
126
129
|
*
|
|
127
|
-
* @param provider - OAuth provider name
|
|
128
130
|
*/
|
|
129
|
-
|
|
131
|
+
oauthLogin(params: OAuthLoginParams): Promise<ClientResult<LoginResponse>>;
|
|
130
132
|
|
|
131
133
|
/**
|
|
132
|
-
*
|
|
134
|
+
* WeChat Mini Program login
|
|
135
|
+
*
|
|
136
|
+
* Authenticates user in WeChat Mini Program environment.
|
|
137
|
+
*
|
|
138
|
+
* @param params - WeChat login code
|
|
139
|
+
* @returns User info and access token
|
|
133
140
|
*
|
|
134
|
-
* @param provider - OAuth provider name
|
|
135
141
|
*/
|
|
136
|
-
|
|
142
|
+
wechatMiniProgramLogin(params: WeChatMiniProgramLoginParams): Promise<ClientResult<LoginResponse>>;
|
|
137
143
|
}
|