@amaster.ai/client 1.1.0-beta.30 → 1.1.0-beta.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,5 @@
1
1
  /**
2
- * ============================================================================
3
- * OAuth & Social Login - Type Definitions
4
- * ============================================================================
5
- *
6
- * OAuth and social authentication including:
2
+ * * OAuth and social authentication including:
7
3
  * - GitHub OAuth
8
4
  * - Google OAuth
9
5
  * - WeChat OAuth (Web & Mini Program)
@@ -30,30 +26,7 @@ export type OAuthProvider =
30
26
 
31
27
  /**
32
28
  * OAuth login parameters
33
- *
34
- * @example
35
- * GitHub OAuth:
36
- * ```typescript
37
- * // 1. Get OAuth URL
38
- * const url = await client.auth.getOAuthUrl({
39
- * provider: 'github',
40
- * redirectUri: 'https://app.example.com/auth/callback'
41
- * });
42
- *
43
- * // 2. Redirect user to OAuth provider
44
- * window.location.href = url.data.authUrl;
45
- *
46
- * // 3. Handle callback
47
- * // User is redirected back with code in URL params
48
- * const params = new URLSearchParams(window.location.search);
49
- * const code = params.get('code');
50
- *
51
- * // 4. Complete OAuth login
52
- * const result = await client.auth.oauthLogin({
53
- * provider: 'github',
54
- * code: code!
55
- * });
56
- * ```
29
+ *
57
30
  */
58
31
  export interface OAuthLoginParams {
59
32
  /** OAuth provider */
@@ -101,23 +74,7 @@ export interface OAuthUrlResponse {
101
74
 
102
75
  /**
103
76
  * WeChat Mini Program login parameters
104
- *
105
- * @example
106
- * ```typescript
107
- * // 1. Get code from WeChat API
108
- * wx.login({
109
- * success: async (res) => {
110
- * // 2. Login with code
111
- * const result = await client.auth.wechatMiniProgramLogin({
112
- * code: res.code
113
- * });
114
- *
115
- * if (result.data) {
116
- * console.log('Logged in:', result.data.user);
117
- * }
118
- * }
119
- * });
120
- * ```
77
+ *
121
78
  */
122
79
  export interface WeChatMiniProgramLoginParams {
123
80
  /** WeChat login code */
@@ -158,30 +115,7 @@ export interface OAuthAPI {
158
115
  *
159
116
  * @param params - OAuth provider and redirect URI
160
117
  * @returns Authorization URL and state
161
- *
162
- * @example
163
- * GitHub OAuth flow:
164
- * ```typescript
165
- * const result = await client.auth.getOAuthUrl({
166
- * provider: 'github',
167
- * redirectUri: 'https://app.example.com/auth/callback'
168
- * });
169
- *
170
- * if (result.data) {
171
- * // Redirect user to GitHub login
172
- * window.location.href = result.data.authUrl;
173
- * }
174
- * ```
175
- *
176
- * @example
177
- * Google OAuth with custom scopes:
178
- * ```typescript
179
- * const result = await client.auth.getOAuthUrl({
180
- * provider: 'google',
181
- * redirectUri: 'https://app.example.com/auth/callback',
182
- * scopes: ['email', 'profile', 'https://www.googleapis.com/auth/calendar']
183
- * });
184
- * ```
118
+ *
185
119
  */
186
120
  getOAuthUrl(params: GetOAuthUrlParams): Promise<ClientResult<OAuthUrlResponse>>;
187
121
 
@@ -192,42 +126,7 @@ export interface OAuthAPI {
192
126
  *
193
127
  * @param params - OAuth provider and authorization code
194
128
  * @returns User info and access token
195
- *
196
- * @example
197
- * Complete GitHub OAuth:
198
- * ```typescript
199
- * // After user is redirected back from GitHub
200
- * const params = new URLSearchParams(window.location.search);
201
- * const code = params.get('code');
202
- *
203
- * const result = await client.auth.oauthLogin({
204
- * provider: 'github',
205
- * code: code!,
206
- * redirectUri: 'https://app.example.com/auth/callback'
207
- * });
208
- *
209
- * if (result.data) {
210
- * console.log('Logged in as:', result.data.user.displayName);
211
- * // Token is now automatically attached to all requests
212
- * }
213
- * ```
214
- *
215
- * @example
216
- * With error handling:
217
- * ```typescript
218
- * const result = await client.auth.oauthLogin({
219
- * provider: 'google',
220
- * code: authCode
221
- * });
222
- *
223
- * if (result.error) {
224
- * if (result.status === 400) {
225
- * console.error('Invalid or expired authorization code');
226
- * } else {
227
- * console.error('OAuth login failed:', result.error.message);
228
- * }
229
- * }
230
- * ```
129
+ *
231
130
  */
232
131
  oauthLogin(params: OAuthLoginParams): Promise<ClientResult<LoginResponse>>;
233
132
 
@@ -238,43 +137,7 @@ export interface OAuthAPI {
238
137
  *
239
138
  * @param params - WeChat login code
240
139
  * @returns User info and access token
241
- *
242
- * @example
243
- * ```typescript
244
- * // In WeChat Mini Program
245
- * wx.login({
246
- * success: async (res) => {
247
- * const result = await client.auth.wechatMiniProgramLogin({
248
- * code: res.code
249
- * });
250
- *
251
- * if (result.data) {
252
- * wx.setStorageSync('token', result.data.accessToken);
253
- * wx.showToast({ title: 'Login successful!' });
254
- * }
255
- * }
256
- * });
257
- * ```
258
- *
259
- * @example
260
- * With user info:
261
- * ```typescript
262
- * wx.login({
263
- * success: async (loginRes) => {
264
- * wx.getUserInfo({
265
- * success: async (userRes) => {
266
- * await client.auth.wechatMiniProgramLogin({
267
- * code: loginRes.code,
268
- * userInfo: {
269
- * encryptedData: userRes.encryptedData,
270
- * iv: userRes.iv
271
- * }
272
- * });
273
- * }
274
- * });
275
- * }
276
- * });
277
- * ```
140
+ *
278
141
  */
279
142
  wechatMiniProgramLogin(params: WeChatMiniProgramLoginParams): Promise<ClientResult<LoginResponse>>;
280
143
  }
@@ -1,9 +1,5 @@
1
1
  /**
2
- * ============================================================================
3
- * Password Authentication - Type Definitions
4
- * ============================================================================
5
- *
6
- * Password-based authentication including:
2
+ * * Password-based authentication including:
7
3
  * - Email/username/phone + password login
8
4
  * - User registration
9
5
  * - Password change
@@ -20,45 +16,7 @@ import type { User } from './user';
20
16
  * User registration parameters
21
17
  *
22
18
  * At least one identifier (username, email, or phone) must be provided.
23
- *
24
- * @example
25
- * Register with email:
26
- * ```typescript
27
- * await client.auth.register({
28
- * email: 'user@example.com',
29
- * password: 'Password@123',
30
- * displayName: 'John Doe'
31
- * });
32
- * ```
33
- *
34
- * @example
35
- * Register with username and email:
36
- * ```typescript
37
- * await client.auth.register({
38
- * username: 'johndoe',
39
- * email: 'john@example.com',
40
- * password: 'Password@123',
41
- * displayName: 'John Doe'
42
- * });
43
- * ```
44
- *
45
- * @example
46
- * Register with captcha verification:
47
- * ```typescript
48
- * // 1. Get captcha
49
- * const captcha = await client.auth.getCaptcha();
50
- *
51
- * // 2. Show captcha.data.captchaImage to user
52
- * const userInput = prompt('Enter captcha:');
53
- *
54
- * // 3. Register with captcha
55
- * await client.auth.register({
56
- * username: 'johndoe',
57
- * email: 'john@example.com',
58
- * password: 'Password@123',
59
- * captcha: `${captcha.data.captchaId}:${userInput}`
60
- * });
61
- * ```
19
+ *
62
20
  */
63
21
  export interface RegisterParams {
64
22
  /** Username (optional, but one of username/email/phone required) */
@@ -82,7 +40,6 @@ export interface RegisterParams {
82
40
  /**
83
41
  * Captcha verification (optional)
84
42
  * Format: "captchaId:userInput"
85
- * @example "abc-123:XY7K"
86
43
  */
87
44
  captcha?: string;
88
45
  }
@@ -97,34 +54,7 @@ export type LoginType = 'username' | 'email' | 'phone';
97
54
  *
98
55
  * The `loginType` field is optional - it will be auto-detected based on
99
56
  * which identifier field (username/email/phone) you provide.
100
- *
101
- * @example
102
- * Login with email (auto-detect):
103
- * ```typescript
104
- * await client.auth.login({
105
- * email: 'user@example.com',
106
- * password: 'Password@123'
107
- * });
108
- * ```
109
- *
110
- * @example
111
- * Login with username (explicit type):
112
- * ```typescript
113
- * await client.auth.login({
114
- * loginType: 'username',
115
- * username: 'johndoe',
116
- * password: 'Password@123'
117
- * });
118
- * ```
119
- *
120
- * @example
121
- * Login with phone:
122
- * ```typescript
123
- * await client.auth.login({
124
- * phone: '+86-13800138000',
125
- * password: 'Password@123'
126
- * });
127
- * ```
57
+ *
128
58
  */
129
59
  export interface LoginParams {
130
60
  /** Login method (optional, auto-detected if not provided) */
@@ -145,18 +75,7 @@ export interface LoginParams {
145
75
 
146
76
  /**
147
77
  * Change password parameters
148
- *
149
- * @example
150
- * ```typescript
151
- * const result = await client.auth.changePassword({
152
- * oldPassword: 'OldPassword@123',
153
- * newPassword: 'NewPassword@456'
154
- * });
155
- *
156
- * if (result.data?.success) {
157
- * console.log('Password changed successfully');
158
- * }
159
- * ```
78
+ *
160
79
  */
161
80
  export interface ChangePasswordParams {
162
81
  /** Current password (for verification) */
@@ -173,23 +92,7 @@ export interface ChangePasswordParams {
173
92
 
174
93
  /**
175
94
  * Login/Registration response with user info and access token
176
- *
177
- * @example
178
- * ```typescript
179
- * const result = await client.auth.login({
180
- * email: 'user@example.com',
181
- * password: 'password123'
182
- * });
183
- *
184
- * if (result.data) {
185
- * const { user, accessToken } = result.data;
186
- * console.log(`Welcome ${user.displayName}!`);
187
- * console.log(`Token: ${accessToken}`);
188
- *
189
- * // All subsequent requests now include this token automatically
190
- * await client.entity.list('default', 'users');
191
- * }
192
- * ```
95
+ *
193
96
  */
194
97
  export interface LoginResponse {
195
98
  /** User information */
@@ -222,6 +125,8 @@ export interface SuccessResponse {
222
125
  * Password Authentication API
223
126
  *
224
127
  * Methods for password-based authentication and account management.
128
+ *
129
+ * @since 1.0.0
225
130
  */
226
131
  export interface PasswordAuthAPI {
227
132
  /**
@@ -234,30 +139,25 @@ export interface PasswordAuthAPI {
234
139
  * @returns User info and access token (if auto-login enabled)
235
140
  *
236
141
  * @example
237
- * Basic registration:
238
- * ```typescript
142
+ * // Register with email
239
143
  * const result = await client.auth.register({
240
144
  * email: 'user@example.com',
241
- * password: 'Password@123',
145
+ * password: 'SecurePass123',
242
146
  * displayName: 'John Doe'
243
147
  * });
244
148
  *
245
- * if (result.data) {
246
- * console.log('Registration successful!');
247
- * console.log('User:', result.data.user);
149
+ * if (result.success) {
150
+ * console.log('User registered:', result.data.user.uid);
248
151
  * }
249
- * ```
250
152
  *
251
153
  * @example
252
- * Registration with username:
253
- * ```typescript
254
- * await client.auth.register({
154
+ * // Register with username
155
+ * const result = await client.auth.register({
255
156
  * username: 'johndoe',
256
- * email: 'john@example.com',
257
- * password: 'Password@123',
258
- * displayName: 'John Doe'
157
+ * password: 'SecurePass123'
259
158
  * });
260
- * ```
159
+ *
160
+ * @since 1.0.0
261
161
  */
262
162
  register(params: RegisterParams): Promise<ClientResult<LoginResponse>>;
263
163
 
@@ -271,30 +171,33 @@ export interface PasswordAuthAPI {
271
171
  * @returns User info and access token
272
172
  *
273
173
  * @example
274
- * Login with email:
275
- * ```typescript
174
+ * // Login with email
276
175
  * const result = await client.auth.login({
277
176
  * email: 'user@example.com',
278
- * password: 'Password@123'
177
+ * password: 'myPassword123'
279
178
  * });
280
179
  *
281
- * if (result.data) {
282
- * console.log('Welcome', result.data.user.displayName);
283
- * // Token is now automatically attached to all requests
180
+ * if (result.success) {
181
+ * console.log('Welcome,', result.data.user.displayName);
284
182
  * } else {
285
- * console.error('Login failed:', result.error?.message);
183
+ * console.error('Login failed:', result.error.message);
286
184
  * }
287
- * ```
288
185
  *
289
186
  * @example
290
- * Login with username:
291
- * ```typescript
292
- * await client.auth.login({
293
- * loginType: 'username',
187
+ * // Login with username
188
+ * const result = await client.auth.login({
294
189
  * username: 'johndoe',
295
- * password: 'Password@123'
190
+ * password: 'myPassword123'
191
+ * });
192
+ *
193
+ * @example
194
+ * // Login with phone
195
+ * const result = await client.auth.login({
196
+ * phone: '+1234567890',
197
+ * password: 'myPassword123'
296
198
  * });
297
- * ```
199
+ *
200
+ * @since 1.0.0
298
201
  */
299
202
  login(params: LoginParams): Promise<ClientResult<LoginResponse>>;
300
203
 
@@ -308,18 +211,16 @@ export interface PasswordAuthAPI {
308
211
  * @returns Success status
309
212
  *
310
213
  * @example
311
- * ```typescript
312
214
  * const result = await client.auth.changePassword({
313
- * oldPassword: 'OldPassword@123',
314
- * newPassword: 'NewPassword@456'
215
+ * oldPassword: 'currentPass123',
216
+ * newPassword: 'newSecurePass456'
315
217
  * });
316
218
  *
317
- * if (result.data?.success) {
219
+ * if (result.success) {
318
220
  * console.log('Password changed successfully');
319
- * } else {
320
- * console.error('Failed:', result.error?.message);
321
221
  * }
322
- * ```
222
+ *
223
+ * @since 1.0.0
323
224
  */
324
225
  changePassword(params: ChangePasswordParams): Promise<ClientResult<SuccessResponse>>;
325
226
  }
@@ -1,9 +1,5 @@
1
1
  /**
2
- * ============================================================================
3
- * User Profile Management - Type Definitions
4
- * ============================================================================
5
- *
6
- * User profile operations including:
2
+ * * User profile operations including:
7
3
  * - Get current user information
8
4
  * - Update profile fields
9
5
  * - Avatar management
@@ -20,36 +16,7 @@ import type { User } from './user';
20
16
  * Update user profile parameters
21
17
  *
22
18
  * All fields are optional - only update what you want to change.
23
- *
24
- * @example
25
- * Update display name:
26
- * ```typescript
27
- * await client.auth.updateProfile({
28
- * displayName: 'Jane Doe'
29
- * });
30
- * ```
31
- *
32
- * @example
33
- * Update multiple fields:
34
- * ```typescript
35
- * await client.auth.updateProfile({
36
- * displayName: 'John Smith',
37
- * avatarUrl: 'https://cdn.example.com/avatar.jpg',
38
- * phone: '+86-13900139000'
39
- * });
40
- * ```
41
- *
42
- * @example
43
- * Update email (may require verification):
44
- * ```typescript
45
- * const result = await client.auth.updateProfile({
46
- * email: 'newemail@example.com'
47
- * });
48
- *
49
- * if (result.data && !result.data.emailVerified) {
50
- * console.log('Verification email sent to new address');
51
- * }
52
- * ```
19
+ *
53
20
  */
54
21
  export interface UpdateProfileParams {
55
22
  /** New display name */
@@ -79,41 +46,7 @@ export interface ProfileAPI {
79
46
  * Retrieves the profile of the currently authenticated user.
80
47
  *
81
48
  * @returns Current user info with roles and permissions
82
- *
83
- * @example
84
- * Basic usage:
85
- * ```typescript
86
- * const result = await client.auth.getMe();
87
- * if (result.data) {
88
- * console.log('Current user:', result.data.displayName);
89
- * console.log('Email:', result.data.email);
90
- * console.log('Roles:', result.data.roles);
91
- * console.log('Permissions:', result.data.permissions);
92
- * }
93
- * ```
94
- *
95
- * @example
96
- * Check permissions:
97
- * ```typescript
98
- * const result = await client.auth.getMe();
99
- * if (result.data?.permissions.includes('user:delete')) {
100
- * showDeleteButton();
101
- * }
102
- *
103
- * if (result.data?.roles.includes('admin')) {
104
- * showAdminPanel();
105
- * }
106
- * ```
107
- *
108
- * @example
109
- * Display verification status:
110
- * ```typescript
111
- * const user = (await client.auth.getMe()).data;
112
- * if (user) {
113
- * console.log(`Email ${user.email}${user.emailVerified ? ' ✓' : ' (unverified)'}`);
114
- * console.log(`Phone ${user.phone}${user.phoneVerified ? ' ✓' : ' (unverified)'}`);
115
- * }
116
- * ```
49
+ *
117
50
  */
118
51
  getMe(): Promise<ClientResult<User>>;
119
52
 
@@ -125,39 +58,7 @@ export interface ProfileAPI {
125
58
  *
126
59
  * @param params - Fields to update
127
60
  * @returns Updated user info
128
- *
129
- * @example
130
- * Update display name:
131
- * ```typescript
132
- * const result = await client.auth.updateProfile({
133
- * displayName: 'Jane Smith'
134
- * });
135
- *
136
- * if (result.data) {
137
- * console.log('Profile updated:', result.data.displayName);
138
- * }
139
- * ```
140
- *
141
- * @example
142
- * Update avatar:
143
- * ```typescript
144
- * // After uploading avatar to CDN
145
- * const avatarUrl = 'https://cdn.example.com/avatars/user-123.jpg';
146
- *
147
- * await client.auth.updateProfile({
148
- * avatarUrl: avatarUrl
149
- * });
150
- * ```
151
- *
152
- * @example
153
- * Update multiple fields:
154
- * ```typescript
155
- * await client.auth.updateProfile({
156
- * displayName: 'John Doe',
157
- * avatarUrl: 'https://cdn.example.com/avatar.jpg',
158
- * phone: '+86-13900139000'
159
- * });
160
- * ```
61
+ *
161
62
  */
162
63
  updateProfile(params: UpdateProfileParams): Promise<ClientResult<User>>;
163
64
  }
@@ -1,9 +1,5 @@
1
1
  /**
2
- * ============================================================================
3
- * User Types - Base User Information
4
- * ============================================================================
5
- *
6
- * Core user data structures including:
2
+ * * Core user data structures including:
7
3
  * - User profile information
8
4
  * - Role and permission types
9
5
  * - User status enums
@@ -17,30 +13,7 @@
17
13
  * Roles and permissions are returned as simple string arrays for efficient client-side use:
18
14
  * - `roles`: ["admin", "user", "manager"]
19
15
  * - `permissions`: ["user:read", "user:write", "order:read"]
20
- *
21
- * @example
22
- * Check user permissions:
23
- * ```typescript
24
- * const result = await client.auth.getMe();
25
- * const user = result.data;
26
- *
27
- * if (user.roles.includes('admin')) {
28
- * console.log('User is an admin');
29
- * }
30
- *
31
- * if (user.permissions.includes('user:delete')) {
32
- * showDeleteButton();
33
- * }
34
- * ```
35
- *
36
- * @example
37
- * Display user info:
38
- * ```typescript
39
- * const user = result.data;
40
- * console.log(`Name: ${user.displayName}`);
41
- * console.log(`Email: ${user.email}${user.emailVerified ? ' ✓' : ''}`);
42
- * console.log(`Roles: ${user.roles.join(', ')}`);
43
- * ```
16
+ *
44
17
  */
45
18
  export interface User {
46
19
  /** Unique user identifier */
@@ -82,16 +55,13 @@ export interface User {
82
55
  * Includes system roles and custom roles:
83
56
  * - System roles: "anonymous" (unauthenticated), "member" (default), "admin"
84
57
  * - Custom roles: defined in app.settings.yml
85
- *
86
- * @example ["admin", "user", "manager"]
87
- * @example ["anonymous"] // For unauthenticated users
58
+ *
88
59
  */
89
60
  roles: string[];
90
61
 
91
62
  /**
92
63
  * Permission names granted to user
93
64
  * Format: "resource:action"
94
- * @example ["user:read", "user:write", "order:read", "order:delete"]
95
65
  */
96
66
  permissions: string[];
97
67