@plyaz/types 1.27.6 → 1.27.7

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.
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @fileoverview Authentication event constants for @plyaz/auth
3
+ * @module @plyaz/auth/constants/auth-events
4
+ *
5
+ * @description
6
+ * Defines standardized event names for authentication system events.
7
+ * These events are published via @plyaz/events for audit logging and
8
+ * cross-component communication. Used by repositories, services, and
9
+ * frontend stores for reactive state management.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { AUTH_EVENTS } from '@plyaz/auth';
14
+ *
15
+ * // Publish event
16
+ * eventManager.publish(AUTH_EVENTS.USER_AUTHENTICATED, { userId, provider });
17
+ *
18
+ * // Subscribe to event
19
+ * eventManager.subscribe(AUTH_EVENTS.SESSION_EXPIRED, handleSessionExpiry);
20
+ * ```
21
+ */
22
+ /**
23
+ * Authentication event type constants
24
+ * Used for event publishing and subscription throughout the auth system
25
+ */
26
+ export declare const AUTH_EVENTS: {
27
+ /** User successfully authenticated */
28
+ readonly USER_AUTHENTICATED: "auth.user.authenticated";
29
+ /** User signed up (new account created) */
30
+ readonly USER_SIGNED_UP: "auth.user.signed_up";
31
+ /** User logged out */
32
+ readonly USER_LOGGED_OUT: "auth.user.logged_out";
33
+ /** Authentication attempt failed */
34
+ readonly AUTHENTICATION_FAILED: "auth.authentication.failed";
35
+ /** Session created */
36
+ readonly SESSION_CREATED: "auth.session.created";
37
+ /** Session expired */
38
+ readonly SESSION_EXPIRED: "auth.session.expired";
39
+ /** Session refreshed */
40
+ readonly SESSION_REFRESHED: "auth.session.refreshed";
41
+ /** Session invalidated (logout) */
42
+ readonly SESSION_INVALIDATED: "auth.session.invalidated";
43
+ /** Account linked to user */
44
+ readonly ACCOUNT_LINKED: "auth.account.linked";
45
+ /** Account unlinked from user */
46
+ readonly ACCOUNT_UNLINKED: "auth.account.unlinked";
47
+ /** Role assigned to user */
48
+ readonly ROLE_ASSIGNED: "auth.rbac.role_assigned";
49
+ /** Role revoked from user */
50
+ readonly ROLE_REVOKED: "auth.rbac.role_revoked";
51
+ /** Suspicious login attempt detected */
52
+ readonly SUSPICIOUS_LOGIN_ATTEMPT: "auth.security.suspicious_login";
53
+ /** Password changed */
54
+ readonly PASSWORD_CHANGED: "auth.password.changed";
55
+ /** Password reset requested */
56
+ readonly PASSWORD_RESET_REQUESTED: "auth.password.reset_requested";
57
+ };
58
+ /**
59
+ * Type for authentication event names
60
+ */
61
+ export type AuthEventTypes = typeof AUTH_EVENTS[keyof typeof AUTH_EVENTS];
62
+ /**
63
+ * Authentication event payload interfaces
64
+ */
65
+ export interface AuthEventPayload {
66
+ /** Base event data */
67
+ timestamp: Date;
68
+ /** IP address of the request */
69
+ ipAddress?: string;
70
+ /** User agent string */
71
+ userAgent?: string;
72
+ /** Additional metadata */
73
+ metadata?: Record<string, unknown>;
74
+ }
75
+ export interface UserAuthenticatedPayload extends AuthEventPayload {
76
+ userId: string;
77
+ provider: string;
78
+ sessionId: string;
79
+ }
80
+ export interface UserSignedUpPayload extends AuthEventPayload {
81
+ userId: string;
82
+ provider: string;
83
+ email: string;
84
+ }
85
+ export interface UserLoggedOutPayload extends AuthEventPayload {
86
+ userId: string;
87
+ sessionId: string;
88
+ }
89
+ export interface AuthenticationFailedPayload extends AuthEventPayload {
90
+ provider: string;
91
+ reason: string;
92
+ email?: string;
93
+ }
94
+ export interface SessionEventPayload extends AuthEventPayload {
95
+ userId: string;
96
+ sessionId: string;
97
+ }
98
+ export interface AccountLinkedPayload extends AuthEventPayload {
99
+ userId: string;
100
+ provider: string;
101
+ accountId: string;
102
+ }
103
+ export interface RoleEventPayload extends AuthEventPayload {
104
+ userId: string;
105
+ role: string;
106
+ assignedBy?: string;
107
+ }
@@ -248,12 +248,81 @@ var AUTH_ERROR_CODES = {
248
248
  ACCOUNT_LOCKED: "AUTH_ACCOUNT_LOCKED",
249
249
  ACCOUNT_SUSPENDED: "AUTH_ACCOUNT_SUSPENDED"
250
250
  };
251
+ var ERROR_CODE_TO_HTTP_STATUS = {
252
+ [AUTH_ERROR_CODES.INVALID_CREDENTIALS]: 401,
253
+ [AUTH_ERROR_CODES.TOKEN_EXPIRED]: 401,
254
+ [AUTH_ERROR_CODES.TOKEN_INVALID]: 401,
255
+ [AUTH_ERROR_CODES.TOKEN_REVOKED]: 401,
256
+ [AUTH_ERROR_CODES.SESSION_EXPIRED]: 401,
257
+ [AUTH_ERROR_CODES.MFA_REQUIRED]: 401,
258
+ [AUTH_ERROR_CODES.MFA_INVALID]: 401,
259
+ [AUTH_ERROR_CODES.INSUFFICIENT_PERMISSIONS]: 403,
260
+ [AUTH_ERROR_CODES.ROLE_REQUIRED]: 403,
261
+ [AUTH_ERROR_CODES.WALLET_SIGNATURE_INVALID]: 401,
262
+ [AUTH_ERROR_CODES.NONCE_EXPIRED]: 401,
263
+ [AUTH_ERROR_CODES.NONCE_ALREADY_USED]: 401,
264
+ [AUTH_ERROR_CODES.ACCOUNT_LOCKED]: 423,
265
+ [AUTH_ERROR_CODES.ACCOUNT_SUSPENDED]: 423
266
+ };
267
+ var ERROR_CODE_DESCRIPTIONS = {
268
+ [AUTH_ERROR_CODES.INVALID_CREDENTIALS]: "errors.auth.invalid_credentials",
269
+ [AUTH_ERROR_CODES.TOKEN_EXPIRED]: "errors.auth.token_expired",
270
+ [AUTH_ERROR_CODES.TOKEN_INVALID]: "errors.auth.token_invalid",
271
+ [AUTH_ERROR_CODES.TOKEN_REVOKED]: "errors.auth.token_revoked",
272
+ [AUTH_ERROR_CODES.SESSION_EXPIRED]: "errors.auth.session_expired",
273
+ [AUTH_ERROR_CODES.MFA_REQUIRED]: "errors.auth.mfa_required",
274
+ [AUTH_ERROR_CODES.MFA_INVALID]: "errors.auth.mfa_invalid",
275
+ [AUTH_ERROR_CODES.INSUFFICIENT_PERMISSIONS]: "errors.auth.insufficient_permissions",
276
+ [AUTH_ERROR_CODES.ROLE_REQUIRED]: "errors.auth.role_required",
277
+ [AUTH_ERROR_CODES.WALLET_SIGNATURE_INVALID]: "errors.auth.wallet_signature_invalid",
278
+ [AUTH_ERROR_CODES.NONCE_EXPIRED]: "errors.auth.nonce_expired",
279
+ [AUTH_ERROR_CODES.NONCE_ALREADY_USED]: "errors.auth.nonce_already_used",
280
+ [AUTH_ERROR_CODES.ACCOUNT_LOCKED]: "errors.auth.account_locked",
281
+ [AUTH_ERROR_CODES.ACCOUNT_SUSPENDED]: "errors.auth.account_suspended"
282
+ };
283
+
284
+ // src/auth/auth-events.ts
285
+ var AUTH_EVENTS = {
286
+ /** User successfully authenticated */
287
+ USER_AUTHENTICATED: "auth.user.authenticated",
288
+ /** User signed up (new account created) */
289
+ USER_SIGNED_UP: "auth.user.signed_up",
290
+ /** User logged out */
291
+ USER_LOGGED_OUT: "auth.user.logged_out",
292
+ /** Authentication attempt failed */
293
+ AUTHENTICATION_FAILED: "auth.authentication.failed",
294
+ /** Session created */
295
+ SESSION_CREATED: "auth.session.created",
296
+ /** Session expired */
297
+ SESSION_EXPIRED: "auth.session.expired",
298
+ /** Session refreshed */
299
+ SESSION_REFRESHED: "auth.session.refreshed",
300
+ /** Session invalidated (logout) */
301
+ SESSION_INVALIDATED: "auth.session.invalidated",
302
+ /** Account linked to user */
303
+ ACCOUNT_LINKED: "auth.account.linked",
304
+ /** Account unlinked from user */
305
+ ACCOUNT_UNLINKED: "auth.account.unlinked",
306
+ /** Role assigned to user */
307
+ ROLE_ASSIGNED: "auth.rbac.role_assigned",
308
+ /** Role revoked from user */
309
+ ROLE_REVOKED: "auth.rbac.role_revoked",
310
+ /** Suspicious login attempt detected */
311
+ SUSPICIOUS_LOGIN_ATTEMPT: "auth.security.suspicious_login",
312
+ /** Password changed */
313
+ PASSWORD_CHANGED: "auth.password.changed",
314
+ /** Password reset requested */
315
+ PASSWORD_RESET_REQUESTED: "auth.password.reset_requested"
316
+ };
251
317
 
252
318
  exports.AUTH_ERROR_CODES = AUTH_ERROR_CODES;
253
319
  exports.AUTH_ERROR_DEFINITIONS = AUTH_ERROR_DEFINITIONS;
320
+ exports.AUTH_EVENTS = AUTH_EVENTS;
254
321
  exports.AUTH_PROVIDER = AUTH_PROVIDER;
255
322
  exports.AUTH_PROVIDER_TYPE = AUTH_PROVIDER_TYPE;
256
323
  exports.ContactUsFormSchema = ContactUsFormSchema;
324
+ exports.ERROR_CODE_DESCRIPTIONS = ERROR_CODE_DESCRIPTIONS;
325
+ exports.ERROR_CODE_TO_HTTP_STATUS = ERROR_CODE_TO_HTTP_STATUS;
257
326
  exports.SignupFormSchema = SignupFormSchema;
258
327
  exports.TOKEN_TYPE = TOKEN_TYPE;
259
328
  exports.USER_ROLE = USER_ROLE;