@dax-crafta/auth 2.1.6 → 2.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dax-crafta/auth",
3
- "version": "2.1.6",
3
+ "version": "2.1.7",
4
4
  "description": "A powerful, flexible, and secure authentication plugin for the Crafta framework. Supports JWT, social login, 2FA, RBAC, audit logging, and enterprise-grade security features.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
package/src/index.d.ts CHANGED
@@ -1,107 +1,206 @@
1
- export interface CraftaAuthRoutes {
2
- register?: string;
3
- login?: string;
4
- verify?: string;
5
- forgotPassword?: string;
6
- resetPassword?: string;
7
- refreshToken?: string;
8
- profile?: string;
9
- twoFactor?: string;
10
- roles?: string;
11
- permissions?: string;
12
- }
13
-
14
- export interface PasswordPolicyConfig {
15
- minLength?: number;
16
- requireUppercase?: boolean;
17
- requireLowercase?: boolean;
18
- requireNumbers?: boolean;
19
- requireSpecialChars?: boolean;
20
- expiryDays?: number;
21
- minStrength?: number;
22
- }
23
-
24
- export interface SmtpConfig {
25
- host: string;
26
- port: number;
27
- auth: {
28
- user: string;
29
- pass: string;
30
- };
31
- from: string;
32
- }
33
-
34
- export interface SocialGoogleConfig {
35
- clientID: string;
36
- clientSecret: string;
37
- callbackURL: string;
38
- }
39
-
40
- export interface SocialConfig {
41
- google?: SocialGoogleConfig | null;
42
- facebook?: any;
43
- github?: any;
44
- }
45
-
46
- export interface EnvConfig {
47
- JWT_SECRET: string;
48
- [key: string]: any;
49
- }
50
-
51
- export interface AuthConfig {
52
- strategy?: 'jwt';
53
- fields?: string[];
54
- routes?: CraftaAuthRoutes;
55
- mongoUrl?: string;
56
- maxLoginAttempts?: number;
57
- emailVerification?: boolean;
58
- loginAlerts?: boolean;
59
- passwordPolicy?: PasswordPolicyConfig;
60
- smtp?: SmtpConfig | null;
61
- social?: SocialConfig;
62
- env?: EnvConfig;
63
- accessTokenExpiry?: string;
64
- refreshTokenDays?: number;
65
- enableCSRF?: boolean;
66
- limits?: {
67
- loginMax?: number;
68
- twoFAMax?: number;
69
- forgotPasswordMax?: number;
70
- refreshMax?: number;
71
- };
72
- baseUrl?: string;
73
- emailTemplateDir?: string;
74
- features?: AuthFeaturesConfig;
75
- logging?: boolean;
76
- }
77
-
78
- export interface AuthFeaturesConfig {
79
- emailVerification?: boolean;
80
- loginAlerts?: boolean;
81
- securityAttempts?: boolean;
82
- rateLimit?: boolean;
83
- auditLogs?: boolean;
84
- twoFactor?: boolean;
85
- csrf?: boolean;
86
- }
87
-
88
- export class ApiError extends Error {
89
- status: number;
90
- constructor(message: string, status?: number);
91
- }
92
-
93
- export function auth(config?: AuthConfig): (app: any) => void;
94
-
95
- export interface AdaptiveTestCase {
96
- name: string;
97
- feature: string;
98
- run: (cfg: AuthConfig, log: any) => Promise<void>;
99
- }
100
-
101
- export function inferFeatureFlags(authConfig?: AuthConfig): Record<string, boolean>;
102
- export function runAdaptiveTests(
103
- authConfig?: AuthConfig,
104
- featureFlags?: Record<string, boolean>,
105
- opts?: { logging?: boolean }
106
- ): Promise<boolean>;
107
- export const testCatalog: AdaptiveTestCase[];
1
+ export interface CraftaAuthRoutes {
2
+ register?: string;
3
+ login?: string;
4
+ verify?: string;
5
+ forgotPassword?: string;
6
+ resetPassword?: string;
7
+ refreshToken?: string;
8
+ profile?: string;
9
+ twoFactor?: string;
10
+ roles?: string;
11
+ permissions?: string;
12
+ magicLink?: string;
13
+ }
14
+
15
+ export interface PasswordPolicyConfig {
16
+ minLength?: number;
17
+ requireUppercase?: boolean;
18
+ requireLowercase?: boolean;
19
+ requireNumbers?: boolean;
20
+ requireSpecialChars?: boolean;
21
+ expiryDays?: number;
22
+ minStrength?: number;
23
+ passwordHistory?: number;
24
+ }
25
+
26
+ export interface SmtpConfig {
27
+ host: string;
28
+ port: number;
29
+ auth: {
30
+ user: string;
31
+ pass: string;
32
+ };
33
+ from: string;
34
+ }
35
+
36
+ export interface SocialGoogleConfig {
37
+ clientID: string;
38
+ clientSecret: string;
39
+ callbackURL: string;
40
+ }
41
+
42
+ export interface SocialConfig {
43
+ google?: SocialGoogleConfig | null;
44
+ facebook?: any;
45
+ github?: any;
46
+ }
47
+
48
+ export interface EnvConfig {
49
+ JWT_SECRET: string;
50
+ [key: string]: any;
51
+ }
52
+
53
+ export interface RateLimitConfig {
54
+ loginMax?: number;
55
+ twoFAMax?: number;
56
+ forgotPasswordMax?: number;
57
+ refreshMax?: number;
58
+ registerMax?: number;
59
+ }
60
+
61
+ export interface WebhookConfig {
62
+ url: string;
63
+ events?: string[];
64
+ secret?: string;
65
+ }
66
+
67
+ export interface SessionConfig {
68
+ maxSessions?: number;
69
+ sessionExpiryMs?: number;
70
+ }
71
+
72
+ export interface LockoutConfig {
73
+ maxAttempts?: number;
74
+ lockDurationMs?: number;
75
+ }
76
+
77
+ export interface AuthFeaturesConfig {
78
+ emailVerification?: boolean;
79
+ loginAlerts?: boolean;
80
+ securityAttempts?: boolean;
81
+ rateLimit?: boolean;
82
+ auditLogs?: boolean;
83
+ twoFactor?: boolean;
84
+ csrf?: boolean;
85
+ }
86
+
87
+ export interface AuthConfig {
88
+ strategy?: 'jwt';
89
+ fields?: string[];
90
+ routes?: CraftaAuthRoutes;
91
+ mongoUrl?: string;
92
+ maxLoginAttempts?: number;
93
+ emailVerification?: boolean;
94
+ loginAlerts?: boolean;
95
+ passwordPolicy?: PasswordPolicyConfig;
96
+ smtp?: SmtpConfig | null;
97
+ social?: SocialConfig;
98
+ env?: EnvConfig;
99
+ accessTokenExpiry?: string;
100
+ refreshTokenDays?: number;
101
+ enableCSRF?: boolean;
102
+ limits?: RateLimitConfig;
103
+ baseUrl?: string;
104
+ emailTemplateDir?: string;
105
+ features?: AuthFeaturesConfig;
106
+ logging?: boolean;
107
+ webhooks?: WebhookConfig;
108
+ session?: SessionConfig;
109
+ lockout?: LockoutConfig;
110
+ }
111
+
112
+ export class ApiError extends Error {
113
+ code: string;
114
+ status: number;
115
+ details?: any;
116
+ constructor(message: string, code?: string, status?: number, details?: any);
117
+ static unauthorized(message?: string, details?: any): ApiError;
118
+ static forbidden(message?: string, details?: any): ApiError;
119
+ static notFound(message?: string, details?: any): ApiError;
120
+ static validation(message?: string, details?: any): ApiError;
121
+ static badRequest(message?: string, details?: any): ApiError;
122
+ static conflict(message?: string, details?: any): ApiError;
123
+ static tooManyRequests(message?: string, details?: any): ApiError;
124
+ static accountLocked(message?: string, details?: any): ApiError;
125
+ static invalidCredentials(message?: string, details?: any): ApiError;
126
+ static invalidToken(message?: string, details?: any): ApiError;
127
+ static expiredToken(message?: string, details?: any): ApiError;
128
+ static emailNotVerified(message?: string, details?: any): ApiError;
129
+ static twoFactorRequired(message?: string, details?: any): ApiError;
130
+ static twoFactorFailed(message?: string, details?: any): ApiError;
131
+ static passwordPolicy(message?: string, details?: any): ApiError;
132
+ static passwordReuse(message?: string, details?: any): ApiError;
133
+ static smtpDisabled(message?: string, details?: any): ApiError;
134
+ static socialAuthFailed(message?: string, details?: any): ApiError;
135
+ static internal(message?: string, details?: any): ApiError;
136
+ static isApiError(err: unknown): err is ApiError;
137
+ static normalize(err: unknown): ApiError;
138
+ }
139
+
140
+ export interface AuthEvent {
141
+ type: string;
142
+ userId?: string;
143
+ timestamp: string;
144
+ metadata?: Record<string, any>;
145
+ }
146
+
147
+ export interface AuthService {
148
+ register(userData: any): Promise<any>;
149
+ verifyEmail(token: string): Promise<any>;
150
+ login(email: string, password: string, deviceInfo: any): Promise<any>;
151
+ verify2FA(userId: string, code: string): Promise<any>;
152
+ refreshToken(refreshToken: string): Promise<any>;
153
+ forgotPassword(email: string): Promise<any>;
154
+ resetPassword(token: string, newPassword: string): Promise<any>;
155
+ generateBackupCodes(userId: string, mfaService: any): Promise<string[]>;
156
+ updateProfile(userId: string, updates: any): Promise<any>;
157
+ generateTokens(user: any): Promise<{ accessToken: string; refreshToken: string }>;
158
+ logout(userId: string, sessionId: string): Promise<boolean>;
159
+ handleSocialLogin(provider: string, profile: any): Promise<any>;
160
+ }
161
+
162
+ export interface RoleService {
163
+ createRole(roleData: any): Promise<any>;
164
+ getRoleByName(name: string): Promise<any>;
165
+ updateRole(name: string, updates: any): Promise<any>;
166
+ deleteRole(name: string): Promise<void>;
167
+ assignPermissions(roleName: string, permissions: any[]): Promise<any>;
168
+ checkPermission(role: string, resource: string, action: string): Promise<boolean>;
169
+ }
170
+
171
+ export interface AuditService {
172
+ logActivity(data: any): Promise<any>;
173
+ getUserActivity(userId: string, filters?: any): Promise<any[]>;
174
+ getActivityByDateRange(startDate: Date, endDate: Date): Promise<any[]>;
175
+ getFailedLoginAttempts(userId: string, timeWindow: number): Promise<number>;
176
+ }
177
+
178
+ export interface MFAService {
179
+ generateSecret(label: string, issuer?: string): Promise<{ secret: string; qrCode: string }>;
180
+ verifyToken(token: string, secret: string): boolean;
181
+ generateBackupCodes(): Array<{ raw: string; hash: string }>;
182
+ verifyBackupCode(rawCode: string, storedCodes?: any[]): any;
183
+ }
184
+
185
+ export interface PasswordPolicyService {
186
+ validate(password: string, userInfo?: any): { isValid: boolean; errors: string[]; strength: number };
187
+ allowsReuse(password: string, passwordHistory: any[], bcrypt: any): Promise<boolean>;
188
+ isExpired(lastChange: Date): boolean;
189
+ }
190
+
191
+ export function auth(config?: AuthConfig): (app: any) => void;
192
+ export function normalizeError(err: unknown): ApiError;
193
+
194
+ export interface AdaptiveTestCase {
195
+ name: string;
196
+ feature: string;
197
+ run: (cfg: AuthConfig, log: any) => Promise<void>;
198
+ }
199
+
200
+ export function inferFeatureFlags(authConfig?: AuthConfig): Record<string, boolean>;
201
+ export function runAdaptiveTests(
202
+ authConfig?: AuthConfig,
203
+ featureFlags?: Record<string, boolean>,
204
+ opts?: { logging?: boolean }
205
+ ): Promise<boolean>;
206
+ export const testCatalog: AdaptiveTestCase[];