@bagelink/auth 1.4.169 → 1.4.171

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.ts 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,272 @@ 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;
59
68
  }
60
- interface UserUpdateMe {
61
- email?: string;
69
+ interface SessionInfo {
70
+ id: string;
71
+ created_at: string;
72
+ expires_at: string;
73
+ ip_address?: string;
74
+ user_agent?: string;
75
+ is_current?: boolean;
76
+ }
77
+ interface RegisterRequest {
78
+ email: string;
79
+ first_name: string;
80
+ last_name: string;
81
+ phone_number?: string;
82
+ password?: string;
83
+ }
84
+ interface UpdateAccountRequest {
62
85
  first_name?: string;
63
86
  last_name?: string;
87
+ email?: string;
88
+ phone_number?: string;
89
+ }
90
+ interface PasswordLoginRequest {
91
+ email: string;
92
+ password: string;
64
93
  }
65
- interface UpdatePassword {
94
+ interface ChangePasswordRequest {
66
95
  current_password: string;
67
96
  new_password: string;
68
97
  }
69
- interface UserCreate {
98
+ interface ForgotPasswordRequest {
70
99
  email: string;
71
- password: string;
72
- first_name?: string;
73
- last_name?: string;
74
- is_active?: boolean;
75
- is_superuser?: boolean;
76
100
  }
77
- interface SanitizedUserOut {
101
+ interface ResetPasswordRequest {
102
+ token: string;
103
+ new_password: string;
104
+ }
105
+ interface SendVerificationRequest {
106
+ email?: string;
107
+ }
108
+ interface VerifyEmailRequest {
109
+ token: string;
110
+ }
111
+ interface NewUser extends RegisterRequest {
112
+ confirmPassword: string;
113
+ }
114
+ interface UpdatePasswordForm extends ChangePasswordRequest {
115
+ confirmNewPassword: string;
116
+ }
117
+ interface MessageResponse {
118
+ message: string;
119
+ }
120
+ interface AuthStatusResponse {
121
+ status: string;
122
+ methods: string[];
123
+ }
124
+ interface AvailableMethodsResponse {
125
+ available_methods: {
126
+ [key: string]: any;
127
+ }[];
128
+ }
129
+ interface OTPMetadata {
130
+ nonce: string;
131
+ verification_hash: string;
132
+ timestamp: number;
133
+ expires_in_minutes: number;
134
+ autofill: {
135
+ [key: string]: any;
136
+ };
137
+ }
138
+ interface SSOMetadata {
139
+ provider: string;
140
+ sso_user_info: {
141
+ [key: string]: any;
142
+ };
143
+ can_create_account?: boolean;
144
+ }
145
+ interface AuthenticationResponse {
146
+ success: boolean;
147
+ account_id?: string;
148
+ session_token?: string;
149
+ requires_verification?: boolean;
150
+ verification_method?: AuthenticationMethodType;
151
+ message?: string;
152
+ metadata?: OTPMetadata | SSOMetadata | {
153
+ [key: string]: any;
154
+ };
155
+ }
156
+ interface SessionListResponse {
157
+ account_id: string;
158
+ sessions: SessionInfo[];
159
+ }
160
+ type LoginResponse = AxiosResponse<AuthenticationResponse>;
161
+ type RegisterResponse = AxiosResponse<AuthenticationResponse>;
162
+ type LogoutResponse = AxiosResponse<MessageResponse>;
163
+ type GetMeResponse = AxiosResponse<AccountInfo>;
164
+ type UpdateMeResponse = AxiosResponse<AccountInfo>;
165
+ type DeleteMeResponse = AxiosResponse<MessageResponse>;
166
+ type GetAccountResponse = AxiosResponse<AccountInfo>;
167
+ type UpdateAccountResponse = AxiosResponse<AccountInfo>;
168
+ type DeleteAccountResponse = AxiosResponse<MessageResponse>;
169
+ type ActivateAccountResponse = AxiosResponse<AccountInfo>;
170
+ type DeactivateAccountResponse = AxiosResponse<AccountInfo>;
171
+ type ChangePasswordResponse = AxiosResponse<MessageResponse>;
172
+ type ForgotPasswordResponse = AxiosResponse<MessageResponse>;
173
+ type ResetPasswordResponse = AxiosResponse<MessageResponse>;
174
+ type VerifyResetTokenResponse = AxiosResponse<MessageResponse>;
175
+ type SendVerificationResponse = AxiosResponse<MessageResponse>;
176
+ type VerifyEmailResponse = AxiosResponse<MessageResponse>;
177
+ type RefreshSessionResponse = AxiosResponse<AuthenticationResponse>;
178
+ type GetSessionsResponse = AxiosResponse<SessionListResponse>;
179
+ type DeleteSessionResponse = AxiosResponse<MessageResponse>;
180
+ type DeleteAllSessionsResponse = AxiosResponse<MessageResponse>;
181
+ type CleanupSessionsResponse = AxiosResponse<MessageResponse>;
182
+ type GetMethodsResponse = AxiosResponse<AvailableMethodsResponse>;
183
+ /** @deprecated Use AccountInfo instead */
184
+ type User = AccountInfo & {
78
185
  email: string;
79
- is_active?: boolean;
80
- is_superuser?: boolean;
81
186
  first_name?: string;
82
187
  last_name?: string;
83
- id: string;
84
- }
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>;
188
+ is_superuser?: boolean;
189
+ is_active?: boolean;
190
+ };
101
191
 
102
192
  declare class AuthApi {
103
193
  private api;
104
194
  constructor(axiosInstance?: AxiosInstance, baseURL?: string);
105
195
  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>;
196
+ /**
197
+ * Get available authentication methods
198
+ */
199
+ getAuthMethods(): Promise<GetMethodsResponse>;
200
+ /**
201
+ * Register a new account
202
+ */
203
+ register(data: RegisterRequest): Promise<RegisterResponse>;
204
+ /**
205
+ * Login with password
206
+ */
207
+ login(email: string, password: string): Promise<LoginResponse>;
208
+ /**
209
+ * Logout and clear session
210
+ */
211
+ logout(): Promise<LogoutResponse>;
212
+ /**
213
+ * Refresh current session
214
+ */
215
+ refreshSession(): Promise<RefreshSessionResponse>;
216
+ /**
217
+ * Get current user account info
218
+ */
110
219
  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>;
220
+ /**
221
+ * Update current user profile
222
+ */
223
+ updateCurrentUser(data: UpdateAccountRequest): Promise<UpdateMeResponse>;
224
+ /**
225
+ * Delete current user account
226
+ */
227
+ deleteCurrentUser(): Promise<DeleteMeResponse>;
228
+ /**
229
+ * Get account information by ID
230
+ */
231
+ getAccount(accountId: string): Promise<GetAccountResponse>;
232
+ /**
233
+ * Update account by ID
234
+ */
235
+ updateAccount(accountId: string, data: UpdateAccountRequest): Promise<UpdateAccountResponse>;
236
+ /**
237
+ * Delete account by ID
238
+ */
239
+ deleteAccount(accountId: string): Promise<DeleteAccountResponse>;
240
+ /**
241
+ * Activate account by ID
242
+ */
243
+ activateAccount(accountId: string): Promise<ActivateAccountResponse>;
244
+ /**
245
+ * Deactivate account by ID
246
+ */
247
+ deactivateAccount(accountId: string): Promise<DeactivateAccountResponse>;
248
+ /**
249
+ * Change password (requires current password)
250
+ */
251
+ changePassword(data: ChangePasswordRequest): Promise<ChangePasswordResponse>;
252
+ /**
253
+ * Initiate forgot password flow
254
+ */
255
+ forgotPassword(email: string): Promise<ForgotPasswordResponse>;
256
+ /**
257
+ * Verify password reset token
258
+ */
259
+ verifyResetToken(token: string): Promise<VerifyResetTokenResponse>;
260
+ /**
261
+ * Reset password with token
262
+ */
263
+ resetPassword(data: ResetPasswordRequest): Promise<ResetPasswordResponse>;
264
+ /**
265
+ * Send email verification
266
+ */
267
+ sendVerification(data?: SendVerificationRequest, user?: AuthenticationAccount): Promise<SendVerificationResponse>;
268
+ /**
269
+ * Verify email with token
270
+ */
271
+ verifyEmail(token: string): Promise<VerifyEmailResponse>;
272
+ /**
273
+ * Get sessions for an account
274
+ */
275
+ getSessions(accountId: string): Promise<GetSessionsResponse>;
276
+ /**
277
+ * Revoke a specific session
278
+ */
279
+ revokeSession(sessionToken: string): Promise<DeleteSessionResponse>;
280
+ /**
281
+ * Revoke all sessions for an account
282
+ */
283
+ revokeAllSessions(accountId: string): Promise<DeleteAllSessionsResponse>;
284
+ /**
285
+ * Cleanup expired sessions (admin)
286
+ */
287
+ cleanupSessions(): Promise<CleanupSessionsResponse>;
119
288
  }
120
289
 
121
290
  declare function initAuth({ axios, baseURL, }: {
@@ -130,35 +299,73 @@ declare function initAuth({ axios, baseURL, }: {
130
299
  declare function useAuth(): {
131
300
  currentUser: vue.Ref<{
132
301
  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 | {
302
+ account_type: string;
303
+ display_name: string;
304
+ is_active: boolean;
305
+ is_verified: boolean;
306
+ last_login?: string | undefined;
307
+ authentication_methods: {
308
+ id: string;
309
+ type: string;
310
+ identifier?: string | undefined;
311
+ is_verified: boolean;
312
+ last_used?: string | undefined;
313
+ use_count: number;
314
+ }[];
315
+ person?: {
316
+ id: string;
317
+ name: string;
318
+ email?: string | undefined;
319
+ roles: string[];
320
+ } | undefined;
321
+ } | null, AccountInfo | {
139
322
  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
- }>;
323
+ account_type: string;
324
+ display_name: string;
325
+ is_active: boolean;
326
+ is_verified: boolean;
327
+ last_login?: string | undefined;
328
+ authentication_methods: {
329
+ id: string;
330
+ type: string;
331
+ identifier?: string | undefined;
332
+ is_verified: boolean;
333
+ last_used?: string | undefined;
334
+ use_count: number;
335
+ }[];
336
+ person?: {
337
+ id: string;
338
+ name: string;
339
+ email?: string | undefined;
340
+ roles: string[];
341
+ } | undefined;
342
+ } | null>;
146
343
  getFullName: () => string;
147
344
  getIsLoggedIn: () => boolean;
148
- logout: () => Promise<void>;
345
+ getEmail: () => string;
149
346
  login: (credentials: {
150
347
  email: string;
151
348
  password: string;
152
- }) => Promise<void>;
349
+ }) => Promise<AuthenticationResponse>;
350
+ logout: () => Promise<void>;
351
+ signup: (user: NewUser) => Promise<AuthenticationResponse>;
153
352
  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>;
353
+ refreshSession: () => Promise<void>;
354
+ updateProfile: (updates: UpdateAccountRequest) => Promise<void>;
355
+ deleteCurrentUser: () => Promise<void>;
356
+ changePassword: (form: UpdatePasswordForm) => Promise<void>;
357
+ forgotPassword: (email: string) => Promise<void>;
358
+ verifyResetToken: (token: string) => Promise<void>;
359
+ resetPassword: (token: string, newPassword: string) => Promise<void>;
360
+ sendVerification: (email?: string) => Promise<void>;
361
+ verifyEmail: (token: string) => Promise<void>;
362
+ activateAccount: (accountId: string) => Promise<void>;
363
+ deactivateAccount: (accountId: string) => Promise<void>;
364
+ deleteAccount: (accountId: string) => Promise<void>;
365
+ getSessions: (accountId?: string) => Promise<GetSessionsResponse>;
366
+ revokeSession: (sessionToken: string) => Promise<void>;
367
+ revokeAllSessions: (accountId?: string) => Promise<void>;
161
368
  };
162
369
 
163
370
  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 };
371
+ export type { AccountInfo, ActivateAccountResponse, AuthEventHandler, AuthEventMap, AuthMethodInfo, AuthStatusResponse, AuthenticationAccount, AuthenticationAccountType, AuthenticationMethodType, AuthenticationResponse, AvailableMethodsResponse, ChangePasswordRequest, ChangePasswordResponse, CleanupSessionsResponse, DeactivateAccountResponse, DeleteAccountResponse, DeleteAllSessionsResponse, DeleteMeResponse, DeleteSessionResponse, 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 };