@bagelink/auth 1.4.169 → 1.4.174

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.
package/dist/index.d.mts CHANGED
@@ -2,35 +2,16 @@ import { AxiosResponse, AxiosInstance } from 'axios';
2
2
  import * as vue from 'vue';
3
3
  import { App } from 'vue';
4
4
 
5
- interface User {
6
- id: string;
7
- email: string;
8
- first_name?: string;
9
- last_name?: string;
10
- is_superuser?: boolean;
11
- is_active?: boolean;
12
- }
13
- interface UserRegister {
14
- email: string;
15
- password: string;
16
- first_name: string;
17
- last_name: string;
18
- }
19
- interface NewUser extends UserRegister {
20
- confirmPassword: string;
21
- }
22
- interface UpdatePasswordForm {
23
- current_password: string;
24
- new_password: string;
25
- confirmNewPassword: string;
26
- }
27
5
  declare enum AuthState {
28
6
  LOGIN = "login",
29
7
  LOGOUT = "logout",
30
8
  SIGNUP = "signup",
31
9
  PASSWORD_RESET = "password_reset",
10
+ PASSWORD_CHANGE = "password_change",
32
11
  PROFILE_UPDATE = "profile_update",
33
- AUTH_CHECK = "auth_check"
12
+ AUTH_CHECK = "auth_check",
13
+ EMAIL_VERIFIED = "email_verified",
14
+ SESSION_REFRESH = "session_refresh"
34
15
  }
35
16
  type AuthEventHandler = () => void;
36
17
  interface AuthEventMap {
@@ -38,84 +19,303 @@ interface AuthEventMap {
38
19
  [AuthState.LOGOUT]: AuthEventHandler;
39
20
  [AuthState.SIGNUP]: AuthEventHandler;
40
21
  [AuthState.PASSWORD_RESET]: AuthEventHandler;
22
+ [AuthState.PASSWORD_CHANGE]: AuthEventHandler;
41
23
  [AuthState.PROFILE_UPDATE]: AuthEventHandler;
42
24
  [AuthState.AUTH_CHECK]: AuthEventHandler;
25
+ [AuthState.EMAIL_VERIFIED]: AuthEventHandler;
26
+ [AuthState.SESSION_REFRESH]: AuthEventHandler;
43
27
  }
44
- interface Token {
45
- access_token: string;
28
+ type AuthenticationAccountType = 'person' | 'entity' | 'service';
29
+ type AuthenticationMethodType = 'password' | 'email_token' | 'sso' | 'otp';
30
+ interface AuthenticationAccount {
31
+ created_at?: string;
32
+ updated_at?: string;
33
+ account_type?: AuthenticationAccountType;
34
+ person_id?: string;
35
+ entity_id?: string;
36
+ display_name?: string;
37
+ is_active?: boolean;
38
+ is_verified?: boolean;
39
+ account_metadata?: string;
40
+ last_login_at?: string;
41
+ failed_login_attempts?: number;
42
+ locked_until?: string;
43
+ id: string;
46
44
  }
47
- interface PasswordRecovery {
48
- email: string;
45
+ interface PersonInfo {
46
+ id: string;
47
+ name: string;
48
+ email?: string;
49
+ roles: string[];
49
50
  }
50
- interface NewPassword {
51
- new_password: string;
51
+ interface AuthMethodInfo {
52
+ id: string;
53
+ type: string;
54
+ identifier?: string;
55
+ is_verified: boolean;
56
+ last_used?: string;
57
+ use_count: number;
52
58
  }
53
- interface UserUpdate {
54
- email?: string;
55
- is_active?: boolean;
56
- is_superuser?: boolean;
57
- first_name?: string;
58
- last_name?: string;
59
+ interface AccountInfo {
60
+ id: string;
61
+ account_type: string;
62
+ display_name: string;
63
+ is_active: boolean;
64
+ is_verified: boolean;
65
+ last_login?: string;
66
+ authentication_methods: AuthMethodInfo[];
67
+ person?: PersonInfo;
68
+ entity?: EntityInfo;
59
69
  }
60
- interface UserUpdateMe {
70
+ interface EntityInfo {
71
+ id: string;
72
+ name: string;
73
+ type?: string;
74
+ metadata?: Record<string, any>;
75
+ }
76
+ interface SessionInfo {
77
+ id: string;
78
+ created_at: string;
79
+ expires_at: string;
80
+ ip_address?: string;
81
+ user_agent?: string;
82
+ is_current?: boolean;
83
+ }
84
+ /**
85
+ * Unified user representation that works for both person and entity accounts
86
+ * This is the primary interface for accessing user data in the application
87
+ */
88
+ interface User {
89
+ /** Unique identifier (person_id or entity_id) */
90
+ id: string;
91
+ /** Account ID */
92
+ accountId: string;
93
+ /** Display name */
94
+ name: string;
95
+ /** Email address (from person or authentication methods) */
61
96
  email?: string;
97
+ /** Account type: 'person', 'entity', or 'service' */
98
+ type: AuthenticationAccountType;
99
+ /** User roles (only for person accounts) */
100
+ roles?: string[];
101
+ /** Is the account active */
102
+ isActive: boolean;
103
+ /** Is the account verified */
104
+ isVerified: boolean;
105
+ /** Last login timestamp */
106
+ lastLogin?: string;
107
+ /** Entity-specific info (only for entity accounts) */
108
+ entityType?: string;
109
+ /** Additional metadata */
110
+ metadata?: Record<string, any>;
111
+ }
112
+ interface RegisterRequest {
113
+ email: string;
114
+ first_name: string;
115
+ last_name: string;
116
+ phone_number?: string;
117
+ password?: string;
118
+ }
119
+ interface UpdateAccountRequest {
62
120
  first_name?: string;
63
121
  last_name?: string;
122
+ email?: string;
123
+ phone_number?: string;
64
124
  }
65
- interface UpdatePassword {
125
+ interface PasswordLoginRequest {
126
+ email: string;
127
+ password: string;
128
+ }
129
+ interface ChangePasswordRequest {
66
130
  current_password: string;
67
131
  new_password: string;
68
132
  }
69
- interface UserCreate {
133
+ interface ForgotPasswordRequest {
70
134
  email: string;
71
- password: string;
72
- first_name?: string;
73
- last_name?: string;
74
- is_active?: boolean;
75
- is_superuser?: boolean;
76
135
  }
77
- interface SanitizedUserOut {
78
- email: string;
79
- is_active?: boolean;
80
- is_superuser?: boolean;
81
- first_name?: string;
82
- last_name?: string;
83
- id: string;
136
+ interface ResetPasswordRequest {
137
+ token: string;
138
+ new_password: string;
84
139
  }
85
- interface SanitizedUserList {
86
- data: SanitizedUserOut[];
87
- count: number;
88
- }
89
- type LoginResponse = AxiosResponse<Token>;
90
- type PasswordRecoveryResponse = AxiosResponse;
91
- type ResetPasswordResponse = AxiosResponse;
92
- type GetUserResponse = AxiosResponse<SanitizedUserOut>;
93
- type UpdateUserResponse = AxiosResponse<SanitizedUserOut>;
94
- type DeleteUserResponse = AxiosResponse;
95
- type GetUsersResponse = AxiosResponse<SanitizedUserList>;
96
- type CreateUserResponse = AxiosResponse<SanitizedUserOut>;
97
- type GetMeResponse = AxiosResponse<SanitizedUserOut>;
98
- type UpdateMeResponse = AxiosResponse<SanitizedUserOut>;
99
- type UpdatePasswordResponse = AxiosResponse;
100
- type SignupResponse = AxiosResponse<SanitizedUserOut>;
140
+ interface SendVerificationRequest {
141
+ email?: string;
142
+ }
143
+ interface VerifyEmailRequest {
144
+ token: string;
145
+ }
146
+ interface NewUser extends RegisterRequest {
147
+ confirmPassword: string;
148
+ }
149
+ interface UpdatePasswordForm extends ChangePasswordRequest {
150
+ confirmNewPassword: string;
151
+ }
152
+ interface MessageResponse {
153
+ message: string;
154
+ }
155
+ interface AuthStatusResponse {
156
+ status: string;
157
+ methods: string[];
158
+ }
159
+ interface AvailableMethodsResponse {
160
+ available_methods: {
161
+ [key: string]: any;
162
+ }[];
163
+ }
164
+ interface OTPMetadata {
165
+ nonce: string;
166
+ verification_hash: string;
167
+ timestamp: number;
168
+ expires_in_minutes: number;
169
+ autofill: {
170
+ [key: string]: any;
171
+ };
172
+ }
173
+ interface SSOMetadata {
174
+ provider: string;
175
+ sso_user_info: {
176
+ [key: string]: any;
177
+ };
178
+ can_create_account?: boolean;
179
+ }
180
+ interface AuthenticationResponse {
181
+ success: boolean;
182
+ account_id?: string;
183
+ session_token?: string;
184
+ requires_verification?: boolean;
185
+ verification_method?: AuthenticationMethodType;
186
+ message?: string;
187
+ metadata?: OTPMetadata | SSOMetadata | {
188
+ [key: string]: any;
189
+ };
190
+ }
191
+ interface SessionListResponse {
192
+ account_id: string;
193
+ sessions: SessionInfo[];
194
+ }
195
+ type LoginResponse = AxiosResponse<AuthenticationResponse>;
196
+ type RegisterResponse = AxiosResponse<AuthenticationResponse>;
197
+ type LogoutResponse = AxiosResponse<MessageResponse>;
198
+ type GetMeResponse = AxiosResponse<AccountInfo>;
199
+ type UpdateMeResponse = AxiosResponse<AccountInfo>;
200
+ type DeleteMeResponse = AxiosResponse<MessageResponse>;
201
+ type GetAccountResponse = AxiosResponse<AccountInfo>;
202
+ type UpdateAccountResponse = AxiosResponse<AccountInfo>;
203
+ type DeleteAccountResponse = AxiosResponse<MessageResponse>;
204
+ type ActivateAccountResponse = AxiosResponse<AccountInfo>;
205
+ type DeactivateAccountResponse = AxiosResponse<AccountInfo>;
206
+ type ChangePasswordResponse = AxiosResponse<MessageResponse>;
207
+ type ForgotPasswordResponse = AxiosResponse<MessageResponse>;
208
+ type ResetPasswordResponse = AxiosResponse<MessageResponse>;
209
+ type VerifyResetTokenResponse = AxiosResponse<MessageResponse>;
210
+ type SendVerificationResponse = AxiosResponse<MessageResponse>;
211
+ type VerifyEmailResponse = AxiosResponse<MessageResponse>;
212
+ type RefreshSessionResponse = AxiosResponse<AuthenticationResponse>;
213
+ type GetSessionsResponse = AxiosResponse<SessionListResponse>;
214
+ type DeleteSessionResponse = AxiosResponse<MessageResponse>;
215
+ type DeleteAllSessionsResponse = AxiosResponse<MessageResponse>;
216
+ type CleanupSessionsResponse = AxiosResponse<MessageResponse>;
217
+ type GetMethodsResponse = AxiosResponse<AvailableMethodsResponse>;
218
+ /**
219
+ * Extract unified user from account info
220
+ */
221
+ declare function accountToUser(account: AccountInfo | null): User | null;
101
222
 
102
223
  declare class AuthApi {
103
224
  private api;
104
225
  constructor(axiosInstance?: AxiosInstance, baseURL?: string);
105
226
  private setupInterceptors;
106
- login(username: string, password: string): Promise<LoginResponse>;
107
- logout(): void;
108
- passwordRecovery(email?: string): Promise<PasswordRecoveryResponse>;
109
- resetPassword(newPassword: NewPassword['new_password']): Promise<ResetPasswordResponse>;
227
+ /**
228
+ * Get available authentication methods
229
+ */
230
+ getAuthMethods(): Promise<GetMethodsResponse>;
231
+ /**
232
+ * Register a new account
233
+ */
234
+ register(data: RegisterRequest): Promise<RegisterResponse>;
235
+ /**
236
+ * Login with password
237
+ */
238
+ login(email: string, password: string): Promise<LoginResponse>;
239
+ /**
240
+ * Logout and clear session
241
+ */
242
+ logout(): Promise<LogoutResponse>;
243
+ /**
244
+ * Refresh current session
245
+ */
246
+ refreshSession(): Promise<RefreshSessionResponse>;
247
+ /**
248
+ * Get current user account info
249
+ */
110
250
  getCurrentUser(): Promise<GetMeResponse>;
111
- signup(user: NewUser): Promise<SignupResponse>;
112
- updatePassword(form: UpdatePasswordForm): Promise<UpdatePasswordResponse>;
113
- updateUserProfile(user: Partial<User>): Promise<UpdateMeResponse>;
114
- setUserStatus(userId: string, isActive: boolean): Promise<UpdateUserResponse>;
115
- deleteUser(userId: string): Promise<DeleteUserResponse>;
116
- getUsers(limit?: number, skip?: number): Promise<GetUsersResponse>;
117
- createUser(user: UserCreate): Promise<CreateUserResponse>;
118
- getUser(userId: string): Promise<GetUserResponse>;
251
+ /**
252
+ * Update current user profile
253
+ */
254
+ updateCurrentUser(data: UpdateAccountRequest): Promise<UpdateMeResponse>;
255
+ /**
256
+ * Delete current user account
257
+ */
258
+ deleteCurrentUser(): Promise<DeleteMeResponse>;
259
+ /**
260
+ * Get account information by ID
261
+ */
262
+ getAccount(accountId: string): Promise<GetAccountResponse>;
263
+ /**
264
+ * Update account by ID
265
+ */
266
+ updateAccount(accountId: string, data: UpdateAccountRequest): Promise<UpdateAccountResponse>;
267
+ /**
268
+ * Delete account by ID
269
+ */
270
+ deleteAccount(accountId: string): Promise<DeleteAccountResponse>;
271
+ /**
272
+ * Activate account by ID
273
+ */
274
+ activateAccount(accountId: string): Promise<ActivateAccountResponse>;
275
+ /**
276
+ * Deactivate account by ID
277
+ */
278
+ deactivateAccount(accountId: string): Promise<DeactivateAccountResponse>;
279
+ /**
280
+ * Change password (requires current password)
281
+ */
282
+ changePassword(data: ChangePasswordRequest): Promise<ChangePasswordResponse>;
283
+ /**
284
+ * Initiate forgot password flow
285
+ */
286
+ forgotPassword(email: string): Promise<ForgotPasswordResponse>;
287
+ /**
288
+ * Verify password reset token
289
+ */
290
+ verifyResetToken(token: string): Promise<VerifyResetTokenResponse>;
291
+ /**
292
+ * Reset password with token
293
+ */
294
+ resetPassword(data: ResetPasswordRequest): Promise<ResetPasswordResponse>;
295
+ /**
296
+ * Send email verification
297
+ */
298
+ sendVerification(data?: SendVerificationRequest, user?: AuthenticationAccount): Promise<SendVerificationResponse>;
299
+ /**
300
+ * Verify email with token
301
+ */
302
+ verifyEmail(token: string): Promise<VerifyEmailResponse>;
303
+ /**
304
+ * Get sessions for an account
305
+ */
306
+ getSessions(accountId: string): Promise<GetSessionsResponse>;
307
+ /**
308
+ * Revoke a specific session
309
+ */
310
+ revokeSession(sessionToken: string): Promise<DeleteSessionResponse>;
311
+ /**
312
+ * Revoke all sessions for an account
313
+ */
314
+ revokeAllSessions(accountId: string): Promise<DeleteAllSessionsResponse>;
315
+ /**
316
+ * Cleanup expired sessions (admin)
317
+ */
318
+ cleanupSessions(): Promise<CleanupSessionsResponse>;
119
319
  }
120
320
 
121
321
  declare function initAuth({ axios, baseURL, }: {
@@ -128,37 +328,92 @@ declare function initAuth({ axios, baseURL, }: {
128
328
  install(app: App): void;
129
329
  };
130
330
  declare function useAuth(): {
131
- currentUser: vue.Ref<{
331
+ user: vue.ComputedRef<User | null>;
332
+ accountInfo: vue.Ref<{
132
333
  id: string;
133
- email: string;
134
- first_name?: string | undefined;
135
- last_name?: string | undefined;
136
- is_superuser?: boolean | undefined;
137
- is_active?: boolean | undefined;
138
- }, User | {
334
+ account_type: string;
335
+ display_name: string;
336
+ is_active: boolean;
337
+ is_verified: boolean;
338
+ last_login?: string | undefined;
339
+ authentication_methods: {
340
+ id: string;
341
+ type: string;
342
+ identifier?: string | undefined;
343
+ is_verified: boolean;
344
+ last_used?: string | undefined;
345
+ use_count: number;
346
+ }[];
347
+ person?: {
348
+ id: string;
349
+ name: string;
350
+ email?: string | undefined;
351
+ roles: string[];
352
+ } | undefined;
353
+ entity?: {
354
+ id: string;
355
+ name: string;
356
+ type?: string | undefined;
357
+ metadata?: Record<string, any> | undefined;
358
+ } | undefined;
359
+ } | null, AccountInfo | {
139
360
  id: string;
140
- email: string;
141
- first_name?: string | undefined;
142
- last_name?: string | undefined;
143
- is_superuser?: boolean | undefined;
144
- is_active?: boolean | undefined;
145
- }>;
361
+ account_type: string;
362
+ display_name: string;
363
+ is_active: boolean;
364
+ is_verified: boolean;
365
+ last_login?: string | undefined;
366
+ authentication_methods: {
367
+ id: string;
368
+ type: string;
369
+ identifier?: string | undefined;
370
+ is_verified: boolean;
371
+ last_used?: string | undefined;
372
+ use_count: number;
373
+ }[];
374
+ person?: {
375
+ id: string;
376
+ name: string;
377
+ email?: string | undefined;
378
+ roles: string[];
379
+ } | undefined;
380
+ entity?: {
381
+ id: string;
382
+ name: string;
383
+ type?: string | undefined;
384
+ metadata?: Record<string, any> | undefined;
385
+ } | undefined;
386
+ } | null>;
146
387
  getFullName: () => string;
147
388
  getIsLoggedIn: () => boolean;
148
- logout: () => Promise<void>;
389
+ getEmail: () => string;
390
+ getRoles: () => string[];
391
+ getAccountType: () => AuthenticationAccountType;
392
+ isPersonAccount: () => boolean;
393
+ isEntityAccount: () => boolean;
149
394
  login: (credentials: {
150
395
  email: string;
151
396
  password: string;
152
- }) => Promise<void>;
397
+ }) => Promise<AuthenticationResponse>;
398
+ logout: () => Promise<void>;
399
+ signup: (newUser: NewUser) => Promise<AuthenticationResponse>;
153
400
  checkAuth: () => Promise<boolean>;
154
- signup: (user: NewUser) => Promise<void>;
155
- recoverPassword: (email: string) => Promise<void>;
156
- resetPassword: (newPassword: string) => Promise<void>;
157
- updatePassword: (form: UpdatePasswordForm) => Promise<void>;
158
- updateProfile: (user: Partial<User>) => Promise<void>;
159
- toggleUserStatus: (userId: string, isActive: boolean) => Promise<void>;
160
- deleteUser: (userId: string) => Promise<void>;
401
+ refreshSession: () => Promise<void>;
402
+ updateProfile: (updates: UpdateAccountRequest) => Promise<void>;
403
+ deleteCurrentUser: () => Promise<void>;
404
+ changePassword: (form: UpdatePasswordForm) => Promise<void>;
405
+ forgotPassword: (email: string) => Promise<void>;
406
+ verifyResetToken: (token: string) => Promise<void>;
407
+ resetPassword: (token: string, newPassword: string) => Promise<void>;
408
+ sendVerification: (email?: string) => Promise<void>;
409
+ verifyEmail: (token: string) => Promise<void>;
410
+ activateAccount: (accountId: string) => Promise<void>;
411
+ deactivateAccount: (accountId: string) => Promise<void>;
412
+ deleteAccount: (accountId: string) => Promise<void>;
413
+ getSessions: (accountId?: string) => Promise<GetSessionsResponse>;
414
+ revokeSession: (sessionToken: string) => Promise<void>;
415
+ revokeAllSessions: (accountId?: string) => Promise<void>;
161
416
  };
162
417
 
163
- export { AuthApi, AuthState, initAuth, useAuth };
164
- export type { AuthEventHandler, AuthEventMap, CreateUserResponse, DeleteUserResponse, GetMeResponse, GetUserResponse, GetUsersResponse, LoginResponse, NewPassword, NewUser, PasswordRecovery, PasswordRecoveryResponse, ResetPasswordResponse, SanitizedUserList, SanitizedUserOut, SignupResponse, Token, UpdateMeResponse, UpdatePassword, UpdatePasswordForm, UpdatePasswordResponse, UpdateUserResponse, User, UserCreate, UserRegister, UserUpdate, UserUpdateMe };
418
+ export { AuthApi, AuthState, accountToUser, initAuth, useAuth };
419
+ export type { AccountInfo, ActivateAccountResponse, AuthEventHandler, AuthEventMap, AuthMethodInfo, AuthStatusResponse, AuthenticationAccount, AuthenticationAccountType, AuthenticationMethodType, AuthenticationResponse, AvailableMethodsResponse, ChangePasswordRequest, ChangePasswordResponse, CleanupSessionsResponse, DeactivateAccountResponse, DeleteAccountResponse, DeleteAllSessionsResponse, DeleteMeResponse, DeleteSessionResponse, EntityInfo, ForgotPasswordRequest, ForgotPasswordResponse, GetAccountResponse, GetMeResponse, GetMethodsResponse, GetSessionsResponse, LoginResponse, LogoutResponse, MessageResponse, NewUser, OTPMetadata, PasswordLoginRequest, PersonInfo, RefreshSessionResponse, RegisterRequest, RegisterResponse, ResetPasswordRequest, ResetPasswordResponse, SSOMetadata, SendVerificationRequest, SendVerificationResponse, SessionInfo, SessionListResponse, UpdateAccountRequest, UpdateAccountResponse, UpdateMeResponse, UpdatePasswordForm, User, VerifyEmailRequest, VerifyEmailResponse, VerifyResetTokenResponse };