@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.
@@ -3,7 +3,7 @@
3
3
  * - Email/username/phone + password login
4
4
  * - User registration
5
5
  * - Password change
6
- *
6
+ *
7
7
  * @module auth/password-auth
8
8
  */
9
9
 
@@ -14,29 +14,30 @@ import type { User } from './user';
14
14
 
15
15
  /**
16
16
  * User registration parameters
17
- *
17
+ *
18
18
  * At least one identifier (username, email, or phone) must be provided.
19
+ *
19
20
  */
20
21
  export interface RegisterParams {
21
22
  /** Username (optional, but one of username/email/phone required) */
22
23
  username?: string;
23
-
24
+
24
25
  /** Email address (optional, but one of username/email/phone required) */
25
26
  email?: string;
26
-
27
+
27
28
  /** Phone number (optional, but one of username/email/phone required) */
28
29
  phone?: string;
29
-
30
- /**
30
+
31
+ /**
31
32
  * Password (required, 8-128 characters)
32
33
  * Must contain at least: uppercase, lowercase, number
33
34
  */
34
35
  password: string;
35
-
36
+
36
37
  /** Display name for UI */
37
38
  displayName?: string;
38
-
39
- /**
39
+
40
+ /**
40
41
  * Captcha verification (optional)
41
42
  * Format: "captchaId:userInput"
42
43
  */
@@ -50,35 +51,37 @@ export type LoginType = 'username' | 'email' | 'phone';
50
51
 
51
52
  /**
52
53
  * Login parameters for password-based authentication
53
- *
54
+ *
54
55
  * The `loginType` field is optional - it will be auto-detected based on
55
56
  * which identifier field (username/email/phone) you provide.
57
+ *
56
58
  */
57
59
  export interface LoginParams {
58
60
  /** Login method (optional, auto-detected if not provided) */
59
61
  loginType?: LoginType;
60
-
62
+
61
63
  /** Username (required if loginType='username') */
62
64
  username?: string;
63
-
65
+
64
66
  /** Email (required if loginType='email') */
65
67
  email?: string;
66
-
68
+
67
69
  /** Phone (required if loginType='phone') */
68
70
  phone?: string;
69
-
71
+
70
72
  /** Password (always required) */
71
73
  password: string;
72
74
  }
73
75
 
74
76
  /**
75
77
  * Change password parameters
78
+ *
76
79
  */
77
80
  export interface ChangePasswordParams {
78
81
  /** Current password (for verification) */
79
82
  oldPassword: string;
80
-
81
- /**
83
+
84
+ /**
82
85
  * New password (8-128 characters)
83
86
  * Must contain: uppercase, lowercase, number
84
87
  */
@@ -88,86 +91,53 @@ export interface ChangePasswordParams {
88
91
  // ==================== Responses ====================
89
92
 
90
93
  /**
91
- * Login response with user info and access token
94
+ * Login/Registration response with user info and access token
95
+ *
92
96
  */
93
97
  export interface LoginResponse {
94
98
  /** User information */
95
99
  user: User;
96
-
100
+
97
101
  /** JWT access token */
98
102
  accessToken: string;
99
-
103
+
100
104
  /** Refresh token (if configured) */
101
105
  refreshToken?: string;
102
-
106
+
103
107
  /** Token expiration time in seconds */
104
108
  expiresIn?: number;
105
-
106
- /**
107
- * Whether the SDK already handled the current page redirect target.
108
- */
109
- redirectHandled?: boolean;
110
-
111
- /**
112
- * Redirect target consumed by the SDK when `redirectHandled` is true.
113
- */
114
- redirectTarget?: string;
115
- }
116
-
117
- /**
118
- * Registration response
119
- *
120
- * Depending on backend configuration, registration may or may not auto-login.
121
- */
122
- export interface RegisterResponse {
123
- /** Newly created user info */
124
- user?: User;
125
-
126
- /** JWT access token when auto-login is enabled */
127
- accessToken?: string;
128
- }
129
-
130
- /**
131
- * Access token refresh response
132
- */
133
- export interface RefreshTokenResponse {
134
- /** New access token */
135
- accessToken: string;
136
109
  }
137
110
 
138
111
  /**
139
112
  * Generic success response
140
113
  */
141
114
  export interface SuccessResponse {
142
- /** Backend status code */
143
- statusCode: number;
144
-
115
+ /** Whether operation was successful */
116
+ success: boolean;
117
+
145
118
  /** Optional message */
146
119
  message?: string;
147
-
148
- /** Backend timestamp */
149
- timestamp?: string;
150
120
  }
151
121
 
152
122
  // ==================== API ====================
153
123
 
154
124
  /**
155
125
  * Password Authentication API
156
- *
126
+ *
157
127
  * Methods for password-based authentication and account management.
158
- *
128
+ *
159
129
  * @since 1.0.0
160
130
  */
161
131
  export interface PasswordAuthAPI {
162
132
  /**
163
133
  * Register a new user account
164
- *
134
+ *
165
135
  * Creates a new user account with the provided credentials.
166
136
  * Depending on backend configuration, may auto-login after registration.
167
- *
137
+ *
168
138
  * @param params - Registration parameters
169
139
  * @returns User info and access token (if auto-login enabled)
170
- *
140
+ *
171
141
  * @example
172
142
  * // Register with email
173
143
  * const result = await client.auth.register({
@@ -175,81 +145,81 @@ export interface PasswordAuthAPI {
175
145
  * password: 'SecurePass123',
176
146
  * displayName: 'John Doe'
177
147
  * });
178
- *
179
- * if (result.data) {
148
+ *
149
+ * if (result.success) {
180
150
  * console.log('User registered:', result.data.user.uid);
181
151
  * }
182
- *
152
+ *
183
153
  * @example
184
154
  * // Register with username
185
155
  * const result = await client.auth.register({
186
156
  * username: 'johndoe',
187
157
  * password: 'SecurePass123'
188
158
  * });
189
- *
159
+ *
190
160
  * @since 1.0.0
191
161
  */
192
162
  register(params: RegisterParams): Promise<ClientResult<LoginResponse>>;
193
163
 
194
164
  /**
195
165
  * Login with password
196
- *
166
+ *
197
167
  * Authenticates a user with username/email/phone and password.
198
168
  * On success, access token is automatically stored and attached to all subsequent requests.
199
- *
169
+ *
200
170
  * @param params - Login credentials
201
171
  * @returns User info and access token
202
- *
172
+ *
203
173
  * @example
204
174
  * // Login with email
205
175
  * const result = await client.auth.login({
206
176
  * email: 'user@example.com',
207
177
  * password: 'myPassword123'
208
178
  * });
209
- *
210
- * if (result.data) {
179
+ *
180
+ * if (result.success) {
211
181
  * console.log('Welcome,', result.data.user.displayName);
212
182
  * } else {
213
- * console.error('Login failed:', result.error?.message);
183
+ * console.error('Login failed:', result.error.message);
214
184
  * }
215
- *
185
+ *
216
186
  * @example
217
187
  * // Login with username
218
188
  * const result = await client.auth.login({
219
189
  * username: 'johndoe',
220
190
  * password: 'myPassword123'
221
191
  * });
222
- *
192
+ *
223
193
  * @example
224
194
  * // Login with phone
225
195
  * const result = await client.auth.login({
226
196
  * phone: '+1234567890',
227
197
  * password: 'myPassword123'
228
198
  * });
229
- *
199
+ *
230
200
  * @since 1.0.0
231
201
  */
232
202
  login(params: LoginParams): Promise<ClientResult<LoginResponse>>;
233
203
 
234
204
  /**
235
205
  * Change password
236
- *
206
+ *
237
207
  * Changes the password for the current user.
238
208
  * Requires the old password for verification.
239
- *
209
+ *
240
210
  * @param params - Old and new passwords
241
211
  * @returns Success status
242
- *
212
+ *
243
213
  * @example
244
214
  * const result = await client.auth.changePassword({
245
215
  * oldPassword: 'currentPass123',
246
216
  * newPassword: 'newSecurePass456'
247
217
  * });
248
- *
249
- * if (result.data) {
218
+ *
219
+ * if (result.success) {
250
220
  * console.log('Password changed successfully');
251
221
  * }
252
- *
222
+ *
253
223
  * @since 1.0.0
254
224
  */
255
225
  changePassword(params: ChangePasswordParams): Promise<ClientResult<SuccessResponse>>;
@@ -3,7 +3,7 @@
3
3
  * - Get current user information
4
4
  * - Update profile fields
5
5
  * - Avatar management
6
- *
6
+ *
7
7
  * @module auth/profile
8
8
  */
9
9
 
@@ -13,48 +13,52 @@ import type { User } from './user';
13
13
  // ==================== Parameters ====================
14
14
 
15
15
  /**
16
- * Update current user profile parameters
17
- *
16
+ * Update user profile parameters
17
+ *
18
18
  * All fields are optional - only update what you want to change.
19
+ *
19
20
  */
20
- export interface UpdateMeParams {
21
+ export interface UpdateProfileParams {
21
22
  /** New display name */
22
23
  displayName?: string;
23
-
24
+
24
25
  /** New avatar URL */
25
26
  avatarUrl?: string;
27
+
28
+ /** New email (may require verification) */
29
+ email?: string;
30
+
31
+ /** New phone (may require verification) */
32
+ phone?: string;
26
33
  }
27
34
 
28
- /**
29
- * @deprecated Use `UpdateMeParams`
30
- */
31
- export type UpdateProfileParams = UpdateMeParams;
32
-
33
35
  // ==================== API ====================
34
36
 
35
37
  /**
36
38
  * User Profile Management API
37
- *
39
+ *
38
40
  * Methods for managing user profile information.
39
41
  */
40
42
  export interface ProfileAPI {
41
43
  /**
42
44
  * Get current user information
43
- *
45
+ *
44
46
  * Retrieves the profile of the currently authenticated user.
45
- *
47
+ *
46
48
  * @returns Current user info with roles and permissions
49
+ *
47
50
  */
48
51
  getMe(): Promise<ClientResult<User>>;
49
52
 
50
53
  /**
51
- * Update current user profile
52
- *
54
+ * Update user profile
55
+ *
53
56
  * Updates one or more fields of the current user's profile.
54
57
  * Only the fields provided will be updated.
55
- *
58
+ *
56
59
  * @param params - Fields to update
57
60
  * @returns Updated user info
61
+ *
58
62
  */
59
- updateMe(params: UpdateMeParams): Promise<ClientResult<User>>;
63
+ updateProfile(params: UpdateProfileParams): Promise<ClientResult<User>>;
60
64
  }
@@ -3,115 +3,71 @@
3
3
  * - User profile information
4
4
  * - Role and permission types
5
5
  * - User status enums
6
- *
6
+ *
7
7
  * @module auth/user
8
8
  */
9
9
 
10
10
  /**
11
11
  * User information with optimized roles and permissions
12
- *
12
+ *
13
13
  * Roles and permissions are returned as simple string arrays for efficient client-side use:
14
14
  * - `roles`: ["admin", "user", "manager"]
15
15
  * - `permissions`: ["user.read", "user.write", "order.read"]
16
+ *
16
17
  */
17
18
  export interface User {
18
19
  /** Unique user identifier */
19
20
  uid: string;
20
-
21
+
21
22
  /** Username (null if not set) */
22
23
  username: string | null;
23
-
24
+
24
25
  /** Email address (null if not set) */
25
26
  email: string | null;
26
-
27
+
27
28
  /** Phone number (null if not set) */
28
29
  phone: string | null;
29
-
30
+
30
31
  /** Display name shown in UI */
31
32
  displayName: string | null;
32
-
33
+
33
34
  /** Avatar image URL */
34
35
  avatarUrl: string | null;
35
-
36
+
36
37
  /** Whether account is active */
37
38
  isActive: boolean;
38
-
39
+
39
40
  /** Whether email is verified */
40
41
  emailVerified: boolean;
41
-
42
+
42
43
  /** Whether phone is verified */
43
44
  phoneVerified: boolean;
44
-
45
+
45
46
  /** Email verification timestamp (ISO 8601) */
46
47
  emailVerifiedAt: string | null;
47
-
48
+
48
49
  /** Phone verification timestamp (ISO 8601) */
49
50
  phoneVerifiedAt: string | null;
50
-
51
- /**
51
+
52
+ /**
52
53
  * Role codes assigned to user
53
- *
54
+ *
54
55
  * Includes system roles and custom roles:
55
56
  * - System roles: "anonymous" (unauthenticated), "member" (default), "admin"
56
57
  * - Custom roles: defined in app.settings.yml
58
+ *
57
59
  */
58
60
  roles: string[];
59
-
60
- /**
61
+
62
+ /**
61
63
  * Permission names granted to user
62
64
  * Format: "resource.action"
63
65
  */
64
66
  permissions: string[];
65
-
67
+
66
68
  /** Account creation timestamp (ISO 8601) */
67
69
  createdAt: string;
68
-
70
+
69
71
  /** Last update timestamp (ISO 8601) */
70
72
  updatedAt: string;
71
73
  }
72
-
73
- /**
74
- * Detailed role information
75
- */
76
- export interface RoleDetail {
77
- id: number;
78
- code: string;
79
- displayName: string;
80
- description?: string;
81
- isSystem: boolean;
82
- }
83
-
84
- /**
85
- * Detailed permission information
86
- */
87
- export interface PermissionDetail {
88
- id: number;
89
- name: string;
90
- resource: string;
91
- action: string;
92
- description?: string;
93
- sourceType: 'system' | 'role' | 'direct';
94
- }
95
-
96
- /**
97
- * @deprecated Use string role codes from `User.roles`
98
- */
99
- export interface Role {
100
- id: number;
101
- code: string;
102
- displayName: string;
103
- description?: string;
104
- isSystem: boolean;
105
- }
106
-
107
- /**
108
- * @deprecated Use string permission names from `User.permissions`
109
- */
110
- export interface Permission {
111
- id: number;
112
- name: string;
113
- resource: string;
114
- action: string;
115
- description?: string;
116
- sourceType: 'system' | 'role' | 'direct';
117
- }