@factiii/auth 0.1.0
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/LICENSE +21 -0
- package/README.md +120 -0
- package/bin/init.mjs +315 -0
- package/dist/chunk-CLHDX2R2.mjs +118 -0
- package/dist/chunk-CLHDX2R2.mjs.map +1 -0
- package/dist/hooks-B4Kl294A.d.mts +400 -0
- package/dist/hooks-B4Kl294A.d.ts +400 -0
- package/dist/index.d.mts +1061 -0
- package/dist/index.d.ts +1061 -0
- package/dist/index.js +2096 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1947 -0
- package/dist/index.mjs.map +1 -0
- package/dist/validators.d.mts +2 -0
- package/dist/validators.d.ts +2 -0
- package/dist/validators.js +164 -0
- package/dist/validators.js.map +1 -0
- package/dist/validators.mjs +51 -0
- package/dist/validators.mjs.map +1 -0
- package/package.json +104 -0
- package/prisma/schema.prisma +138 -0
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { z, AnyZodObject } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Schema for user registration
|
|
5
|
+
*/
|
|
6
|
+
declare const signupSchema: z.ZodObject<{
|
|
7
|
+
username: z.ZodString;
|
|
8
|
+
email: z.ZodString;
|
|
9
|
+
password: z.ZodString;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
username: string;
|
|
12
|
+
email: string;
|
|
13
|
+
password: string;
|
|
14
|
+
}, {
|
|
15
|
+
username: string;
|
|
16
|
+
email: string;
|
|
17
|
+
password: string;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Schema for user login
|
|
21
|
+
*/
|
|
22
|
+
declare const loginSchema: z.ZodObject<{
|
|
23
|
+
username: z.ZodString;
|
|
24
|
+
password: z.ZodString;
|
|
25
|
+
code: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
username: string;
|
|
28
|
+
password: string;
|
|
29
|
+
code?: string | undefined;
|
|
30
|
+
}, {
|
|
31
|
+
username: string;
|
|
32
|
+
password: string;
|
|
33
|
+
code?: string | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Schema for OAuth login
|
|
37
|
+
*/
|
|
38
|
+
declare const oAuthLoginSchema: z.ZodObject<{
|
|
39
|
+
idToken: z.ZodString;
|
|
40
|
+
user: z.ZodOptional<z.ZodObject<{
|
|
41
|
+
email: z.ZodOptional<z.ZodString>;
|
|
42
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
email?: string | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
email?: string | undefined;
|
|
46
|
+
}>>;
|
|
47
|
+
provider: z.ZodEnum<["GOOGLE", "APPLE"]>;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
idToken: string;
|
|
50
|
+
provider: "GOOGLE" | "APPLE";
|
|
51
|
+
user?: {
|
|
52
|
+
email?: string | undefined;
|
|
53
|
+
} | undefined;
|
|
54
|
+
}, {
|
|
55
|
+
idToken: string;
|
|
56
|
+
provider: "GOOGLE" | "APPLE";
|
|
57
|
+
user?: {
|
|
58
|
+
email?: string | undefined;
|
|
59
|
+
} | undefined;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Schema for password reset request
|
|
63
|
+
*/
|
|
64
|
+
declare const requestPasswordResetSchema: z.ZodObject<{
|
|
65
|
+
email: z.ZodString;
|
|
66
|
+
}, "strip", z.ZodTypeAny, {
|
|
67
|
+
email: string;
|
|
68
|
+
}, {
|
|
69
|
+
email: string;
|
|
70
|
+
}>;
|
|
71
|
+
/**
|
|
72
|
+
* Schema for password reset confirmation
|
|
73
|
+
*/
|
|
74
|
+
declare const resetPasswordSchema: z.ZodObject<{
|
|
75
|
+
token: z.ZodString;
|
|
76
|
+
password: z.ZodString;
|
|
77
|
+
}, "strip", z.ZodTypeAny, {
|
|
78
|
+
password: string;
|
|
79
|
+
token: string;
|
|
80
|
+
}, {
|
|
81
|
+
password: string;
|
|
82
|
+
token: string;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Schema for checking password reset token
|
|
86
|
+
*/
|
|
87
|
+
declare const checkPasswordResetSchema: z.ZodObject<{
|
|
88
|
+
token: z.ZodString;
|
|
89
|
+
}, "strip", z.ZodTypeAny, {
|
|
90
|
+
token: string;
|
|
91
|
+
}, {
|
|
92
|
+
token: string;
|
|
93
|
+
}>;
|
|
94
|
+
/**
|
|
95
|
+
* Schema for changing password (authenticated)
|
|
96
|
+
*/
|
|
97
|
+
declare const changePasswordSchema: z.ZodObject<{
|
|
98
|
+
currentPassword: z.ZodString;
|
|
99
|
+
newPassword: z.ZodString;
|
|
100
|
+
}, "strip", z.ZodTypeAny, {
|
|
101
|
+
currentPassword: string;
|
|
102
|
+
newPassword: string;
|
|
103
|
+
}, {
|
|
104
|
+
currentPassword: string;
|
|
105
|
+
newPassword: string;
|
|
106
|
+
}>;
|
|
107
|
+
/**
|
|
108
|
+
* Schema for 2FA verification
|
|
109
|
+
*/
|
|
110
|
+
declare const twoFaVerifySchema: z.ZodObject<{
|
|
111
|
+
code: z.ZodString;
|
|
112
|
+
sessionId: z.ZodOptional<z.ZodNumber>;
|
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
code: string;
|
|
115
|
+
sessionId?: number | undefined;
|
|
116
|
+
}, {
|
|
117
|
+
code: string;
|
|
118
|
+
sessionId?: number | undefined;
|
|
119
|
+
}>;
|
|
120
|
+
/**
|
|
121
|
+
* Schema for 2FA setup
|
|
122
|
+
*/
|
|
123
|
+
declare const twoFaSetupSchema: z.ZodObject<{
|
|
124
|
+
code: z.ZodString;
|
|
125
|
+
}, "strip", z.ZodTypeAny, {
|
|
126
|
+
code: string;
|
|
127
|
+
}, {
|
|
128
|
+
code: string;
|
|
129
|
+
}>;
|
|
130
|
+
/**
|
|
131
|
+
* Schema for 2FA reset request
|
|
132
|
+
*/
|
|
133
|
+
declare const twoFaResetSchema: z.ZodObject<{
|
|
134
|
+
username: z.ZodString;
|
|
135
|
+
password: z.ZodString;
|
|
136
|
+
}, "strip", z.ZodTypeAny, {
|
|
137
|
+
username: string;
|
|
138
|
+
password: string;
|
|
139
|
+
}, {
|
|
140
|
+
username: string;
|
|
141
|
+
password: string;
|
|
142
|
+
}>;
|
|
143
|
+
/**
|
|
144
|
+
* Schema for 2FA reset verification
|
|
145
|
+
*/
|
|
146
|
+
declare const twoFaResetVerifySchema: z.ZodObject<{
|
|
147
|
+
code: z.ZodNumber;
|
|
148
|
+
username: z.ZodString;
|
|
149
|
+
}, "strip", z.ZodTypeAny, {
|
|
150
|
+
username: string;
|
|
151
|
+
code: number;
|
|
152
|
+
}, {
|
|
153
|
+
username: string;
|
|
154
|
+
code: number;
|
|
155
|
+
}>;
|
|
156
|
+
/**
|
|
157
|
+
* Schema for email verification
|
|
158
|
+
*/
|
|
159
|
+
declare const verifyEmailSchema: z.ZodObject<{
|
|
160
|
+
code: z.ZodString;
|
|
161
|
+
}, "strip", z.ZodTypeAny, {
|
|
162
|
+
code: string;
|
|
163
|
+
}, {
|
|
164
|
+
code: string;
|
|
165
|
+
}>;
|
|
166
|
+
/**
|
|
167
|
+
* Schema for resending verification email
|
|
168
|
+
*/
|
|
169
|
+
declare const resendVerificationSchema: z.ZodObject<{
|
|
170
|
+
email: z.ZodOptional<z.ZodString>;
|
|
171
|
+
}, "strip", z.ZodTypeAny, {
|
|
172
|
+
email?: string | undefined;
|
|
173
|
+
}, {
|
|
174
|
+
email?: string | undefined;
|
|
175
|
+
}>;
|
|
176
|
+
/**
|
|
177
|
+
* Schema for biometric verification
|
|
178
|
+
*/
|
|
179
|
+
declare const biometricVerifySchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
180
|
+
/**
|
|
181
|
+
* Schema for push token registration
|
|
182
|
+
*/
|
|
183
|
+
declare const registerPushTokenSchema: z.ZodObject<{
|
|
184
|
+
pushToken: z.ZodString;
|
|
185
|
+
}, "strip", z.ZodTypeAny, {
|
|
186
|
+
pushToken: string;
|
|
187
|
+
}, {
|
|
188
|
+
pushToken: string;
|
|
189
|
+
}>;
|
|
190
|
+
/**
|
|
191
|
+
* Schema for push token deregistration
|
|
192
|
+
*/
|
|
193
|
+
declare const deregisterPushTokenSchema: z.ZodObject<{
|
|
194
|
+
pushToken: z.ZodString;
|
|
195
|
+
}, "strip", z.ZodTypeAny, {
|
|
196
|
+
pushToken: string;
|
|
197
|
+
}, {
|
|
198
|
+
pushToken: string;
|
|
199
|
+
}>;
|
|
200
|
+
/**
|
|
201
|
+
* Schema for getting 2FA secret
|
|
202
|
+
*/
|
|
203
|
+
declare const getTwofaSecretSchema: z.ZodObject<{
|
|
204
|
+
pushCode: z.ZodString;
|
|
205
|
+
}, "strip", z.ZodTypeAny, {
|
|
206
|
+
pushCode: string;
|
|
207
|
+
}, {
|
|
208
|
+
pushCode: string;
|
|
209
|
+
}>;
|
|
210
|
+
/**
|
|
211
|
+
* Schema for disabling 2FA
|
|
212
|
+
*/
|
|
213
|
+
declare const disableTwofaSchema: z.ZodObject<{
|
|
214
|
+
password: z.ZodString;
|
|
215
|
+
}, "strip", z.ZodTypeAny, {
|
|
216
|
+
password: string;
|
|
217
|
+
}, {
|
|
218
|
+
password: string;
|
|
219
|
+
}>;
|
|
220
|
+
/**
|
|
221
|
+
* Schema for logout
|
|
222
|
+
*/
|
|
223
|
+
declare const logoutSchema: z.ZodObject<{
|
|
224
|
+
allDevices: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
225
|
+
}, "strip", z.ZodTypeAny, {
|
|
226
|
+
allDevices: boolean;
|
|
227
|
+
}, {
|
|
228
|
+
allDevices?: boolean | undefined;
|
|
229
|
+
}>;
|
|
230
|
+
/**
|
|
231
|
+
* Schema for ending all sessions
|
|
232
|
+
*/
|
|
233
|
+
declare const endAllSessionsSchema: z.ZodObject<{
|
|
234
|
+
skipCurrentSession: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
235
|
+
}, "strip", z.ZodTypeAny, {
|
|
236
|
+
skipCurrentSession: boolean;
|
|
237
|
+
}, {
|
|
238
|
+
skipCurrentSession?: boolean | undefined;
|
|
239
|
+
}>;
|
|
240
|
+
/**
|
|
241
|
+
* Schema for OTP-based login request
|
|
242
|
+
*/
|
|
243
|
+
declare const otpLoginRequestSchema: z.ZodObject<{
|
|
244
|
+
email: z.ZodString;
|
|
245
|
+
}, "strip", z.ZodTypeAny, {
|
|
246
|
+
email: string;
|
|
247
|
+
}, {
|
|
248
|
+
email: string;
|
|
249
|
+
}>;
|
|
250
|
+
/**
|
|
251
|
+
* Schema for OTP-based login verification
|
|
252
|
+
*/
|
|
253
|
+
declare const otpLoginVerifySchema: z.ZodObject<{
|
|
254
|
+
email: z.ZodString;
|
|
255
|
+
code: z.ZodNumber;
|
|
256
|
+
}, "strip", z.ZodTypeAny, {
|
|
257
|
+
email: string;
|
|
258
|
+
code: number;
|
|
259
|
+
}, {
|
|
260
|
+
email: string;
|
|
261
|
+
code: number;
|
|
262
|
+
}>;
|
|
263
|
+
type SignupInput = z.infer<typeof signupSchema>;
|
|
264
|
+
type LoginInput = z.infer<typeof loginSchema>;
|
|
265
|
+
type OAuthLoginInput = z.infer<typeof oAuthLoginSchema>;
|
|
266
|
+
type ResetPasswordInput = z.infer<typeof resetPasswordSchema>;
|
|
267
|
+
type ChangePasswordInput = z.infer<typeof changePasswordSchema>;
|
|
268
|
+
type TwoFaVerifyInput = z.infer<typeof twoFaVerifySchema>;
|
|
269
|
+
type VerifyEmailInput = z.infer<typeof verifyEmailSchema>;
|
|
270
|
+
type LogoutInput = z.infer<typeof logoutSchema>;
|
|
271
|
+
/** Schemas used by auth procedures */
|
|
272
|
+
interface AuthSchemas {
|
|
273
|
+
signup: AnyZodObject;
|
|
274
|
+
login: AnyZodObject;
|
|
275
|
+
oauth: AnyZodObject;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Compute merged ZodObject type.
|
|
279
|
+
* When TExt is defined, produces a schema with both base and extension shapes.
|
|
280
|
+
* When TExt is undefined, produces the base schema.
|
|
281
|
+
*/
|
|
282
|
+
type MergedSchema<TBase extends AnyZodObject, TExt extends AnyZodObject | undefined> = [
|
|
283
|
+
TExt
|
|
284
|
+
] extends [AnyZodObject] ? z.ZodObject<TBase['shape'] & TExt['shape'], 'strip', z.ZodTypeAny> : TBase;
|
|
285
|
+
/** Result type from createSchemas - preserves concrete schema types */
|
|
286
|
+
type CreatedSchemas<TExtensions extends SchemaExtensions = {}> = {
|
|
287
|
+
signup: MergedSchema<typeof signupSchema, TExtensions['signup']>;
|
|
288
|
+
login: MergedSchema<typeof loginSchema, TExtensions['login']>;
|
|
289
|
+
oauth: MergedSchema<typeof oAuthLoginSchema, TExtensions['oauth']>;
|
|
290
|
+
};
|
|
291
|
+
type SignupSchemaInput<TExtensions extends SchemaExtensions = {}> = SignupInput & (TExtensions['signup'] extends AnyZodObject ? z.infer<TExtensions['signup']> : {});
|
|
292
|
+
type LoginSchemaInput<TExtensions extends SchemaExtensions = {}> = LoginInput & (TExtensions['login'] extends AnyZodObject ? z.infer<TExtensions['login']> : {});
|
|
293
|
+
type OAuthSchemaInput<TExtensions extends SchemaExtensions = {}> = OAuthLoginInput & (TExtensions['oauth'] extends AnyZodObject ? z.infer<TExtensions['oauth']> : {});
|
|
294
|
+
/** Create schemas with optional extensions merged in */
|
|
295
|
+
declare function createSchemas<TExtensions extends SchemaExtensions = {}>(extensions?: TExtensions): CreatedSchemas<TExtensions>;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Schema extensions for adding custom fields to auth inputs
|
|
299
|
+
*/
|
|
300
|
+
interface SchemaExtensions {
|
|
301
|
+
signup?: AnyZodObject;
|
|
302
|
+
login?: AnyZodObject;
|
|
303
|
+
oauth?: AnyZodObject;
|
|
304
|
+
}
|
|
305
|
+
type BaseSignupInput = z.infer<typeof signupSchema>;
|
|
306
|
+
type BaseLoginInput = z.infer<typeof loginSchema>;
|
|
307
|
+
type BaseOAuthInput = z.infer<typeof oAuthLoginSchema>;
|
|
308
|
+
/** Input types that include base fields plus any extension fields */
|
|
309
|
+
type ExtendedSignupInput<TExtensions extends SchemaExtensions> = BaseSignupInput & (TExtensions['signup'] extends AnyZodObject ? z.infer<TExtensions['signup']> : Record<string, unknown>);
|
|
310
|
+
type ExtendedLoginInput<TExtensions extends SchemaExtensions> = BaseLoginInput & (TExtensions['login'] extends AnyZodObject ? z.infer<TExtensions['login']> : Record<string, unknown>);
|
|
311
|
+
type ExtendedOAuthInput<TExtensions extends SchemaExtensions> = BaseOAuthInput & (TExtensions['oauth'] extends AnyZodObject ? z.infer<TExtensions['oauth']> : Record<string, unknown>);
|
|
312
|
+
/**
|
|
313
|
+
* Lifecycle hooks for extending auth behavior with business logic
|
|
314
|
+
* @template TExtensions - Schema extensions to merge with base input types
|
|
315
|
+
*/
|
|
316
|
+
interface AuthHooks<TExtensions extends SchemaExtensions = {}> {
|
|
317
|
+
/**
|
|
318
|
+
* Called before user registration validation
|
|
319
|
+
* Use this to add custom validation or check business rules
|
|
320
|
+
*/
|
|
321
|
+
beforeRegister?: (input: ExtendedSignupInput<TExtensions>) => Promise<void>;
|
|
322
|
+
/**
|
|
323
|
+
* Called before user login validation
|
|
324
|
+
* Use this to add custom validation or check business rules
|
|
325
|
+
*/
|
|
326
|
+
beforeLogin?: (input: ExtendedLoginInput<TExtensions>) => Promise<void>;
|
|
327
|
+
/**
|
|
328
|
+
* Called after a new user is created
|
|
329
|
+
* Use this to set up user preferences, default data, etc.
|
|
330
|
+
*/
|
|
331
|
+
onUserCreated?: (userId: number, input: ExtendedSignupInput<TExtensions> | ExtendedOAuthInput<TExtensions>) => Promise<void>;
|
|
332
|
+
/**
|
|
333
|
+
* Called after successful login
|
|
334
|
+
* Use this to update activity status, send notifications, etc.
|
|
335
|
+
*/
|
|
336
|
+
onUserLogin?: (userId: number, sessionId: number) => Promise<void>;
|
|
337
|
+
/**
|
|
338
|
+
* Called to get additional data for session creation
|
|
339
|
+
* Return an object with extra fields to include in session.create
|
|
340
|
+
*/
|
|
341
|
+
getSessionData?: (input: ExtendedSignupInput<TExtensions> | ExtendedLoginInput<TExtensions> | ExtendedOAuthInput<TExtensions>) => Promise<Record<string, unknown>>;
|
|
342
|
+
/**
|
|
343
|
+
* Called after a new session is created
|
|
344
|
+
*/
|
|
345
|
+
onSessionCreated?: (sessionId: number, input: ExtendedSignupInput<TExtensions> | ExtendedLoginInput<TExtensions> | ExtendedOAuthInput<TExtensions>) => Promise<void>;
|
|
346
|
+
/**
|
|
347
|
+
* Called when a session is revoked
|
|
348
|
+
*/
|
|
349
|
+
onSessionRevoked?: (sessionId: number, socketId: string | null, reason: string) => Promise<void>;
|
|
350
|
+
/**
|
|
351
|
+
* Called after user logs out
|
|
352
|
+
*/
|
|
353
|
+
afterLogout?: (userId: number, sessionId: number, socketId: string | null) => Promise<void>;
|
|
354
|
+
/**
|
|
355
|
+
* Called on token refresh
|
|
356
|
+
*/
|
|
357
|
+
onRefresh?: (userId: number) => Promise<void>;
|
|
358
|
+
/**
|
|
359
|
+
* Called after password is changed
|
|
360
|
+
*/
|
|
361
|
+
onPasswordChanged?: (userId: number) => Promise<void>;
|
|
362
|
+
/**
|
|
363
|
+
* Called after email is verified
|
|
364
|
+
*/
|
|
365
|
+
onEmailVerified?: (userId: number) => Promise<void>;
|
|
366
|
+
/**
|
|
367
|
+
* Called after 2FA is enabled/disabled
|
|
368
|
+
*/
|
|
369
|
+
onTwoFaStatusChanged?: (userId: number, enabled: boolean) => Promise<void>;
|
|
370
|
+
/**
|
|
371
|
+
* Called after OAuth account is linked
|
|
372
|
+
*/
|
|
373
|
+
onOAuthLinked?: (userId: number, provider: 'GOOGLE' | 'APPLE') => Promise<void>;
|
|
374
|
+
/**
|
|
375
|
+
* Custom validation for biometric verification
|
|
376
|
+
* Return timeout in ms, or null to skip timeout enforcement
|
|
377
|
+
*/
|
|
378
|
+
getBiometricTimeout?: () => Promise<number | null>;
|
|
379
|
+
/**
|
|
380
|
+
* Called after biometric verification
|
|
381
|
+
*/
|
|
382
|
+
onBiometricVerified?: (userId: number) => Promise<void>;
|
|
383
|
+
/**
|
|
384
|
+
* Called to log errors (e.g., server errors, auth errors)
|
|
385
|
+
* Provides a hook for centralized error logging
|
|
386
|
+
* Returns error ID for linking purposes
|
|
387
|
+
*/
|
|
388
|
+
logError?: (params: {
|
|
389
|
+
type: 'SERVER_ERROR' | 'DATABASE_ERROR' | 'SECURITY' | 'OTHER';
|
|
390
|
+
description: string;
|
|
391
|
+
stack: string;
|
|
392
|
+
ip?: string;
|
|
393
|
+
userId?: number | null;
|
|
394
|
+
}) => Promise<{
|
|
395
|
+
errorId: number;
|
|
396
|
+
stackId: number;
|
|
397
|
+
} | null>;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export { type AuthHooks as A, getTwofaSecretSchema as B, type ChangePasswordInput as C, registerPushTokenSchema as D, resendVerificationSchema as E, twoFaResetVerifySchema as F, type LoginInput as L, type OAuthLoginInput as O, type ResetPasswordInput as R, type SchemaExtensions as S, type TwoFaVerifyInput as T, type VerifyEmailInput as V, type LogoutInput as a, type SignupInput as b, biometricVerifySchema as c, changePasswordSchema as d, endAllSessionsSchema as e, logoutSchema as f, otpLoginRequestSchema as g, otpLoginVerifySchema as h, resetPasswordSchema as i, twoFaSetupSchema as j, twoFaVerifySchema as k, loginSchema as l, type AuthSchemas as m, type CreatedSchemas as n, oAuthLoginSchema as o, type LoginSchemaInput as p, type OAuthSchemaInput as q, requestPasswordResetSchema as r, signupSchema as s, twoFaResetSchema as t, type SignupSchemaInput as u, verifyEmailSchema as v, checkPasswordResetSchema as w, createSchemas as x, deregisterPushTokenSchema as y, disableTwofaSchema as z };
|