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