@classic-homes/theme-svelte 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/README.md +305 -0
- package/dist/lib/components/Alert.svelte +51 -0
- package/dist/lib/components/Alert.svelte.d.ts +9 -0
- package/dist/lib/components/AlertDescription.svelte +16 -0
- package/dist/lib/components/AlertDescription.svelte.d.ts +9 -0
- package/dist/lib/components/AlertDialog.svelte +136 -0
- package/dist/lib/components/AlertDialog.svelte.d.ts +79 -0
- package/dist/lib/components/AlertTitle.svelte +16 -0
- package/dist/lib/components/AlertTitle.svelte.d.ts +9 -0
- package/dist/lib/components/Avatar.svelte +56 -0
- package/dist/lib/components/Avatar.svelte.d.ts +26 -0
- package/dist/lib/components/AvatarFallback.svelte +31 -0
- package/dist/lib/components/AvatarFallback.svelte.d.ts +17 -0
- package/dist/lib/components/AvatarImage.svelte +29 -0
- package/dist/lib/components/AvatarImage.svelte.d.ts +12 -0
- package/dist/lib/components/Badge.svelte +73 -0
- package/dist/lib/components/Badge.svelte.d.ts +11 -0
- package/dist/lib/components/Button.svelte +130 -0
- package/dist/lib/components/Button.svelte.d.ts +17 -0
- package/dist/lib/components/Card.svelte +58 -0
- package/dist/lib/components/Card.svelte.d.ts +26 -0
- package/dist/lib/components/CardContent.svelte +16 -0
- package/dist/lib/components/CardContent.svelte.d.ts +9 -0
- package/dist/lib/components/CardDescription.svelte +16 -0
- package/dist/lib/components/CardDescription.svelte.d.ts +9 -0
- package/dist/lib/components/CardFooter.svelte +16 -0
- package/dist/lib/components/CardFooter.svelte.d.ts +9 -0
- package/dist/lib/components/CardHeader.svelte +16 -0
- package/dist/lib/components/CardHeader.svelte.d.ts +9 -0
- package/dist/lib/components/CardTitle.svelte +16 -0
- package/dist/lib/components/CardTitle.svelte.d.ts +9 -0
- package/dist/lib/components/Checkbox.svelte +65 -0
- package/dist/lib/components/Checkbox.svelte.d.ts +14 -0
- package/dist/lib/components/DataTable.svelte +334 -0
- package/dist/lib/components/DataTable.svelte.d.ts +103 -0
- package/dist/lib/components/Dialog.svelte +111 -0
- package/dist/lib/components/Dialog.svelte.d.ts +22 -0
- package/dist/lib/components/DropdownMenu.svelte +135 -0
- package/dist/lib/components/DropdownMenu.svelte.d.ts +33 -0
- package/dist/lib/components/FileUpload.svelte +448 -0
- package/dist/lib/components/FileUpload.svelte.d.ts +42 -0
- package/dist/lib/components/FormField.svelte +134 -0
- package/dist/lib/components/FormField.svelte.d.ts +37 -0
- package/dist/lib/components/Input.svelte +61 -0
- package/dist/lib/components/Input.svelte.d.ts +19 -0
- package/dist/lib/components/Label.svelte +33 -0
- package/dist/lib/components/Label.svelte.d.ts +11 -0
- package/dist/lib/components/LoadingLogo.svelte +124 -0
- package/dist/lib/components/LoadingLogo.svelte.d.ts +16 -0
- package/dist/lib/components/LogoMain.svelte +237 -0
- package/dist/lib/components/LogoMain.svelte.d.ts +20 -0
- package/dist/lib/components/PageHeader.svelte +90 -0
- package/dist/lib/components/PageHeader.svelte.d.ts +28 -0
- package/dist/lib/components/Section.svelte +44 -0
- package/dist/lib/components/Section.svelte.d.ts +28 -0
- package/dist/lib/components/Select.svelte +174 -0
- package/dist/lib/components/Select.svelte.d.ts +32 -0
- package/dist/lib/components/Separator.svelte +29 -0
- package/dist/lib/components/Separator.svelte.d.ts +9 -0
- package/dist/lib/components/Skeleton.svelte +35 -0
- package/dist/lib/components/Skeleton.svelte.d.ts +7 -0
- package/dist/lib/components/Spinner.svelte +50 -0
- package/dist/lib/components/Spinner.svelte.d.ts +8 -0
- package/dist/lib/components/Switch.svelte +56 -0
- package/dist/lib/components/Switch.svelte.d.ts +14 -0
- package/dist/lib/components/TabPanel.svelte +44 -0
- package/dist/lib/components/TabPanel.svelte.d.ts +12 -0
- package/dist/lib/components/Tabs.svelte +125 -0
- package/dist/lib/components/Tabs.svelte.d.ts +19 -0
- package/dist/lib/components/Textarea.svelte +54 -0
- package/dist/lib/components/Textarea.svelte.d.ts +16 -0
- package/dist/lib/components/Toast.svelte +116 -0
- package/dist/lib/components/Toast.svelte.d.ts +12 -0
- package/dist/lib/components/ToastContainer.svelte +56 -0
- package/dist/lib/components/ToastContainer.svelte.d.ts +8 -0
- package/dist/lib/components/Tooltip.svelte +55 -0
- package/dist/lib/components/Tooltip.svelte.d.ts +18 -0
- package/dist/lib/components/layout/AppShell.svelte +82 -0
- package/dist/lib/components/layout/AppShell.svelte.d.ts +44 -0
- package/dist/lib/components/layout/DashboardLayout.svelte +248 -0
- package/dist/lib/components/layout/DashboardLayout.svelte.d.ts +62 -0
- package/dist/lib/components/layout/Footer.svelte +130 -0
- package/dist/lib/components/layout/Footer.svelte.d.ts +32 -0
- package/dist/lib/components/layout/FormPageLayout.svelte +92 -0
- package/dist/lib/components/layout/FormPageLayout.svelte.d.ts +33 -0
- package/dist/lib/components/layout/Header.svelte +94 -0
- package/dist/lib/components/layout/Header.svelte.d.ts +30 -0
- package/dist/lib/components/layout/PublicLayout.svelte +180 -0
- package/dist/lib/components/layout/PublicLayout.svelte.d.ts +39 -0
- package/dist/lib/components/layout/QuickLinks.svelte +112 -0
- package/dist/lib/components/layout/QuickLinks.svelte.d.ts +27 -0
- package/dist/lib/components/layout/Sidebar.svelte +243 -0
- package/dist/lib/components/layout/Sidebar.svelte.d.ts +48 -0
- package/dist/lib/composables/index.d.ts +8 -0
- package/dist/lib/composables/index.js +10 -0
- package/dist/lib/composables/useAsync.svelte.d.ts +102 -0
- package/dist/lib/composables/useAsync.svelte.js +210 -0
- package/dist/lib/composables/useForm.svelte.d.ts +123 -0
- package/dist/lib/composables/useForm.svelte.js +245 -0
- package/dist/lib/index.d.ts +65 -0
- package/dist/lib/index.js +83 -0
- package/dist/lib/performance.d.ts +79 -0
- package/dist/lib/performance.js +170 -0
- package/dist/lib/schemas/auth.d.ts +410 -0
- package/dist/lib/schemas/auth.js +216 -0
- package/dist/lib/schemas/common.d.ts +267 -0
- package/dist/lib/schemas/common.js +268 -0
- package/dist/lib/schemas/index.d.ts +24 -0
- package/dist/lib/schemas/index.js +32 -0
- package/dist/lib/stores/sidebar.svelte.d.ts +25 -0
- package/dist/lib/stores/sidebar.svelte.js +38 -0
- package/dist/lib/stores/theme.svelte.d.ts +72 -0
- package/dist/lib/stores/theme.svelte.js +150 -0
- package/dist/lib/stores/toast.svelte.d.ts +62 -0
- package/dist/lib/stores/toast.svelte.js +93 -0
- package/dist/lib/types/components.d.ts +85 -0
- package/dist/lib/types/components.js +7 -0
- package/dist/lib/types/layout.d.ts +258 -0
- package/dist/lib/types/layout.js +7 -0
- package/dist/lib/utils.d.ts +6 -0
- package/dist/lib/utils.js +9 -0
- package/dist/lib/validation.d.ts +101 -0
- package/dist/lib/validation.js +170 -0
- package/package.json +56 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Validation Schemas
|
|
3
|
+
*
|
|
4
|
+
* Zod schemas for authentication-related forms and data validation.
|
|
5
|
+
* These schemas provide consistent validation rules across the application.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
/**
|
|
9
|
+
* Email field validation
|
|
10
|
+
* - Required
|
|
11
|
+
* - Valid email format
|
|
12
|
+
*/
|
|
13
|
+
export declare const emailSchema: z.ZodString;
|
|
14
|
+
/**
|
|
15
|
+
* Password field validation
|
|
16
|
+
* - Minimum 8 characters
|
|
17
|
+
* - At least one uppercase letter
|
|
18
|
+
* - At least one lowercase letter
|
|
19
|
+
* - At least one number
|
|
20
|
+
*/
|
|
21
|
+
export declare const passwordSchema: z.ZodString;
|
|
22
|
+
/**
|
|
23
|
+
* Simple password (for login - less strict validation)
|
|
24
|
+
* - Just requires minimum length
|
|
25
|
+
*/
|
|
26
|
+
export declare const loginPasswordSchema: z.ZodString;
|
|
27
|
+
/**
|
|
28
|
+
* Username field validation
|
|
29
|
+
* - 3-50 characters
|
|
30
|
+
* - Alphanumeric, underscores, hyphens
|
|
31
|
+
*/
|
|
32
|
+
export declare const usernameSchema: z.ZodString;
|
|
33
|
+
/**
|
|
34
|
+
* Full name field validation
|
|
35
|
+
* - 2-100 characters
|
|
36
|
+
*/
|
|
37
|
+
export declare const fullNameSchema: z.ZodString;
|
|
38
|
+
/**
|
|
39
|
+
* Phone number field validation
|
|
40
|
+
* - Optional
|
|
41
|
+
* - Valid phone format when provided
|
|
42
|
+
*/
|
|
43
|
+
export declare const phoneSchema: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
|
|
44
|
+
/**
|
|
45
|
+
* MFA/OTP code validation
|
|
46
|
+
* - 6 digits
|
|
47
|
+
*/
|
|
48
|
+
export declare const mfaCodeSchema: z.ZodString;
|
|
49
|
+
/**
|
|
50
|
+
* TOTP secret validation
|
|
51
|
+
* - Base32 encoded string
|
|
52
|
+
*/
|
|
53
|
+
export declare const totpSecretSchema: z.ZodString;
|
|
54
|
+
/**
|
|
55
|
+
* Login form schema
|
|
56
|
+
*/
|
|
57
|
+
export declare const loginSchema: z.ZodObject<{
|
|
58
|
+
email: z.ZodString;
|
|
59
|
+
password: z.ZodString;
|
|
60
|
+
rememberMe: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
61
|
+
}, "strip", z.ZodTypeAny, {
|
|
62
|
+
email: string;
|
|
63
|
+
password: string;
|
|
64
|
+
rememberMe: boolean;
|
|
65
|
+
}, {
|
|
66
|
+
email: string;
|
|
67
|
+
password: string;
|
|
68
|
+
rememberMe?: boolean | undefined;
|
|
69
|
+
}>;
|
|
70
|
+
export type LoginFormData = z.infer<typeof loginSchema>;
|
|
71
|
+
/**
|
|
72
|
+
* Registration form schema
|
|
73
|
+
*/
|
|
74
|
+
export declare const registerSchema: z.ZodEffects<z.ZodObject<{
|
|
75
|
+
email: z.ZodString;
|
|
76
|
+
username: z.ZodOptional<z.ZodString>;
|
|
77
|
+
fullName: z.ZodString;
|
|
78
|
+
password: z.ZodString;
|
|
79
|
+
confirmPassword: z.ZodString;
|
|
80
|
+
acceptTerms: z.ZodLiteral<true>;
|
|
81
|
+
}, "strip", z.ZodTypeAny, {
|
|
82
|
+
email: string;
|
|
83
|
+
password: string;
|
|
84
|
+
fullName: string;
|
|
85
|
+
confirmPassword: string;
|
|
86
|
+
acceptTerms: true;
|
|
87
|
+
username?: string | undefined;
|
|
88
|
+
}, {
|
|
89
|
+
email: string;
|
|
90
|
+
password: string;
|
|
91
|
+
fullName: string;
|
|
92
|
+
confirmPassword: string;
|
|
93
|
+
acceptTerms: true;
|
|
94
|
+
username?: string | undefined;
|
|
95
|
+
}>, {
|
|
96
|
+
email: string;
|
|
97
|
+
password: string;
|
|
98
|
+
fullName: string;
|
|
99
|
+
confirmPassword: string;
|
|
100
|
+
acceptTerms: true;
|
|
101
|
+
username?: string | undefined;
|
|
102
|
+
}, {
|
|
103
|
+
email: string;
|
|
104
|
+
password: string;
|
|
105
|
+
fullName: string;
|
|
106
|
+
confirmPassword: string;
|
|
107
|
+
acceptTerms: true;
|
|
108
|
+
username?: string | undefined;
|
|
109
|
+
}>;
|
|
110
|
+
export type RegisterFormData = z.infer<typeof registerSchema>;
|
|
111
|
+
/**
|
|
112
|
+
* Forgot password form schema
|
|
113
|
+
*/
|
|
114
|
+
export declare const forgotPasswordSchema: z.ZodObject<{
|
|
115
|
+
email: z.ZodString;
|
|
116
|
+
}, "strip", z.ZodTypeAny, {
|
|
117
|
+
email: string;
|
|
118
|
+
}, {
|
|
119
|
+
email: string;
|
|
120
|
+
}>;
|
|
121
|
+
export type ForgotPasswordFormData = z.infer<typeof forgotPasswordSchema>;
|
|
122
|
+
/**
|
|
123
|
+
* Reset password form schema
|
|
124
|
+
*/
|
|
125
|
+
export declare const resetPasswordSchema: z.ZodEffects<z.ZodObject<{
|
|
126
|
+
password: z.ZodString;
|
|
127
|
+
confirmPassword: z.ZodString;
|
|
128
|
+
token: z.ZodOptional<z.ZodString>;
|
|
129
|
+
}, "strip", z.ZodTypeAny, {
|
|
130
|
+
password: string;
|
|
131
|
+
confirmPassword: string;
|
|
132
|
+
token?: string | undefined;
|
|
133
|
+
}, {
|
|
134
|
+
password: string;
|
|
135
|
+
confirmPassword: string;
|
|
136
|
+
token?: string | undefined;
|
|
137
|
+
}>, {
|
|
138
|
+
password: string;
|
|
139
|
+
confirmPassword: string;
|
|
140
|
+
token?: string | undefined;
|
|
141
|
+
}, {
|
|
142
|
+
password: string;
|
|
143
|
+
confirmPassword: string;
|
|
144
|
+
token?: string | undefined;
|
|
145
|
+
}>;
|
|
146
|
+
export type ResetPasswordFormData = z.infer<typeof resetPasswordSchema>;
|
|
147
|
+
/**
|
|
148
|
+
* Change password form schema
|
|
149
|
+
*/
|
|
150
|
+
export declare const changePasswordSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
151
|
+
currentPassword: z.ZodString;
|
|
152
|
+
newPassword: z.ZodString;
|
|
153
|
+
confirmPassword: z.ZodString;
|
|
154
|
+
}, "strip", z.ZodTypeAny, {
|
|
155
|
+
confirmPassword: string;
|
|
156
|
+
currentPassword: string;
|
|
157
|
+
newPassword: string;
|
|
158
|
+
}, {
|
|
159
|
+
confirmPassword: string;
|
|
160
|
+
currentPassword: string;
|
|
161
|
+
newPassword: string;
|
|
162
|
+
}>, {
|
|
163
|
+
confirmPassword: string;
|
|
164
|
+
currentPassword: string;
|
|
165
|
+
newPassword: string;
|
|
166
|
+
}, {
|
|
167
|
+
confirmPassword: string;
|
|
168
|
+
currentPassword: string;
|
|
169
|
+
newPassword: string;
|
|
170
|
+
}>, {
|
|
171
|
+
confirmPassword: string;
|
|
172
|
+
currentPassword: string;
|
|
173
|
+
newPassword: string;
|
|
174
|
+
}, {
|
|
175
|
+
confirmPassword: string;
|
|
176
|
+
currentPassword: string;
|
|
177
|
+
newPassword: string;
|
|
178
|
+
}>;
|
|
179
|
+
export type ChangePasswordFormData = z.infer<typeof changePasswordSchema>;
|
|
180
|
+
/**
|
|
181
|
+
* MFA verification form schema
|
|
182
|
+
*/
|
|
183
|
+
export declare const mfaVerifySchema: z.ZodObject<{
|
|
184
|
+
code: z.ZodString;
|
|
185
|
+
trustDevice: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
186
|
+
}, "strip", z.ZodTypeAny, {
|
|
187
|
+
code: string;
|
|
188
|
+
trustDevice: boolean;
|
|
189
|
+
}, {
|
|
190
|
+
code: string;
|
|
191
|
+
trustDevice?: boolean | undefined;
|
|
192
|
+
}>;
|
|
193
|
+
export type MfaVerifyFormData = z.infer<typeof mfaVerifySchema>;
|
|
194
|
+
/**
|
|
195
|
+
* MFA setup form schema
|
|
196
|
+
*/
|
|
197
|
+
export declare const mfaSetupSchema: z.ZodObject<{
|
|
198
|
+
code: z.ZodString;
|
|
199
|
+
secret: z.ZodString;
|
|
200
|
+
}, "strip", z.ZodTypeAny, {
|
|
201
|
+
code: string;
|
|
202
|
+
secret: string;
|
|
203
|
+
}, {
|
|
204
|
+
code: string;
|
|
205
|
+
secret: string;
|
|
206
|
+
}>;
|
|
207
|
+
export type MfaSetupFormData = z.infer<typeof mfaSetupSchema>;
|
|
208
|
+
/**
|
|
209
|
+
* Profile update form schema
|
|
210
|
+
*/
|
|
211
|
+
export declare const profileUpdateSchema: z.ZodObject<{
|
|
212
|
+
fullName: z.ZodString;
|
|
213
|
+
email: z.ZodString;
|
|
214
|
+
phone: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
|
|
215
|
+
bio: z.ZodOptional<z.ZodString>;
|
|
216
|
+
avatarUrl: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
|
|
217
|
+
}, "strip", z.ZodTypeAny, {
|
|
218
|
+
email: string;
|
|
219
|
+
fullName: string;
|
|
220
|
+
phone?: string | undefined;
|
|
221
|
+
bio?: string | undefined;
|
|
222
|
+
avatarUrl?: string | undefined;
|
|
223
|
+
}, {
|
|
224
|
+
email: string;
|
|
225
|
+
fullName: string;
|
|
226
|
+
phone?: string | undefined;
|
|
227
|
+
bio?: string | undefined;
|
|
228
|
+
avatarUrl?: string | undefined;
|
|
229
|
+
}>;
|
|
230
|
+
export type ProfileUpdateFormData = z.infer<typeof profileUpdateSchema>;
|
|
231
|
+
/**
|
|
232
|
+
* Email change form schema (requires password confirmation)
|
|
233
|
+
*/
|
|
234
|
+
export declare const emailChangeSchema: z.ZodObject<{
|
|
235
|
+
newEmail: z.ZodString;
|
|
236
|
+
password: z.ZodString;
|
|
237
|
+
}, "strip", z.ZodTypeAny, {
|
|
238
|
+
password: string;
|
|
239
|
+
newEmail: string;
|
|
240
|
+
}, {
|
|
241
|
+
password: string;
|
|
242
|
+
newEmail: string;
|
|
243
|
+
}>;
|
|
244
|
+
export type EmailChangeFormData = z.infer<typeof emailChangeSchema>;
|
|
245
|
+
/**
|
|
246
|
+
* User schema
|
|
247
|
+
*/
|
|
248
|
+
export declare const userSchema: z.ZodObject<{
|
|
249
|
+
id: z.ZodString;
|
|
250
|
+
email: z.ZodString;
|
|
251
|
+
username: z.ZodOptional<z.ZodString>;
|
|
252
|
+
fullName: z.ZodOptional<z.ZodString>;
|
|
253
|
+
avatarUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
254
|
+
roles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
255
|
+
permissions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
256
|
+
mfaEnabled: z.ZodOptional<z.ZodBoolean>;
|
|
257
|
+
emailVerified: z.ZodOptional<z.ZodBoolean>;
|
|
258
|
+
createdAt: z.ZodOptional<z.ZodString>;
|
|
259
|
+
updatedAt: z.ZodOptional<z.ZodString>;
|
|
260
|
+
}, "strip", z.ZodTypeAny, {
|
|
261
|
+
id: string;
|
|
262
|
+
email: string;
|
|
263
|
+
username?: string | undefined;
|
|
264
|
+
fullName?: string | undefined;
|
|
265
|
+
avatarUrl?: string | null | undefined;
|
|
266
|
+
roles?: string[] | undefined;
|
|
267
|
+
permissions?: string[] | undefined;
|
|
268
|
+
mfaEnabled?: boolean | undefined;
|
|
269
|
+
emailVerified?: boolean | undefined;
|
|
270
|
+
createdAt?: string | undefined;
|
|
271
|
+
updatedAt?: string | undefined;
|
|
272
|
+
}, {
|
|
273
|
+
id: string;
|
|
274
|
+
email: string;
|
|
275
|
+
username?: string | undefined;
|
|
276
|
+
fullName?: string | undefined;
|
|
277
|
+
avatarUrl?: string | null | undefined;
|
|
278
|
+
roles?: string[] | undefined;
|
|
279
|
+
permissions?: string[] | undefined;
|
|
280
|
+
mfaEnabled?: boolean | undefined;
|
|
281
|
+
emailVerified?: boolean | undefined;
|
|
282
|
+
createdAt?: string | undefined;
|
|
283
|
+
updatedAt?: string | undefined;
|
|
284
|
+
}>;
|
|
285
|
+
export type User = z.infer<typeof userSchema>;
|
|
286
|
+
/**
|
|
287
|
+
* Auth tokens schema
|
|
288
|
+
*/
|
|
289
|
+
export declare const authTokensSchema: z.ZodObject<{
|
|
290
|
+
accessToken: z.ZodString;
|
|
291
|
+
refreshToken: z.ZodOptional<z.ZodString>;
|
|
292
|
+
expiresIn: z.ZodOptional<z.ZodNumber>;
|
|
293
|
+
tokenType: z.ZodOptional<z.ZodString>;
|
|
294
|
+
}, "strip", z.ZodTypeAny, {
|
|
295
|
+
accessToken: string;
|
|
296
|
+
refreshToken?: string | undefined;
|
|
297
|
+
expiresIn?: number | undefined;
|
|
298
|
+
tokenType?: string | undefined;
|
|
299
|
+
}, {
|
|
300
|
+
accessToken: string;
|
|
301
|
+
refreshToken?: string | undefined;
|
|
302
|
+
expiresIn?: number | undefined;
|
|
303
|
+
tokenType?: string | undefined;
|
|
304
|
+
}>;
|
|
305
|
+
export type AuthTokens = z.infer<typeof authTokensSchema>;
|
|
306
|
+
/**
|
|
307
|
+
* Login response schema
|
|
308
|
+
*/
|
|
309
|
+
export declare const loginResponseSchema: z.ZodObject<{
|
|
310
|
+
user: z.ZodOptional<z.ZodObject<{
|
|
311
|
+
id: z.ZodString;
|
|
312
|
+
email: z.ZodString;
|
|
313
|
+
username: z.ZodOptional<z.ZodString>;
|
|
314
|
+
fullName: z.ZodOptional<z.ZodString>;
|
|
315
|
+
avatarUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
316
|
+
roles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
317
|
+
permissions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
318
|
+
mfaEnabled: z.ZodOptional<z.ZodBoolean>;
|
|
319
|
+
emailVerified: z.ZodOptional<z.ZodBoolean>;
|
|
320
|
+
createdAt: z.ZodOptional<z.ZodString>;
|
|
321
|
+
updatedAt: z.ZodOptional<z.ZodString>;
|
|
322
|
+
}, "strip", z.ZodTypeAny, {
|
|
323
|
+
id: string;
|
|
324
|
+
email: string;
|
|
325
|
+
username?: string | undefined;
|
|
326
|
+
fullName?: string | undefined;
|
|
327
|
+
avatarUrl?: string | null | undefined;
|
|
328
|
+
roles?: string[] | undefined;
|
|
329
|
+
permissions?: string[] | undefined;
|
|
330
|
+
mfaEnabled?: boolean | undefined;
|
|
331
|
+
emailVerified?: boolean | undefined;
|
|
332
|
+
createdAt?: string | undefined;
|
|
333
|
+
updatedAt?: string | undefined;
|
|
334
|
+
}, {
|
|
335
|
+
id: string;
|
|
336
|
+
email: string;
|
|
337
|
+
username?: string | undefined;
|
|
338
|
+
fullName?: string | undefined;
|
|
339
|
+
avatarUrl?: string | null | undefined;
|
|
340
|
+
roles?: string[] | undefined;
|
|
341
|
+
permissions?: string[] | undefined;
|
|
342
|
+
mfaEnabled?: boolean | undefined;
|
|
343
|
+
emailVerified?: boolean | undefined;
|
|
344
|
+
createdAt?: string | undefined;
|
|
345
|
+
updatedAt?: string | undefined;
|
|
346
|
+
}>>;
|
|
347
|
+
tokens: z.ZodOptional<z.ZodObject<{
|
|
348
|
+
accessToken: z.ZodString;
|
|
349
|
+
refreshToken: z.ZodOptional<z.ZodString>;
|
|
350
|
+
expiresIn: z.ZodOptional<z.ZodNumber>;
|
|
351
|
+
tokenType: z.ZodOptional<z.ZodString>;
|
|
352
|
+
}, "strip", z.ZodTypeAny, {
|
|
353
|
+
accessToken: string;
|
|
354
|
+
refreshToken?: string | undefined;
|
|
355
|
+
expiresIn?: number | undefined;
|
|
356
|
+
tokenType?: string | undefined;
|
|
357
|
+
}, {
|
|
358
|
+
accessToken: string;
|
|
359
|
+
refreshToken?: string | undefined;
|
|
360
|
+
expiresIn?: number | undefined;
|
|
361
|
+
tokenType?: string | undefined;
|
|
362
|
+
}>>;
|
|
363
|
+
mfaRequired: z.ZodOptional<z.ZodBoolean>;
|
|
364
|
+
mfaToken: z.ZodOptional<z.ZodString>;
|
|
365
|
+
}, "strip", z.ZodTypeAny, {
|
|
366
|
+
user?: {
|
|
367
|
+
id: string;
|
|
368
|
+
email: string;
|
|
369
|
+
username?: string | undefined;
|
|
370
|
+
fullName?: string | undefined;
|
|
371
|
+
avatarUrl?: string | null | undefined;
|
|
372
|
+
roles?: string[] | undefined;
|
|
373
|
+
permissions?: string[] | undefined;
|
|
374
|
+
mfaEnabled?: boolean | undefined;
|
|
375
|
+
emailVerified?: boolean | undefined;
|
|
376
|
+
createdAt?: string | undefined;
|
|
377
|
+
updatedAt?: string | undefined;
|
|
378
|
+
} | undefined;
|
|
379
|
+
tokens?: {
|
|
380
|
+
accessToken: string;
|
|
381
|
+
refreshToken?: string | undefined;
|
|
382
|
+
expiresIn?: number | undefined;
|
|
383
|
+
tokenType?: string | undefined;
|
|
384
|
+
} | undefined;
|
|
385
|
+
mfaRequired?: boolean | undefined;
|
|
386
|
+
mfaToken?: string | undefined;
|
|
387
|
+
}, {
|
|
388
|
+
user?: {
|
|
389
|
+
id: string;
|
|
390
|
+
email: string;
|
|
391
|
+
username?: string | undefined;
|
|
392
|
+
fullName?: string | undefined;
|
|
393
|
+
avatarUrl?: string | null | undefined;
|
|
394
|
+
roles?: string[] | undefined;
|
|
395
|
+
permissions?: string[] | undefined;
|
|
396
|
+
mfaEnabled?: boolean | undefined;
|
|
397
|
+
emailVerified?: boolean | undefined;
|
|
398
|
+
createdAt?: string | undefined;
|
|
399
|
+
updatedAt?: string | undefined;
|
|
400
|
+
} | undefined;
|
|
401
|
+
tokens?: {
|
|
402
|
+
accessToken: string;
|
|
403
|
+
refreshToken?: string | undefined;
|
|
404
|
+
expiresIn?: number | undefined;
|
|
405
|
+
tokenType?: string | undefined;
|
|
406
|
+
} | undefined;
|
|
407
|
+
mfaRequired?: boolean | undefined;
|
|
408
|
+
mfaToken?: string | undefined;
|
|
409
|
+
}>;
|
|
410
|
+
export type LoginResponse = z.infer<typeof loginResponseSchema>;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Validation Schemas
|
|
3
|
+
*
|
|
4
|
+
* Zod schemas for authentication-related forms and data validation.
|
|
5
|
+
* These schemas provide consistent validation rules across the application.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Field Schemas (reusable field-level validators)
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* Email field validation
|
|
13
|
+
* - Required
|
|
14
|
+
* - Valid email format
|
|
15
|
+
*/
|
|
16
|
+
export const emailSchema = z
|
|
17
|
+
.string({ required_error: 'Email is required' })
|
|
18
|
+
.min(1, 'Email is required')
|
|
19
|
+
.email('Please enter a valid email address');
|
|
20
|
+
/**
|
|
21
|
+
* Password field validation
|
|
22
|
+
* - Minimum 8 characters
|
|
23
|
+
* - At least one uppercase letter
|
|
24
|
+
* - At least one lowercase letter
|
|
25
|
+
* - At least one number
|
|
26
|
+
*/
|
|
27
|
+
export const passwordSchema = z
|
|
28
|
+
.string({ required_error: 'Password is required' })
|
|
29
|
+
.min(8, 'Password must be at least 8 characters')
|
|
30
|
+
.regex(/[A-Z]/, 'Password must contain at least one uppercase letter')
|
|
31
|
+
.regex(/[a-z]/, 'Password must contain at least one lowercase letter')
|
|
32
|
+
.regex(/[0-9]/, 'Password must contain at least one number');
|
|
33
|
+
/**
|
|
34
|
+
* Simple password (for login - less strict validation)
|
|
35
|
+
* - Just requires minimum length
|
|
36
|
+
*/
|
|
37
|
+
export const loginPasswordSchema = z
|
|
38
|
+
.string({ required_error: 'Password is required' })
|
|
39
|
+
.min(1, 'Password is required');
|
|
40
|
+
/**
|
|
41
|
+
* Username field validation
|
|
42
|
+
* - 3-50 characters
|
|
43
|
+
* - Alphanumeric, underscores, hyphens
|
|
44
|
+
*/
|
|
45
|
+
export const usernameSchema = z
|
|
46
|
+
.string({ required_error: 'Username is required' })
|
|
47
|
+
.min(3, 'Username must be at least 3 characters')
|
|
48
|
+
.max(50, 'Username must be at most 50 characters')
|
|
49
|
+
.regex(/^[a-zA-Z0-9_-]+$/, 'Username can only contain letters, numbers, underscores, and hyphens');
|
|
50
|
+
/**
|
|
51
|
+
* Full name field validation
|
|
52
|
+
* - 2-100 characters
|
|
53
|
+
*/
|
|
54
|
+
export const fullNameSchema = z
|
|
55
|
+
.string({ required_error: 'Full name is required' })
|
|
56
|
+
.min(2, 'Full name must be at least 2 characters')
|
|
57
|
+
.max(100, 'Full name must be at most 100 characters');
|
|
58
|
+
/**
|
|
59
|
+
* Phone number field validation
|
|
60
|
+
* - Optional
|
|
61
|
+
* - Valid phone format when provided
|
|
62
|
+
*/
|
|
63
|
+
export const phoneSchema = z
|
|
64
|
+
.string()
|
|
65
|
+
.regex(/^[+]?[(]?[0-9]{1,4}[)]?[-\s./0-9]*$/, 'Please enter a valid phone number')
|
|
66
|
+
.optional()
|
|
67
|
+
.or(z.literal(''));
|
|
68
|
+
/**
|
|
69
|
+
* MFA/OTP code validation
|
|
70
|
+
* - 6 digits
|
|
71
|
+
*/
|
|
72
|
+
export const mfaCodeSchema = z
|
|
73
|
+
.string({ required_error: 'Verification code is required' })
|
|
74
|
+
.length(6, 'Verification code must be 6 digits')
|
|
75
|
+
.regex(/^[0-9]+$/, 'Verification code must contain only numbers');
|
|
76
|
+
/**
|
|
77
|
+
* TOTP secret validation
|
|
78
|
+
* - Base32 encoded string
|
|
79
|
+
*/
|
|
80
|
+
export const totpSecretSchema = z
|
|
81
|
+
.string({ required_error: 'TOTP secret is required' })
|
|
82
|
+
.min(16, 'Invalid TOTP secret')
|
|
83
|
+
.regex(/^[A-Z2-7]+=*$/i, 'Invalid TOTP secret format');
|
|
84
|
+
// ============================================================================
|
|
85
|
+
// Form Schemas (complete form validation)
|
|
86
|
+
// ============================================================================
|
|
87
|
+
/**
|
|
88
|
+
* Login form schema
|
|
89
|
+
*/
|
|
90
|
+
export const loginSchema = z.object({
|
|
91
|
+
email: emailSchema,
|
|
92
|
+
password: loginPasswordSchema,
|
|
93
|
+
rememberMe: z.boolean().optional().default(false),
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* Registration form schema
|
|
97
|
+
*/
|
|
98
|
+
export const registerSchema = z
|
|
99
|
+
.object({
|
|
100
|
+
email: emailSchema,
|
|
101
|
+
username: usernameSchema.optional(),
|
|
102
|
+
fullName: fullNameSchema,
|
|
103
|
+
password: passwordSchema,
|
|
104
|
+
confirmPassword: z.string({ required_error: 'Please confirm your password' }),
|
|
105
|
+
acceptTerms: z.literal(true, {
|
|
106
|
+
errorMap: () => ({ message: 'You must accept the terms and conditions' }),
|
|
107
|
+
}),
|
|
108
|
+
})
|
|
109
|
+
.refine((data) => data.password === data.confirmPassword, {
|
|
110
|
+
message: 'Passwords do not match',
|
|
111
|
+
path: ['confirmPassword'],
|
|
112
|
+
});
|
|
113
|
+
/**
|
|
114
|
+
* Forgot password form schema
|
|
115
|
+
*/
|
|
116
|
+
export const forgotPasswordSchema = z.object({
|
|
117
|
+
email: emailSchema,
|
|
118
|
+
});
|
|
119
|
+
/**
|
|
120
|
+
* Reset password form schema
|
|
121
|
+
*/
|
|
122
|
+
export const resetPasswordSchema = z
|
|
123
|
+
.object({
|
|
124
|
+
password: passwordSchema,
|
|
125
|
+
confirmPassword: z.string({ required_error: 'Please confirm your password' }),
|
|
126
|
+
token: z.string().optional(),
|
|
127
|
+
})
|
|
128
|
+
.refine((data) => data.password === data.confirmPassword, {
|
|
129
|
+
message: 'Passwords do not match',
|
|
130
|
+
path: ['confirmPassword'],
|
|
131
|
+
});
|
|
132
|
+
/**
|
|
133
|
+
* Change password form schema
|
|
134
|
+
*/
|
|
135
|
+
export const changePasswordSchema = z
|
|
136
|
+
.object({
|
|
137
|
+
currentPassword: loginPasswordSchema,
|
|
138
|
+
newPassword: passwordSchema,
|
|
139
|
+
confirmPassword: z.string({ required_error: 'Please confirm your new password' }),
|
|
140
|
+
})
|
|
141
|
+
.refine((data) => data.newPassword === data.confirmPassword, {
|
|
142
|
+
message: 'Passwords do not match',
|
|
143
|
+
path: ['confirmPassword'],
|
|
144
|
+
})
|
|
145
|
+
.refine((data) => data.currentPassword !== data.newPassword, {
|
|
146
|
+
message: 'New password must be different from current password',
|
|
147
|
+
path: ['newPassword'],
|
|
148
|
+
});
|
|
149
|
+
/**
|
|
150
|
+
* MFA verification form schema
|
|
151
|
+
*/
|
|
152
|
+
export const mfaVerifySchema = z.object({
|
|
153
|
+
code: mfaCodeSchema,
|
|
154
|
+
trustDevice: z.boolean().optional().default(false),
|
|
155
|
+
});
|
|
156
|
+
/**
|
|
157
|
+
* MFA setup form schema
|
|
158
|
+
*/
|
|
159
|
+
export const mfaSetupSchema = z.object({
|
|
160
|
+
code: mfaCodeSchema,
|
|
161
|
+
secret: totpSecretSchema,
|
|
162
|
+
});
|
|
163
|
+
/**
|
|
164
|
+
* Profile update form schema
|
|
165
|
+
*/
|
|
166
|
+
export const profileUpdateSchema = z.object({
|
|
167
|
+
fullName: fullNameSchema,
|
|
168
|
+
email: emailSchema,
|
|
169
|
+
phone: phoneSchema,
|
|
170
|
+
bio: z.string().max(500, 'Bio must be at most 500 characters').optional(),
|
|
171
|
+
avatarUrl: z.string().url('Please enter a valid URL').optional().or(z.literal('')),
|
|
172
|
+
});
|
|
173
|
+
/**
|
|
174
|
+
* Email change form schema (requires password confirmation)
|
|
175
|
+
*/
|
|
176
|
+
export const emailChangeSchema = z.object({
|
|
177
|
+
newEmail: emailSchema,
|
|
178
|
+
password: loginPasswordSchema,
|
|
179
|
+
});
|
|
180
|
+
// ============================================================================
|
|
181
|
+
// API Response Schemas (for validating API responses)
|
|
182
|
+
// ============================================================================
|
|
183
|
+
/**
|
|
184
|
+
* User schema
|
|
185
|
+
*/
|
|
186
|
+
export const userSchema = z.object({
|
|
187
|
+
id: z.string(),
|
|
188
|
+
email: z.string().email(),
|
|
189
|
+
username: z.string().optional(),
|
|
190
|
+
fullName: z.string().optional(),
|
|
191
|
+
avatarUrl: z.string().url().optional().nullable(),
|
|
192
|
+
roles: z.array(z.string()).optional(),
|
|
193
|
+
permissions: z.array(z.string()).optional(),
|
|
194
|
+
mfaEnabled: z.boolean().optional(),
|
|
195
|
+
emailVerified: z.boolean().optional(),
|
|
196
|
+
createdAt: z.string().datetime().optional(),
|
|
197
|
+
updatedAt: z.string().datetime().optional(),
|
|
198
|
+
});
|
|
199
|
+
/**
|
|
200
|
+
* Auth tokens schema
|
|
201
|
+
*/
|
|
202
|
+
export const authTokensSchema = z.object({
|
|
203
|
+
accessToken: z.string(),
|
|
204
|
+
refreshToken: z.string().optional(),
|
|
205
|
+
expiresIn: z.number().optional(),
|
|
206
|
+
tokenType: z.string().optional(),
|
|
207
|
+
});
|
|
208
|
+
/**
|
|
209
|
+
* Login response schema
|
|
210
|
+
*/
|
|
211
|
+
export const loginResponseSchema = z.object({
|
|
212
|
+
user: userSchema.optional(),
|
|
213
|
+
tokens: authTokensSchema.optional(),
|
|
214
|
+
mfaRequired: z.boolean().optional(),
|
|
215
|
+
mfaToken: z.string().optional(),
|
|
216
|
+
});
|