@amaster.ai/auth-client 1.0.0-beta.5 → 1.0.0-beta.72

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.
@@ -22,20 +22,24 @@
22
22
  * @example
23
23
  * Minimal configuration (recommended):
24
24
  * ```typescript
25
- * const options: AuthClientOptions = {
25
+ * const authClient = createAuthClient();
26
+ * ```
27
+ *
28
+ * @example
29
+ * With callbacks:
30
+ * ```typescript
31
+ * const authClient = createAuthClient({
26
32
  * onTokenExpired: () => window.location.href = "/login",
27
- * };
33
+ * onUnauthorized: () => alert("Session expired"),
34
+ * });
28
35
  * ```
29
36
  *
30
37
  * @example
31
- * Full configuration:
38
+ * With custom base URL:
32
39
  * ```typescript
33
- * const options: AuthClientOptions = {
40
+ * const authClient = createAuthClient({
34
41
  * baseURL: "https://api.example.com",
35
- * storage: "sessionStorage",
36
- * onTokenExpired: () => handleTokenExpired(),
37
- * onUnauthorized: () => handleUnauthorized(),
38
- * };
42
+ * });
39
43
  * ```
40
44
  */
41
45
  interface AuthClientOptions {
@@ -50,12 +54,6 @@ interface AuthClientOptions {
50
54
  * @example { "x-tenant-id": "tenant123", "x-api-key": "key123" }
51
55
  */
52
56
  headers?: Record<string, string>;
53
- /**
54
- * Token storage type (defaults to "localStorage")
55
- * - localStorage: Persistent across browser sessions
56
- * - sessionStorage: Cleared when browser tab closes
57
- */
58
- storage?: "localStorage" | "sessionStorage";
59
57
  /**
60
58
  * Callback when token expires
61
59
  * @example () => window.location.href = "/login"
@@ -66,6 +64,35 @@ interface AuthClientOptions {
66
64
  * @example () => alert("Session expired")
67
65
  */
68
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
+ * Automatically redirect to the current page's `?redirect=...` target after any successful login
88
+ *
89
+ * This applies to password login, code login, registration auto-login, mini-program login,
90
+ * and OAuth callback processing. Set to `false` if your application wants to fully control
91
+ * post-login navigation.
92
+ *
93
+ * @default true
94
+ */
95
+ autoRedirectAfterLogin?: boolean;
69
96
  }
70
97
  /**
71
98
  * User information with roles and permissions
@@ -73,7 +100,7 @@ interface AuthClientOptions {
73
100
  * Note: This is an optimized format for client-side use.
74
101
  * - roles: Only role codes (e.g., ["admin", "user"])
75
102
  * - permissions: Only permission names (e.g., ["user.read", "user.write"])
76
- * - dataScopes: Not included, use getPermissionScope() to load on-demand
103
+ * - dataScopes: Not included
77
104
  *
78
105
  * @example
79
106
  * ```typescript
@@ -164,46 +191,6 @@ interface Permission {
164
191
  description?: string;
165
192
  sourceType: "system" | "role" | "direct";
166
193
  }
167
- /**
168
- * Data scope defining what data a user can access for a permission
169
- *
170
- * @example
171
- * All data:
172
- * ```typescript
173
- * { scopeType: "all", scopeFilter: null }
174
- * ```
175
- *
176
- * @example
177
- * Department-scoped:
178
- * ```typescript
179
- * {
180
- * scopeType: "department",
181
- * scopeFilter: { departmentId: 123 }
182
- * }
183
- * ```
184
- *
185
- * @example
186
- * Self only:
187
- * ```typescript
188
- * { scopeType: "self", scopeFilter: null }
189
- * ```
190
- */
191
- interface DataScope {
192
- /**
193
- * Type of data scope:
194
- * - "all": User can access all data
195
- * - "organization": User can access data in their organization
196
- * - "department": User can access data in their department
197
- * - "self": User can only access their own data
198
- * - "custom": Custom filter defined in scopeFilter
199
- */
200
- scopeType: "all" | "organization" | "department" | "self" | "custom";
201
- /**
202
- * Custom filter conditions (used when scopeType="custom")
203
- * @example { departmentId: 123, regionId: 456 }
204
- */
205
- scopeFilter: any;
206
- }
207
194
  /**
208
195
  * User registration parameters
209
196
  * At least one of username/email/phone must be provided
@@ -343,8 +330,6 @@ interface LoginResponse {
343
330
  user: User;
344
331
  /** Access token (JWT) for API authentication */
345
332
  accessToken: string;
346
- /** Refresh token for obtaining new access tokens */
347
- refreshToken?: string;
348
333
  /** Token expiration time in seconds */
349
334
  expiresIn?: number;
350
335
  }
@@ -405,7 +390,15 @@ interface ChangePasswordParams {
405
390
  oldPassword: string;
406
391
  newPassword: string;
407
392
  }
408
- type OAuthProvider = "google" | "github" | "wechat" | "platform";
393
+ /**
394
+ * OAuth provider types
395
+ * - google: Google OAuth
396
+ * - github: GitHub OAuth
397
+ * - wechat: WeChat Open Platform OAuth (for web/mobile apps)
398
+ * - wechat_mini: WeChat Mini Program login
399
+ * - platform: AMaster Platform OAuth
400
+ */
401
+ type OAuthProvider = "google" | "github" | "wechat" | "wechat_mini" | "platform";
409
402
  interface OAuthBinding {
410
403
  provider: OAuthProvider;
411
404
  providerId: string;
@@ -414,6 +407,15 @@ interface OAuthBinding {
414
407
  avatarUrl: string | null;
415
408
  createdAt: string;
416
409
  }
410
+ /**
411
+ * WeChat Mini Program phone number response
412
+ */
413
+ interface MiniProgramPhoneResponse {
414
+ /** Phone number with country code (e.g., "+8613800138000") */
415
+ phone: string;
416
+ /** Whether the phone number is verified by WeChat */
417
+ phoneVerified: boolean;
418
+ }
417
419
  /**
418
420
  * Session information for multi-device management
419
421
  *
@@ -485,16 +487,5 @@ interface RevokeAllSessionsResponse {
485
487
  timestamp?: string;
486
488
  revokedCount: number;
487
489
  }
488
- interface CheckPermissionResponse {
489
- hasPermission: boolean;
490
- dataScope?: DataScope;
491
- }
492
- interface BatchCheckPermissionsResponse {
493
- [permission: string]: boolean;
494
- }
495
- interface PermissionScopeResponse {
496
- permission: string;
497
- dataScope: DataScope;
498
- }
499
490
 
500
- export type { AuthClientOptions as A, BatchCheckPermissionsResponse as B, ChangePasswordParams as C, DataScope as D, EventHandler as E, LoginParams as L, OAuthBinding as O, Permission as P, RefreshTokenResponse as R, SendCodeParams as S, UpdateMeParams as U, AuthEvent as a, CaptchaResponse as b, CheckPermissionResponse as c, CodeLoginParams as d, CodeLoginType as e, LoginResponse as f, LoginType as g, OAuthProvider as h, PermissionDetail as i, PermissionScopeResponse as j, RegisterParams as k, RegisterResponse as l, RevokeAllSessionsResponse as m, Role as n, RoleDetail as o, SendCodeType as p, Session as q, SuccessResponse as r, User as s };
491
+ 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 };
@@ -22,20 +22,24 @@
22
22
  * @example
23
23
  * Minimal configuration (recommended):
24
24
  * ```typescript
25
- * const options: AuthClientOptions = {
25
+ * const authClient = createAuthClient();
26
+ * ```
27
+ *
28
+ * @example
29
+ * With callbacks:
30
+ * ```typescript
31
+ * const authClient = createAuthClient({
26
32
  * onTokenExpired: () => window.location.href = "/login",
27
- * };
33
+ * onUnauthorized: () => alert("Session expired"),
34
+ * });
28
35
  * ```
29
36
  *
30
37
  * @example
31
- * Full configuration:
38
+ * With custom base URL:
32
39
  * ```typescript
33
- * const options: AuthClientOptions = {
40
+ * const authClient = createAuthClient({
34
41
  * baseURL: "https://api.example.com",
35
- * storage: "sessionStorage",
36
- * onTokenExpired: () => handleTokenExpired(),
37
- * onUnauthorized: () => handleUnauthorized(),
38
- * };
42
+ * });
39
43
  * ```
40
44
  */
41
45
  interface AuthClientOptions {
@@ -50,12 +54,6 @@ interface AuthClientOptions {
50
54
  * @example { "x-tenant-id": "tenant123", "x-api-key": "key123" }
51
55
  */
52
56
  headers?: Record<string, string>;
53
- /**
54
- * Token storage type (defaults to "localStorage")
55
- * - localStorage: Persistent across browser sessions
56
- * - sessionStorage: Cleared when browser tab closes
57
- */
58
- storage?: "localStorage" | "sessionStorage";
59
57
  /**
60
58
  * Callback when token expires
61
59
  * @example () => window.location.href = "/login"
@@ -66,6 +64,35 @@ interface AuthClientOptions {
66
64
  * @example () => alert("Session expired")
67
65
  */
68
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
+ * Automatically redirect to the current page's `?redirect=...` target after any successful login
88
+ *
89
+ * This applies to password login, code login, registration auto-login, mini-program login,
90
+ * and OAuth callback processing. Set to `false` if your application wants to fully control
91
+ * post-login navigation.
92
+ *
93
+ * @default true
94
+ */
95
+ autoRedirectAfterLogin?: boolean;
69
96
  }
70
97
  /**
71
98
  * User information with roles and permissions
@@ -73,7 +100,7 @@ interface AuthClientOptions {
73
100
  * Note: This is an optimized format for client-side use.
74
101
  * - roles: Only role codes (e.g., ["admin", "user"])
75
102
  * - permissions: Only permission names (e.g., ["user.read", "user.write"])
76
- * - dataScopes: Not included, use getPermissionScope() to load on-demand
103
+ * - dataScopes: Not included
77
104
  *
78
105
  * @example
79
106
  * ```typescript
@@ -164,46 +191,6 @@ interface Permission {
164
191
  description?: string;
165
192
  sourceType: "system" | "role" | "direct";
166
193
  }
167
- /**
168
- * Data scope defining what data a user can access for a permission
169
- *
170
- * @example
171
- * All data:
172
- * ```typescript
173
- * { scopeType: "all", scopeFilter: null }
174
- * ```
175
- *
176
- * @example
177
- * Department-scoped:
178
- * ```typescript
179
- * {
180
- * scopeType: "department",
181
- * scopeFilter: { departmentId: 123 }
182
- * }
183
- * ```
184
- *
185
- * @example
186
- * Self only:
187
- * ```typescript
188
- * { scopeType: "self", scopeFilter: null }
189
- * ```
190
- */
191
- interface DataScope {
192
- /**
193
- * Type of data scope:
194
- * - "all": User can access all data
195
- * - "organization": User can access data in their organization
196
- * - "department": User can access data in their department
197
- * - "self": User can only access their own data
198
- * - "custom": Custom filter defined in scopeFilter
199
- */
200
- scopeType: "all" | "organization" | "department" | "self" | "custom";
201
- /**
202
- * Custom filter conditions (used when scopeType="custom")
203
- * @example { departmentId: 123, regionId: 456 }
204
- */
205
- scopeFilter: any;
206
- }
207
194
  /**
208
195
  * User registration parameters
209
196
  * At least one of username/email/phone must be provided
@@ -343,8 +330,6 @@ interface LoginResponse {
343
330
  user: User;
344
331
  /** Access token (JWT) for API authentication */
345
332
  accessToken: string;
346
- /** Refresh token for obtaining new access tokens */
347
- refreshToken?: string;
348
333
  /** Token expiration time in seconds */
349
334
  expiresIn?: number;
350
335
  }
@@ -405,7 +390,15 @@ interface ChangePasswordParams {
405
390
  oldPassword: string;
406
391
  newPassword: string;
407
392
  }
408
- type OAuthProvider = "google" | "github" | "wechat" | "platform";
393
+ /**
394
+ * OAuth provider types
395
+ * - google: Google OAuth
396
+ * - github: GitHub OAuth
397
+ * - wechat: WeChat Open Platform OAuth (for web/mobile apps)
398
+ * - wechat_mini: WeChat Mini Program login
399
+ * - platform: AMaster Platform OAuth
400
+ */
401
+ type OAuthProvider = "google" | "github" | "wechat" | "wechat_mini" | "platform";
409
402
  interface OAuthBinding {
410
403
  provider: OAuthProvider;
411
404
  providerId: string;
@@ -414,6 +407,15 @@ interface OAuthBinding {
414
407
  avatarUrl: string | null;
415
408
  createdAt: string;
416
409
  }
410
+ /**
411
+ * WeChat Mini Program phone number response
412
+ */
413
+ interface MiniProgramPhoneResponse {
414
+ /** Phone number with country code (e.g., "+8613800138000") */
415
+ phone: string;
416
+ /** Whether the phone number is verified by WeChat */
417
+ phoneVerified: boolean;
418
+ }
417
419
  /**
418
420
  * Session information for multi-device management
419
421
  *
@@ -485,16 +487,5 @@ interface RevokeAllSessionsResponse {
485
487
  timestamp?: string;
486
488
  revokedCount: number;
487
489
  }
488
- interface CheckPermissionResponse {
489
- hasPermission: boolean;
490
- dataScope?: DataScope;
491
- }
492
- interface BatchCheckPermissionsResponse {
493
- [permission: string]: boolean;
494
- }
495
- interface PermissionScopeResponse {
496
- permission: string;
497
- dataScope: DataScope;
498
- }
499
490
 
500
- export type { AuthClientOptions as A, BatchCheckPermissionsResponse as B, ChangePasswordParams as C, DataScope as D, EventHandler as E, LoginParams as L, OAuthBinding as O, Permission as P, RefreshTokenResponse as R, SendCodeParams as S, UpdateMeParams as U, AuthEvent as a, CaptchaResponse as b, CheckPermissionResponse as c, CodeLoginParams as d, CodeLoginType as e, LoginResponse as f, LoginType as g, OAuthProvider as h, PermissionDetail as i, PermissionScopeResponse as j, RegisterParams as k, RegisterResponse as l, RevokeAllSessionsResponse as m, Role as n, RoleDetail as o, SendCodeType as p, Session as q, SuccessResponse as r, User as s };
491
+ 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 };
package/dist/user.d.cts CHANGED
@@ -14,7 +14,7 @@
14
14
  * ============================================================================
15
15
  */
16
16
  import { HttpClient, ClientResult } from '@amaster.ai/http-client';
17
- import { s as User, U as UpdateMeParams, C as ChangePasswordParams, r as SuccessResponse } from './types-CsOvCspq.cjs';
17
+ import { q as User, U as UpdateMeParams, C as ChangePasswordParams, p as SuccessResponse } from './types-DGF9cpAg.cjs';
18
18
 
19
19
  /**
20
20
  * User Management Module
package/dist/user.d.ts CHANGED
@@ -14,7 +14,7 @@
14
14
  * ============================================================================
15
15
  */
16
16
  import { HttpClient, ClientResult } from '@amaster.ai/http-client';
17
- import { s as User, U as UpdateMeParams, C as ChangePasswordParams, r as SuccessResponse } from './types-CsOvCspq.js';
17
+ import { q as User, U as UpdateMeParams, C as ChangePasswordParams, p as SuccessResponse } from './types-DGF9cpAg.js';
18
18
 
19
19
  /**
20
20
  * User Management Module
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amaster.ai/auth-client",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.0-beta.72",
4
4
  "description": "Authentication SDK for Amaster platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -47,7 +47,7 @@
47
47
  "registry": "https://registry.npmjs.org/"
48
48
  },
49
49
  "dependencies": {
50
- "@amaster.ai/http-client": "1.0.0-beta.6"
50
+ "@amaster.ai/http-client": "1.0.0-beta.72"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "axios": "^1.11.0"