@amaster.ai/auth-client 1.0.0-beta.6 → 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 {
@@ -45,11 +49,11 @@ interface AuthClientOptions {
45
49
  */
46
50
  baseURL?: string;
47
51
  /**
48
- * Token storage type (defaults to "localStorage")
49
- * - localStorage: Persistent across browser sessions
50
- * - sessionStorage: Cleared when browser tab closes
52
+ * Default headers to include in all requests
53
+ * Useful for adding tenant IDs, API keys, or other common headers
54
+ * @example { "x-tenant-id": "tenant123", "x-api-key": "key123" }
51
55
  */
52
- storage?: "localStorage" | "sessionStorage";
56
+ headers?: Record<string, string>;
53
57
  /**
54
58
  * Callback when token expires
55
59
  * @example () => window.location.href = "/login"
@@ -60,6 +64,35 @@ interface AuthClientOptions {
60
64
  * @example () => alert("Session expired")
61
65
  */
62
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;
63
96
  }
64
97
  /**
65
98
  * User information with roles and permissions
@@ -67,7 +100,7 @@ interface AuthClientOptions {
67
100
  * Note: This is an optimized format for client-side use.
68
101
  * - roles: Only role codes (e.g., ["admin", "user"])
69
102
  * - permissions: Only permission names (e.g., ["user.read", "user.write"])
70
- * - dataScopes: Not included, use getPermissionScope() to load on-demand
103
+ * - dataScopes: Not included
71
104
  *
72
105
  * @example
73
106
  * ```typescript
@@ -158,46 +191,6 @@ interface Permission {
158
191
  description?: string;
159
192
  sourceType: "system" | "role" | "direct";
160
193
  }
161
- /**
162
- * Data scope defining what data a user can access for a permission
163
- *
164
- * @example
165
- * All data:
166
- * ```typescript
167
- * { scopeType: "all", scopeFilter: null }
168
- * ```
169
- *
170
- * @example
171
- * Department-scoped:
172
- * ```typescript
173
- * {
174
- * scopeType: "department",
175
- * scopeFilter: { departmentId: 123 }
176
- * }
177
- * ```
178
- *
179
- * @example
180
- * Self only:
181
- * ```typescript
182
- * { scopeType: "self", scopeFilter: null }
183
- * ```
184
- */
185
- interface DataScope {
186
- /**
187
- * Type of data scope:
188
- * - "all": User can access all data
189
- * - "organization": User can access data in their organization
190
- * - "department": User can access data in their department
191
- * - "self": User can only access their own data
192
- * - "custom": Custom filter defined in scopeFilter
193
- */
194
- scopeType: "all" | "organization" | "department" | "self" | "custom";
195
- /**
196
- * Custom filter conditions (used when scopeType="custom")
197
- * @example { departmentId: 123, regionId: 456 }
198
- */
199
- scopeFilter: any;
200
- }
201
194
  /**
202
195
  * User registration parameters
203
196
  * At least one of username/email/phone must be provided
@@ -337,8 +330,6 @@ interface LoginResponse {
337
330
  user: User;
338
331
  /** Access token (JWT) for API authentication */
339
332
  accessToken: string;
340
- /** Refresh token for obtaining new access tokens */
341
- refreshToken?: string;
342
333
  /** Token expiration time in seconds */
343
334
  expiresIn?: number;
344
335
  }
@@ -399,7 +390,15 @@ interface ChangePasswordParams {
399
390
  oldPassword: string;
400
391
  newPassword: string;
401
392
  }
402
- 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";
403
402
  interface OAuthBinding {
404
403
  provider: OAuthProvider;
405
404
  providerId: string;
@@ -408,6 +407,15 @@ interface OAuthBinding {
408
407
  avatarUrl: string | null;
409
408
  createdAt: string;
410
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
+ }
411
419
  /**
412
420
  * Session information for multi-device management
413
421
  *
@@ -479,16 +487,5 @@ interface RevokeAllSessionsResponse {
479
487
  timestamp?: string;
480
488
  revokedCount: number;
481
489
  }
482
- interface CheckPermissionResponse {
483
- hasPermission: boolean;
484
- dataScope?: DataScope;
485
- }
486
- interface BatchCheckPermissionsResponse {
487
- [permission: string]: boolean;
488
- }
489
- interface PermissionScopeResponse {
490
- permission: string;
491
- dataScope: DataScope;
492
- }
493
490
 
494
- 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 {
@@ -45,11 +49,11 @@ interface AuthClientOptions {
45
49
  */
46
50
  baseURL?: string;
47
51
  /**
48
- * Token storage type (defaults to "localStorage")
49
- * - localStorage: Persistent across browser sessions
50
- * - sessionStorage: Cleared when browser tab closes
52
+ * Default headers to include in all requests
53
+ * Useful for adding tenant IDs, API keys, or other common headers
54
+ * @example { "x-tenant-id": "tenant123", "x-api-key": "key123" }
51
55
  */
52
- storage?: "localStorage" | "sessionStorage";
56
+ headers?: Record<string, string>;
53
57
  /**
54
58
  * Callback when token expires
55
59
  * @example () => window.location.href = "/login"
@@ -60,6 +64,35 @@ interface AuthClientOptions {
60
64
  * @example () => alert("Session expired")
61
65
  */
62
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;
63
96
  }
64
97
  /**
65
98
  * User information with roles and permissions
@@ -67,7 +100,7 @@ interface AuthClientOptions {
67
100
  * Note: This is an optimized format for client-side use.
68
101
  * - roles: Only role codes (e.g., ["admin", "user"])
69
102
  * - permissions: Only permission names (e.g., ["user.read", "user.write"])
70
- * - dataScopes: Not included, use getPermissionScope() to load on-demand
103
+ * - dataScopes: Not included
71
104
  *
72
105
  * @example
73
106
  * ```typescript
@@ -158,46 +191,6 @@ interface Permission {
158
191
  description?: string;
159
192
  sourceType: "system" | "role" | "direct";
160
193
  }
161
- /**
162
- * Data scope defining what data a user can access for a permission
163
- *
164
- * @example
165
- * All data:
166
- * ```typescript
167
- * { scopeType: "all", scopeFilter: null }
168
- * ```
169
- *
170
- * @example
171
- * Department-scoped:
172
- * ```typescript
173
- * {
174
- * scopeType: "department",
175
- * scopeFilter: { departmentId: 123 }
176
- * }
177
- * ```
178
- *
179
- * @example
180
- * Self only:
181
- * ```typescript
182
- * { scopeType: "self", scopeFilter: null }
183
- * ```
184
- */
185
- interface DataScope {
186
- /**
187
- * Type of data scope:
188
- * - "all": User can access all data
189
- * - "organization": User can access data in their organization
190
- * - "department": User can access data in their department
191
- * - "self": User can only access their own data
192
- * - "custom": Custom filter defined in scopeFilter
193
- */
194
- scopeType: "all" | "organization" | "department" | "self" | "custom";
195
- /**
196
- * Custom filter conditions (used when scopeType="custom")
197
- * @example { departmentId: 123, regionId: 456 }
198
- */
199
- scopeFilter: any;
200
- }
201
194
  /**
202
195
  * User registration parameters
203
196
  * At least one of username/email/phone must be provided
@@ -337,8 +330,6 @@ interface LoginResponse {
337
330
  user: User;
338
331
  /** Access token (JWT) for API authentication */
339
332
  accessToken: string;
340
- /** Refresh token for obtaining new access tokens */
341
- refreshToken?: string;
342
333
  /** Token expiration time in seconds */
343
334
  expiresIn?: number;
344
335
  }
@@ -399,7 +390,15 @@ interface ChangePasswordParams {
399
390
  oldPassword: string;
400
391
  newPassword: string;
401
392
  }
402
- 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";
403
402
  interface OAuthBinding {
404
403
  provider: OAuthProvider;
405
404
  providerId: string;
@@ -408,6 +407,15 @@ interface OAuthBinding {
408
407
  avatarUrl: string | null;
409
408
  createdAt: string;
410
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
+ }
411
419
  /**
412
420
  * Session information for multi-device management
413
421
  *
@@ -479,16 +487,5 @@ interface RevokeAllSessionsResponse {
479
487
  timestamp?: string;
480
488
  revokedCount: number;
481
489
  }
482
- interface CheckPermissionResponse {
483
- hasPermission: boolean;
484
- dataScope?: DataScope;
485
- }
486
- interface BatchCheckPermissionsResponse {
487
- [permission: string]: boolean;
488
- }
489
- interface PermissionScopeResponse {
490
- permission: string;
491
- dataScope: DataScope;
492
- }
493
490
 
494
- 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-Bgi_Lwkp.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-Bgi_Lwkp.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.6",
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"