@sqrzro/server 2.0.0-bz.9 → 2.0.0-r19.3
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/auth.js +1 -1
- package/cache.js +1 -1
- package/dist/auth/index.cjs +3 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +110 -0
- package/dist/auth/index.d.ts +110 -6
- package/dist/auth/index.js +3 -6
- package/dist/auth/index.js.map +1 -0
- package/dist/cache/index.cjs +2 -0
- package/dist/cache/index.cjs.map +1 -0
- package/dist/cache/index.d.cts +4 -0
- package/dist/cache/index.d.ts +4 -1
- package/dist/cache/index.js +2 -1
- package/dist/cache/index.js.map +1 -0
- package/dist/database/schema.cjs +2 -0
- package/dist/database/schema.cjs.map +1 -0
- package/dist/database/schema.d.cts +405 -0
- package/dist/database/schema.d.ts +155 -34
- package/dist/database/schema.js +2 -42
- package/dist/database/schema.js.map +1 -0
- package/dist/forms/index.cjs +2 -0
- package/dist/forms/index.cjs.map +1 -0
- package/dist/forms/index.d.cts +50 -0
- package/dist/forms/index.d.ts +50 -3
- package/dist/forms/index.js +2 -3
- package/dist/forms/index.js.map +1 -0
- package/dist/lists/index.cjs +2 -0
- package/dist/lists/index.cjs.map +1 -0
- package/dist/lists/{ListService.d.ts → index.d.cts} +5 -3
- package/dist/lists/index.d.ts +18 -1
- package/dist/lists/index.js +2 -1
- package/dist/lists/index.js.map +1 -0
- package/dist/mail/index.cjs +3 -0
- package/dist/mail/index.cjs.map +1 -0
- package/dist/mail/index.d.cts +19 -0
- package/dist/mail/index.d.ts +19 -1
- package/dist/mail/index.js +3 -1
- package/dist/mail/index.js.map +1 -0
- package/dist/middleware.cjs +2 -0
- package/dist/middleware.cjs.map +1 -0
- package/dist/middleware.d.cts +5 -0
- package/dist/middleware.d.ts +5 -3
- package/dist/middleware.js +2 -30
- package/dist/middleware.js.map +1 -0
- package/dist/url/index.cjs +3 -0
- package/dist/url/index.cjs.map +1 -0
- package/dist/url/{URLService.d.ts → index.d.cts} +9 -2
- package/dist/url/index.d.ts +33 -1
- package/dist/url/index.js +3 -1
- package/dist/url/index.js.map +1 -0
- package/forms.js +1 -1
- package/jest.config.js +7 -0
- package/lists.js +1 -1
- package/mail.js +1 -1
- package/middleware.js +1 -1
- package/next-env.d.ts +5 -0
- package/package.json +77 -46
- package/schema.js +1 -1
- package/url.js +1 -1
- package/database.d.ts +0 -1
- package/database.js +0 -1
- package/dist/auth/AuthService.d.ts +0 -14
- package/dist/auth/AuthService.js +0 -135
- package/dist/auth/ClientService.d.ts +0 -11
- package/dist/auth/ClientService.js +0 -47
- package/dist/auth/LoginRequest.d.ts +0 -4
- package/dist/auth/LoginRequest.js +0 -8
- package/dist/auth/MFARequest.d.ts +0 -4
- package/dist/auth/MFARequest.js +0 -9
- package/dist/auth/MFAService.d.ts +0 -6
- package/dist/auth/MFAService.js +0 -105
- package/dist/auth/PasswordRequest.d.ts +0 -4
- package/dist/auth/PasswordRequest.js +0 -12
- package/dist/auth/PasswordResetRequest.d.ts +0 -4
- package/dist/auth/PasswordResetRequest.js +0 -13
- package/dist/auth/PasswordService.d.ts +0 -8
- package/dist/auth/PasswordService.js +0 -54
- package/dist/auth/SessionService.d.ts +0 -42
- package/dist/auth/SessionService.js +0 -127
- package/dist/auth/interfaces.d.ts +0 -20
- package/dist/auth/interfaces.js +0 -1
- package/dist/cache/CacheService.d.ts +0 -2
- package/dist/cache/CacheService.js +0 -14
- package/dist/database/DatabaseService.d.ts +0 -7
- package/dist/database/DatabaseService.js +0 -12
- package/dist/forms/FormService.d.ts +0 -16
- package/dist/forms/FormService.js +0 -78
- package/dist/forms/ImageService.d.ts +0 -7
- package/dist/forms/ImageService.js +0 -19
- package/dist/forms/ValidationError.d.ts +0 -4
- package/dist/forms/ValidationError.js +0 -7
- package/dist/forms/ValidationService.d.ts +0 -20
- package/dist/forms/ValidationService.js +0 -59
- package/dist/forms/lang.d.ts +0 -2
- package/dist/forms/lang.js +0 -115
- package/dist/lists/ListService.js +0 -28
- package/dist/mail/MailService.d.ts +0 -12
- package/dist/mail/MailService.js +0 -55
- package/dist/url/URLService.js +0 -48
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
2
|
+
|
|
3
|
+
declare const mfaType: drizzle_orm_pg_core.PgEnum<["TOTP", "HARDWARE"]>;
|
|
4
|
+
declare const scope: drizzle_orm_pg_core.PgEnum<["ANON", "MFA", "AUTHED"]>;
|
|
5
|
+
type Scope = (typeof scope.enumValues)[number];
|
|
6
|
+
declare const authSchema: drizzle_orm_pg_core.PgSchema<"auth">;
|
|
7
|
+
declare const authUserTable: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
6
8
|
name: "user_credentials";
|
|
7
9
|
schema: "auth";
|
|
8
10
|
columns: {
|
|
9
|
-
id:
|
|
11
|
+
id: drizzle_orm_pg_core.PgColumn<{
|
|
10
12
|
name: "id";
|
|
11
13
|
tableName: "user_credentials";
|
|
12
14
|
dataType: "string";
|
|
@@ -15,10 +17,15 @@ export declare const authUserTable: import("drizzle-orm/pg-core").PgTableWithCol
|
|
|
15
17
|
driverParam: string;
|
|
16
18
|
notNull: true;
|
|
17
19
|
hasDefault: false;
|
|
20
|
+
isPrimaryKey: true;
|
|
21
|
+
isAutoincrement: false;
|
|
22
|
+
hasRuntimeDefault: false;
|
|
18
23
|
enumValues: [string, ...string[]];
|
|
19
24
|
baseColumn: never;
|
|
25
|
+
identity: undefined;
|
|
26
|
+
generated: undefined;
|
|
20
27
|
}, {}, {}>;
|
|
21
|
-
email:
|
|
28
|
+
email: drizzle_orm_pg_core.PgColumn<{
|
|
22
29
|
name: "email";
|
|
23
30
|
tableName: "user_credentials";
|
|
24
31
|
dataType: "string";
|
|
@@ -27,10 +34,15 @@ export declare const authUserTable: import("drizzle-orm/pg-core").PgTableWithCol
|
|
|
27
34
|
driverParam: string;
|
|
28
35
|
notNull: true;
|
|
29
36
|
hasDefault: false;
|
|
37
|
+
isPrimaryKey: false;
|
|
38
|
+
isAutoincrement: false;
|
|
39
|
+
hasRuntimeDefault: false;
|
|
30
40
|
enumValues: [string, ...string[]];
|
|
31
41
|
baseColumn: never;
|
|
42
|
+
identity: undefined;
|
|
43
|
+
generated: undefined;
|
|
32
44
|
}, {}, {}>;
|
|
33
|
-
password:
|
|
45
|
+
password: drizzle_orm_pg_core.PgColumn<{
|
|
34
46
|
name: "password";
|
|
35
47
|
tableName: "user_credentials";
|
|
36
48
|
dataType: "string";
|
|
@@ -39,10 +51,15 @@ export declare const authUserTable: import("drizzle-orm/pg-core").PgTableWithCol
|
|
|
39
51
|
driverParam: string;
|
|
40
52
|
notNull: false;
|
|
41
53
|
hasDefault: false;
|
|
54
|
+
isPrimaryKey: false;
|
|
55
|
+
isAutoincrement: false;
|
|
56
|
+
hasRuntimeDefault: false;
|
|
42
57
|
enumValues: [string, ...string[]];
|
|
43
58
|
baseColumn: never;
|
|
59
|
+
identity: undefined;
|
|
60
|
+
generated: undefined;
|
|
44
61
|
}, {}, {}>;
|
|
45
|
-
role:
|
|
62
|
+
role: drizzle_orm_pg_core.PgColumn<{
|
|
46
63
|
name: "role";
|
|
47
64
|
tableName: "user_credentials";
|
|
48
65
|
dataType: "number";
|
|
@@ -51,18 +68,40 @@ export declare const authUserTable: import("drizzle-orm/pg-core").PgTableWithCol
|
|
|
51
68
|
driverParam: string | number;
|
|
52
69
|
notNull: true;
|
|
53
70
|
hasDefault: true;
|
|
71
|
+
isPrimaryKey: false;
|
|
72
|
+
isAutoincrement: false;
|
|
73
|
+
hasRuntimeDefault: false;
|
|
54
74
|
enumValues: undefined;
|
|
55
75
|
baseColumn: never;
|
|
76
|
+
identity: undefined;
|
|
77
|
+
generated: undefined;
|
|
78
|
+
}, {}, {}>;
|
|
79
|
+
deletedAt: drizzle_orm_pg_core.PgColumn<{
|
|
80
|
+
name: "deletedAt";
|
|
81
|
+
tableName: "user_credentials";
|
|
82
|
+
dataType: "date";
|
|
83
|
+
columnType: "PgTimestamp";
|
|
84
|
+
data: Date;
|
|
85
|
+
driverParam: string;
|
|
86
|
+
notNull: false;
|
|
87
|
+
hasDefault: false;
|
|
88
|
+
isPrimaryKey: false;
|
|
89
|
+
isAutoincrement: false;
|
|
90
|
+
hasRuntimeDefault: false;
|
|
91
|
+
enumValues: undefined;
|
|
92
|
+
baseColumn: never;
|
|
93
|
+
identity: undefined;
|
|
94
|
+
generated: undefined;
|
|
56
95
|
}, {}, {}>;
|
|
57
96
|
};
|
|
58
97
|
dialect: "pg";
|
|
59
98
|
}>;
|
|
60
|
-
|
|
61
|
-
|
|
99
|
+
type AuthUser = typeof authUserTable.$inferSelect;
|
|
100
|
+
declare const authSessionTable: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
62
101
|
name: "sessions";
|
|
63
102
|
schema: "auth";
|
|
64
103
|
columns: {
|
|
65
|
-
id:
|
|
104
|
+
id: drizzle_orm_pg_core.PgColumn<{
|
|
66
105
|
name: "id";
|
|
67
106
|
tableName: "sessions";
|
|
68
107
|
dataType: "string";
|
|
@@ -71,10 +110,15 @@ export declare const authSessionTable: import("drizzle-orm/pg-core").PgTableWith
|
|
|
71
110
|
driverParam: string;
|
|
72
111
|
notNull: true;
|
|
73
112
|
hasDefault: false;
|
|
113
|
+
isPrimaryKey: true;
|
|
114
|
+
isAutoincrement: false;
|
|
115
|
+
hasRuntimeDefault: false;
|
|
74
116
|
enumValues: [string, ...string[]];
|
|
75
117
|
baseColumn: never;
|
|
118
|
+
identity: undefined;
|
|
119
|
+
generated: undefined;
|
|
76
120
|
}, {}, {}>;
|
|
77
|
-
userId:
|
|
121
|
+
userId: drizzle_orm_pg_core.PgColumn<{
|
|
78
122
|
name: "userId";
|
|
79
123
|
tableName: "sessions";
|
|
80
124
|
dataType: "string";
|
|
@@ -83,10 +127,15 @@ export declare const authSessionTable: import("drizzle-orm/pg-core").PgTableWith
|
|
|
83
127
|
driverParam: string;
|
|
84
128
|
notNull: true;
|
|
85
129
|
hasDefault: false;
|
|
130
|
+
isPrimaryKey: false;
|
|
131
|
+
isAutoincrement: false;
|
|
132
|
+
hasRuntimeDefault: false;
|
|
86
133
|
enumValues: [string, ...string[]];
|
|
87
134
|
baseColumn: never;
|
|
135
|
+
identity: undefined;
|
|
136
|
+
generated: undefined;
|
|
88
137
|
}, {}, {}>;
|
|
89
|
-
scope:
|
|
138
|
+
scope: drizzle_orm_pg_core.PgColumn<{
|
|
90
139
|
name: "scope";
|
|
91
140
|
tableName: "sessions";
|
|
92
141
|
dataType: "string";
|
|
@@ -95,10 +144,15 @@ export declare const authSessionTable: import("drizzle-orm/pg-core").PgTableWith
|
|
|
95
144
|
driverParam: string;
|
|
96
145
|
notNull: true;
|
|
97
146
|
hasDefault: true;
|
|
147
|
+
isPrimaryKey: false;
|
|
148
|
+
isAutoincrement: false;
|
|
149
|
+
hasRuntimeDefault: false;
|
|
98
150
|
enumValues: ["ANON", "MFA", "AUTHED"];
|
|
99
151
|
baseColumn: never;
|
|
152
|
+
identity: undefined;
|
|
153
|
+
generated: undefined;
|
|
100
154
|
}, {}, {}>;
|
|
101
|
-
expiresAt:
|
|
155
|
+
expiresAt: drizzle_orm_pg_core.PgColumn<{
|
|
102
156
|
name: "expiresAt";
|
|
103
157
|
tableName: "sessions";
|
|
104
158
|
dataType: "date";
|
|
@@ -107,18 +161,23 @@ export declare const authSessionTable: import("drizzle-orm/pg-core").PgTableWith
|
|
|
107
161
|
driverParam: string;
|
|
108
162
|
notNull: true;
|
|
109
163
|
hasDefault: false;
|
|
164
|
+
isPrimaryKey: false;
|
|
165
|
+
isAutoincrement: false;
|
|
166
|
+
hasRuntimeDefault: false;
|
|
110
167
|
enumValues: undefined;
|
|
111
168
|
baseColumn: never;
|
|
169
|
+
identity: undefined;
|
|
170
|
+
generated: undefined;
|
|
112
171
|
}, {}, {}>;
|
|
113
172
|
};
|
|
114
173
|
dialect: "pg";
|
|
115
174
|
}>;
|
|
116
|
-
|
|
117
|
-
|
|
175
|
+
type AuthSession = typeof authSessionTable.$inferSelect;
|
|
176
|
+
declare const authResetTable: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
118
177
|
name: "resets";
|
|
119
178
|
schema: "auth";
|
|
120
179
|
columns: {
|
|
121
|
-
id:
|
|
180
|
+
id: drizzle_orm_pg_core.PgColumn<{
|
|
122
181
|
name: "id";
|
|
123
182
|
tableName: "resets";
|
|
124
183
|
dataType: "string";
|
|
@@ -127,10 +186,15 @@ export declare const authResetTable: import("drizzle-orm/pg-core").PgTableWithCo
|
|
|
127
186
|
driverParam: string;
|
|
128
187
|
notNull: true;
|
|
129
188
|
hasDefault: false;
|
|
189
|
+
isPrimaryKey: true;
|
|
190
|
+
isAutoincrement: false;
|
|
191
|
+
hasRuntimeDefault: false;
|
|
130
192
|
enumValues: [string, ...string[]];
|
|
131
193
|
baseColumn: never;
|
|
194
|
+
identity: undefined;
|
|
195
|
+
generated: undefined;
|
|
132
196
|
}, {}, {}>;
|
|
133
|
-
userId:
|
|
197
|
+
userId: drizzle_orm_pg_core.PgColumn<{
|
|
134
198
|
name: "userId";
|
|
135
199
|
tableName: "resets";
|
|
136
200
|
dataType: "string";
|
|
@@ -139,10 +203,15 @@ export declare const authResetTable: import("drizzle-orm/pg-core").PgTableWithCo
|
|
|
139
203
|
driverParam: string;
|
|
140
204
|
notNull: true;
|
|
141
205
|
hasDefault: false;
|
|
206
|
+
isPrimaryKey: false;
|
|
207
|
+
isAutoincrement: false;
|
|
208
|
+
hasRuntimeDefault: false;
|
|
142
209
|
enumValues: [string, ...string[]];
|
|
143
210
|
baseColumn: never;
|
|
211
|
+
identity: undefined;
|
|
212
|
+
generated: undefined;
|
|
144
213
|
}, {}, {}>;
|
|
145
|
-
expiresAt:
|
|
214
|
+
expiresAt: drizzle_orm_pg_core.PgColumn<{
|
|
146
215
|
name: "expiresAt";
|
|
147
216
|
tableName: "resets";
|
|
148
217
|
dataType: "date";
|
|
@@ -151,18 +220,23 @@ export declare const authResetTable: import("drizzle-orm/pg-core").PgTableWithCo
|
|
|
151
220
|
driverParam: string;
|
|
152
221
|
notNull: true;
|
|
153
222
|
hasDefault: false;
|
|
223
|
+
isPrimaryKey: false;
|
|
224
|
+
isAutoincrement: false;
|
|
225
|
+
hasRuntimeDefault: false;
|
|
154
226
|
enumValues: undefined;
|
|
155
227
|
baseColumn: never;
|
|
228
|
+
identity: undefined;
|
|
229
|
+
generated: undefined;
|
|
156
230
|
}, {}, {}>;
|
|
157
231
|
};
|
|
158
232
|
dialect: "pg";
|
|
159
233
|
}>;
|
|
160
|
-
|
|
161
|
-
|
|
234
|
+
type AuthReset = typeof authResetTable.$inferSelect;
|
|
235
|
+
declare const authMFATable: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
162
236
|
name: "mfas";
|
|
163
237
|
schema: "auth";
|
|
164
238
|
columns: {
|
|
165
|
-
id:
|
|
239
|
+
id: drizzle_orm_pg_core.PgColumn<{
|
|
166
240
|
name: "id";
|
|
167
241
|
tableName: "mfas";
|
|
168
242
|
dataType: "string";
|
|
@@ -171,10 +245,15 @@ export declare const authMFATable: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
171
245
|
driverParam: string;
|
|
172
246
|
notNull: true;
|
|
173
247
|
hasDefault: false;
|
|
248
|
+
isPrimaryKey: true;
|
|
249
|
+
isAutoincrement: false;
|
|
250
|
+
hasRuntimeDefault: false;
|
|
174
251
|
enumValues: [string, ...string[]];
|
|
175
252
|
baseColumn: never;
|
|
253
|
+
identity: undefined;
|
|
254
|
+
generated: undefined;
|
|
176
255
|
}, {}, {}>;
|
|
177
|
-
name:
|
|
256
|
+
name: drizzle_orm_pg_core.PgColumn<{
|
|
178
257
|
name: "name";
|
|
179
258
|
tableName: "mfas";
|
|
180
259
|
dataType: "string";
|
|
@@ -183,10 +262,15 @@ export declare const authMFATable: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
183
262
|
driverParam: string;
|
|
184
263
|
notNull: true;
|
|
185
264
|
hasDefault: false;
|
|
265
|
+
isPrimaryKey: false;
|
|
266
|
+
isAutoincrement: false;
|
|
267
|
+
hasRuntimeDefault: false;
|
|
186
268
|
enumValues: [string, ...string[]];
|
|
187
269
|
baseColumn: never;
|
|
270
|
+
identity: undefined;
|
|
271
|
+
generated: undefined;
|
|
188
272
|
}, {}, {}>;
|
|
189
|
-
userId:
|
|
273
|
+
userId: drizzle_orm_pg_core.PgColumn<{
|
|
190
274
|
name: "userId";
|
|
191
275
|
tableName: "mfas";
|
|
192
276
|
dataType: "string";
|
|
@@ -195,10 +279,15 @@ export declare const authMFATable: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
195
279
|
driverParam: string;
|
|
196
280
|
notNull: true;
|
|
197
281
|
hasDefault: false;
|
|
282
|
+
isPrimaryKey: false;
|
|
283
|
+
isAutoincrement: false;
|
|
284
|
+
hasRuntimeDefault: false;
|
|
198
285
|
enumValues: [string, ...string[]];
|
|
199
286
|
baseColumn: never;
|
|
287
|
+
identity: undefined;
|
|
288
|
+
generated: undefined;
|
|
200
289
|
}, {}, {}>;
|
|
201
|
-
type:
|
|
290
|
+
type: drizzle_orm_pg_core.PgColumn<{
|
|
202
291
|
name: "type";
|
|
203
292
|
tableName: "mfas";
|
|
204
293
|
dataType: "string";
|
|
@@ -207,10 +296,15 @@ export declare const authMFATable: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
207
296
|
driverParam: string;
|
|
208
297
|
notNull: true;
|
|
209
298
|
hasDefault: true;
|
|
299
|
+
isPrimaryKey: false;
|
|
300
|
+
isAutoincrement: false;
|
|
301
|
+
hasRuntimeDefault: false;
|
|
210
302
|
enumValues: ["TOTP", "HARDWARE"];
|
|
211
303
|
baseColumn: never;
|
|
304
|
+
identity: undefined;
|
|
305
|
+
generated: undefined;
|
|
212
306
|
}, {}, {}>;
|
|
213
|
-
secret:
|
|
307
|
+
secret: drizzle_orm_pg_core.PgColumn<{
|
|
214
308
|
name: "secret";
|
|
215
309
|
tableName: "mfas";
|
|
216
310
|
dataType: "string";
|
|
@@ -219,10 +313,15 @@ export declare const authMFATable: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
219
313
|
driverParam: string;
|
|
220
314
|
notNull: true;
|
|
221
315
|
hasDefault: false;
|
|
316
|
+
isPrimaryKey: false;
|
|
317
|
+
isAutoincrement: false;
|
|
318
|
+
hasRuntimeDefault: false;
|
|
222
319
|
enumValues: [string, ...string[]];
|
|
223
320
|
baseColumn: never;
|
|
321
|
+
identity: undefined;
|
|
322
|
+
generated: undefined;
|
|
224
323
|
}, {}, {}>;
|
|
225
|
-
verifiedAt:
|
|
324
|
+
verifiedAt: drizzle_orm_pg_core.PgColumn<{
|
|
226
325
|
name: "verifiedAt";
|
|
227
326
|
tableName: "mfas";
|
|
228
327
|
dataType: "date";
|
|
@@ -231,18 +330,23 @@ export declare const authMFATable: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
231
330
|
driverParam: string;
|
|
232
331
|
notNull: false;
|
|
233
332
|
hasDefault: false;
|
|
333
|
+
isPrimaryKey: false;
|
|
334
|
+
isAutoincrement: false;
|
|
335
|
+
hasRuntimeDefault: false;
|
|
234
336
|
enumValues: undefined;
|
|
235
337
|
baseColumn: never;
|
|
338
|
+
identity: undefined;
|
|
339
|
+
generated: undefined;
|
|
236
340
|
}, {}, {}>;
|
|
237
341
|
};
|
|
238
342
|
dialect: "pg";
|
|
239
343
|
}>;
|
|
240
|
-
|
|
241
|
-
|
|
344
|
+
type AuthMFA = typeof authMFATable.$inferSelect;
|
|
345
|
+
declare const authClientTable: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
242
346
|
name: "client_credentials";
|
|
243
347
|
schema: "auth";
|
|
244
348
|
columns: {
|
|
245
|
-
id:
|
|
349
|
+
id: drizzle_orm_pg_core.PgColumn<{
|
|
246
350
|
name: "id";
|
|
247
351
|
tableName: "client_credentials";
|
|
248
352
|
dataType: "string";
|
|
@@ -251,10 +355,15 @@ export declare const authClientTable: import("drizzle-orm/pg-core").PgTableWithC
|
|
|
251
355
|
driverParam: string;
|
|
252
356
|
notNull: true;
|
|
253
357
|
hasDefault: false;
|
|
358
|
+
isPrimaryKey: true;
|
|
359
|
+
isAutoincrement: false;
|
|
360
|
+
hasRuntimeDefault: false;
|
|
254
361
|
enumValues: [string, ...string[]];
|
|
255
362
|
baseColumn: never;
|
|
363
|
+
identity: undefined;
|
|
364
|
+
generated: undefined;
|
|
256
365
|
}, {}, {}>;
|
|
257
|
-
alias:
|
|
366
|
+
alias: drizzle_orm_pg_core.PgColumn<{
|
|
258
367
|
name: "alias";
|
|
259
368
|
tableName: "client_credentials";
|
|
260
369
|
dataType: "string";
|
|
@@ -263,10 +372,15 @@ export declare const authClientTable: import("drizzle-orm/pg-core").PgTableWithC
|
|
|
263
372
|
driverParam: string;
|
|
264
373
|
notNull: true;
|
|
265
374
|
hasDefault: false;
|
|
375
|
+
isPrimaryKey: false;
|
|
376
|
+
isAutoincrement: false;
|
|
377
|
+
hasRuntimeDefault: false;
|
|
266
378
|
enumValues: [string, ...string[]];
|
|
267
379
|
baseColumn: never;
|
|
380
|
+
identity: undefined;
|
|
381
|
+
generated: undefined;
|
|
268
382
|
}, {}, {}>;
|
|
269
|
-
secret:
|
|
383
|
+
secret: drizzle_orm_pg_core.PgColumn<{
|
|
270
384
|
name: "secret";
|
|
271
385
|
tableName: "client_credentials";
|
|
272
386
|
dataType: "string";
|
|
@@ -275,10 +389,17 @@ export declare const authClientTable: import("drizzle-orm/pg-core").PgTableWithC
|
|
|
275
389
|
driverParam: string;
|
|
276
390
|
notNull: true;
|
|
277
391
|
hasDefault: false;
|
|
392
|
+
isPrimaryKey: false;
|
|
393
|
+
isAutoincrement: false;
|
|
394
|
+
hasRuntimeDefault: false;
|
|
278
395
|
enumValues: [string, ...string[]];
|
|
279
396
|
baseColumn: never;
|
|
397
|
+
identity: undefined;
|
|
398
|
+
generated: undefined;
|
|
280
399
|
}, {}, {}>;
|
|
281
400
|
};
|
|
282
401
|
dialect: "pg";
|
|
283
402
|
}>;
|
|
284
|
-
|
|
403
|
+
type AuthClient = typeof authClientTable.$inferSelect;
|
|
404
|
+
|
|
405
|
+
export { type AuthClient, type AuthMFA, type AuthReset, type AuthSession, type AuthUser, type Scope, authClientTable, authMFATable, authResetTable, authSchema, authSessionTable, authUserTable, mfaType, scope };
|
package/dist/database/schema.js
CHANGED
|
@@ -1,42 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const DEFAULT_ROLE = 10;
|
|
4
|
-
export const mfaType = pgEnum('mfaType', ['TOTP', 'HARDWARE']);
|
|
5
|
-
export const scope = pgEnum('scope', ['ANON', 'MFA', 'AUTHED']);
|
|
6
|
-
export const authSchema = pgSchema('auth');
|
|
7
|
-
export const authUserTable = authSchema.table('user_credentials', {
|
|
8
|
-
id: text('id').primaryKey(),
|
|
9
|
-
email: text('email').notNull().unique(),
|
|
10
|
-
password: text('password'),
|
|
11
|
-
role: integer('role').notNull().default(DEFAULT_ROLE),
|
|
12
|
-
});
|
|
13
|
-
export const authSessionTable = authSchema.table('sessions', {
|
|
14
|
-
id: text('id').primaryKey(),
|
|
15
|
-
userId: text('userId')
|
|
16
|
-
.notNull()
|
|
17
|
-
.references(() => authUserTable.id),
|
|
18
|
-
scope: scope('scope').notNull().default('ANON'),
|
|
19
|
-
expiresAt: timestamp('expiresAt').notNull(),
|
|
20
|
-
});
|
|
21
|
-
export const authResetTable = authSchema.table('resets', {
|
|
22
|
-
id: text('id').primaryKey(),
|
|
23
|
-
userId: text('userId')
|
|
24
|
-
.notNull()
|
|
25
|
-
.references(() => authUserTable.id),
|
|
26
|
-
expiresAt: timestamp('expiresAt').notNull(),
|
|
27
|
-
});
|
|
28
|
-
export const authMFATable = authSchema.table('mfas', {
|
|
29
|
-
id: text('id').primaryKey(),
|
|
30
|
-
name: text('name').notNull(),
|
|
31
|
-
userId: text('userId')
|
|
32
|
-
.notNull()
|
|
33
|
-
.references(() => authUserTable.id),
|
|
34
|
-
type: mfaType('type').notNull().default('TOTP'),
|
|
35
|
-
secret: text('secret').notNull(),
|
|
36
|
-
verifiedAt: timestamp('verifiedAt'),
|
|
37
|
-
});
|
|
38
|
-
export const authClientTable = authSchema.table('client_credentials', {
|
|
39
|
-
id: text('id').primaryKey(),
|
|
40
|
-
alias: text('alias').notNull().unique(),
|
|
41
|
-
secret: text('secret').notNull().unique(),
|
|
42
|
-
});
|
|
1
|
+
import {pgEnum,pgSchema,text,integer,timestamp,uniqueIndex}from'drizzle-orm/pg-core';var u=10,p=pgEnum("mfaType",["TOTP","HARDWARE"]),c=pgEnum("scope",["ANON","MFA","AUTHED"]),t=pgSchema("auth"),r=t.table("user_credentials",{id:text("id").primaryKey(),email:text("email").notNull(),password:text("password"),role:integer("role").notNull().default(u),deletedAt:timestamp("deletedAt")},s=>({unique:uniqueIndex().on(s.email,s.role)})),y=t.table("sessions",{id:text("id").primaryKey(),userId:text("userId").notNull().references(()=>r.id,{onDelete:"cascade"}),scope:c("scope").notNull().default("ANON"),expiresAt:timestamp("expiresAt").notNull()}),f=t.table("resets",{id:text("id").primaryKey(),userId:text("userId").notNull().references(()=>r.id,{onDelete:"cascade"}),expiresAt:timestamp("expiresAt").notNull()}),A=t.table("mfas",{id:text("id").primaryKey(),name:text("name").notNull(),userId:text("userId").notNull().references(()=>r.id,{onDelete:"cascade"}),type:p("type").notNull().default("TOTP"),secret:text("secret").notNull(),verifiedAt:timestamp("verifiedAt")}),m=t.table("client_credentials",{id:text("id").primaryKey(),alias:text("alias").notNull().unique(),secret:text("secret").notNull().unique()});export{m as authClientTable,A as authMFATable,f as authResetTable,t as authSchema,y as authSessionTable,r as authUserTable,p as mfaType,c as scope};//# sourceMappingURL=schema.js.map
|
|
2
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/database/schema.ts"],"names":["DEFAULT_ROLE","mfaType","pgEnum","scope","authSchema","pgSchema","authUserTable","text","integer","timestamp","table","uniqueIndex","authSessionTable","authResetTable","authMFATable","authClientTable"],"mappings":"yFAIMA,CAAe,CAAA,EAAA,CAERC,CAAUC,CAAAA,MAAAA,CAAO,SAAW,CAAA,CAAC,MAAQ,CAAA,UAAU,CAAC,CAAA,CAChDC,CAAQD,CAAAA,MAAAA,CAAO,OAAS,CAAA,CAAC,OAAQ,KAAO,CAAA,QAAQ,CAAC,CAAA,CAIjDE,CAAaC,CAAAA,QAAAA,CAAS,MAAM,CAAA,CAE5BC,CAAgBF,CAAAA,CAAAA,CAAW,KACpC,CAAA,kBAAA,CACA,CACI,EAAA,CAAIG,IAAK,CAAA,IAAI,CAAE,CAAA,UAAA,EACf,CAAA,KAAA,CAAOA,IAAK,CAAA,OAAO,CAAE,CAAA,OAAA,EACrB,CAAA,QAAA,CAAUA,IAAK,CAAA,UAAU,CACzB,CAAA,IAAA,CAAMC,QAAQ,MAAM,CAAA,CAAE,OAAQ,EAAA,CAAE,OAAQR,CAAAA,CAAY,CACpD,CAAA,SAAA,CAAWS,SAAU,CAAA,WAAW,CACpC,CAAA,CACCC,CAAW,GAAA,CACR,MAAQC,CAAAA,WAAAA,EAAc,CAAA,EAAA,CAAGD,CAAM,CAAA,KAAA,CAAOA,CAAM,CAAA,IAAI,CACpD,CAAA,CACJ,CAIaE,CAAAA,CAAAA,CAAmBR,CAAW,CAAA,KAAA,CAAM,UAAY,CAAA,CACzD,GAAIG,IAAK,CAAA,IAAI,CAAE,CAAA,UAAA,EACf,CAAA,MAAA,CAAQA,IAAK,CAAA,QAAQ,CAChB,CAAA,OAAA,EACA,CAAA,UAAA,CAAW,IAAMD,CAAAA,CAAc,EAAI,CAAA,CAAE,QAAU,CAAA,SAAU,CAAC,CAAA,CAC/D,KAAOH,CAAAA,CAAAA,CAAM,OAAO,CAAA,CAAE,OAAQ,EAAA,CAAE,OAAQ,CAAA,MAAM,CAC9C,CAAA,SAAA,CAAWM,UAAU,WAAW,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":"schema.js","sourcesContent":["/* istanbul ignore file */\n\nimport { integer, pgEnum, pgSchema, text, timestamp, uniqueIndex } from 'drizzle-orm/pg-core';\n\nconst DEFAULT_ROLE = 10;\n\nexport const mfaType = pgEnum('mfaType', ['TOTP', 'HARDWARE']);\nexport const scope = pgEnum('scope', ['ANON', 'MFA', 'AUTHED']);\n\nexport type Scope = (typeof scope.enumValues)[number];\n\nexport const authSchema = pgSchema('auth');\n\nexport const authUserTable = authSchema.table(\n 'user_credentials',\n {\n id: text('id').primaryKey(),\n email: text('email').notNull(),\n password: text('password'),\n role: integer('role').notNull().default(DEFAULT_ROLE),\n deletedAt: timestamp('deletedAt'),\n },\n (table) => ({\n unique: uniqueIndex().on(table.email, table.role),\n })\n);\n\nexport type AuthUser = typeof authUserTable.$inferSelect;\n\nexport const authSessionTable = authSchema.table('sessions', {\n id: text('id').primaryKey(),\n userId: text('userId')\n .notNull()\n .references(() => authUserTable.id, { onDelete: 'cascade' }),\n scope: scope('scope').notNull().default('ANON'),\n expiresAt: timestamp('expiresAt').notNull(),\n});\n\nexport type AuthSession = typeof authSessionTable.$inferSelect;\n\nexport const authResetTable = authSchema.table('resets', {\n id: text('id').primaryKey(),\n userId: text('userId')\n .notNull()\n .references(() => authUserTable.id, { onDelete: 'cascade' }),\n expiresAt: timestamp('expiresAt').notNull(),\n});\n\nexport type AuthReset = typeof authResetTable.$inferSelect;\n\nexport const authMFATable = authSchema.table('mfas', {\n id: text('id').primaryKey(),\n name: text('name').notNull(),\n userId: text('userId')\n .notNull()\n .references(() => authUserTable.id, { onDelete: 'cascade' }),\n type: mfaType('type').notNull().default('TOTP'),\n secret: text('secret').notNull(),\n verifiedAt: timestamp('verifiedAt'),\n});\n\nexport type AuthMFA = typeof authMFATable.$inferSelect;\n\nexport const authClientTable = authSchema.table('client_credentials', {\n id: text('id').primaryKey(),\n alias: text('alias').notNull().unique(),\n secret: text('secret').notNull().unique(),\n});\n\nexport type AuthClient = typeof authClientTable.$inferSelect;\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var server=require('next/server'),l=require('joi');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var l__default=/*#__PURE__*/_interopDefault(l);var a=class extends Error{messages;constructor(e){super(JSON.stringify(e)),this.messages=e,this.name="ValidationError";}},i=a;var d={"alternatives.all":"","alternatives.any":"","alternatives.match":"","alternatives.one":"","alternatives.types":"","any.custom":"","any.default":"","any.failover":"","any.invalid":"","any.only":"","any.ref":"","any.required":"{{#label}} is required","any.unknown":"","array.base":"","array.excludes":"","array.includesRequiredBoth":"","array.includesRequiredKnowns":"","array.includesRequiredUnknowns":"","array.includes":"","array.length":"","array.max":"","array.min":"","array.orderedLength":"","array.sort":"","array.sort.mismatching":"","array.sort.unsupported":"","array.sparse":"","array.unique":"","array.hasKnown":"","array.hasUnknown":"","binary.base":"","binary.length":"","binary.max":"","binary.min":"","boolean.base":"","date.base":"","date.format":"","date.greater":"","date.less":"","date.max":"","date.min":"","date.strict":"","function.arity":"","function.class":"","function.maxArity":"","function.minArity":"","number.base":"{{#label}} should be a number","number.greater":"","number.infinity":"","number.integer":"","number.less":"","number.max":"","number.min":"{{#label}} should be greater than or equal to {{#limit}}","number.multiple":"","number.negative":"","number.port":"","number.positive":"","number.precision":"","number.unsafe":"","object.unknown":"","object.and":"","object.assert":"","object.base":"","object.length":"","object.max":"","object.min":"","object.missing":"","object.nand":"","object.pattern.match":"","object.refType":"","object.regex":"","object.rename.multiple":"","object.rename.override":"","object.schema":"","object.instance":"","object.with":"","object.without":"","object.xor":"","object.oxor":"","string.alphanum":"","string.base64":"","string.base":"","string.creditCard":"","string.dataUri":"","string.domain":"","string.email":"","string.empty":"{{#label}} is required","string.guid":"","string.hexAlign":"","string.hex":"","string.hostname":"","string.ipVersion":"","string.ip":"","string.isoDate":"","string.isoDuration":"","string.length":"","string.lowercase":"","string.max":"","string.min":"","string.normalize":"","string.pattern.base":"{{#label}} is not in the correct format","string.pattern.name":"","string.pattern.invert.base":"","string.pattern.invert.name":"","string.token":"","string.trim":"","string.uppercase":"","string.uri":"","string.uriCustomScheme":"","string.uriRelativeOnly":"","symbol.base":"","symbol.map":""},s=d;function S(){return l__default.default}function v(){return s}function b(){return Object.entries(s).reduce((r,[e,n])=>n?{...r,[e]:n}:r,{})}function g(r){let e=r.details.reduce((n,t)=>({...n,[t.path.join(".")]:t.message.replace(/"/gu,"")}),{});return new i(e)}async function m(r,e,n){try{return [await e.validateAsync(r,{abortEarly:!1,messages:n||b(),stripUnknown:!0}),null]}catch(t){return t instanceof l__default.default.ValidationError?[null,g(t)]:t instanceof Error?[null,t]:[null,new Error("Unknown validation error occured")]}}function w(r){return l__default.default.object(r)}function A(r,e){return r.append(e)}function c(r){return {cause:r.cause,message:r.message,name:r.name,stack:r.stack}}function p(r){return !!Object.prototype.hasOwnProperty.call(r,"fn")}async function f(r){let e={...r.formData};if(r.request){let[t,o]=await m(r.formData,r.request);if(o!==null)return o instanceof i&&r.onValidationError?.(o),[null,c(o)];e=t;}if(!p(r))return await r.onSuccess?.(e),[e,null];let n=null;try{n=await r.fn(e);}catch(t){if(t instanceof i)return r.onValidationError?.(t),[null,c(t)];throw t instanceof Error?t:new Error("The function supplied to submitForm encountered an unknown error")}if(!n)throw new Error("NO_MODEL");return await r.onSuccess?.(n),[n,null]}async function O(r){let[e,n]=await f(r);if(n!==null){if(n.name==="ValidationError")try{let t=JSON.parse(n.message);return [null,server.NextResponse.json(t,{status:422})]}catch{return [null,server.NextResponse.json({message:"An unknown error occured"},{status:500})]}return [null,server.NextResponse.json({message:n.message},{status:500})]}return [e,null]}var y=["image/png","image/jpeg","image/jpg"];async function R(r,e){return r?r instanceof File?(e?.types||y).includes(r.type)?r.size>(e?.maxSize||5242880)?Promise.resolve([null,new Error("IMAGE_TOO_HEAVY")]):Promise.resolve([r,null]):Promise.resolve([null,new Error("IMAGE_TYPE_NOT_VALID")]):Promise.resolve([null,new Error("IMAGE_NOT_VALID")]):Promise.resolve([null,new Error("IMAGE_UNDEFINED")])}exports.ValidationError=i;exports.createSchema=w;exports.extendSchema=A;exports.getDefaultErrorMessages=v;exports.submitAPIRequest=O;exports.submitForm=f;exports.validate=S;exports.validateImage=R;exports.validateSchema=m;//# sourceMappingURL=index.cjs.map
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/forms/ValidationError.ts","../../src/forms/lang.ts","../../src/forms/ValidationService.ts","../../src/forms/FormService.ts","../../src/forms/ImageService.ts"],"names":["ValidationError","messages","ValidationError_default","lang_default","validate","Joi","getDefaultErrorMessages","getErrorMessages","acc","key","value","transformErrors","error","cur","validateSchema","formData","validation","err","createSchema","schema","extendSchema","appends","serializeError","hasFn","args","submitForm","data","validated","validationError","model","submitAPIRequest","response","errors","NextResponse","DEFAULT_TYPES","validateImage","image","config"],"mappings":"oLAAMA,CAAN,CAAA,cAA8B,KAAM,CACzB,QAAA,CAEA,WAAYC,CAAAA,CAAAA,CAAkC,CACjD,KAAM,CAAA,IAAA,CAAK,UAAUA,CAAQ,CAAC,EAE9B,IAAK,CAAA,QAAA,CAAWA,CAChB,CAAA,IAAA,CAAK,KAAO,kBAChB,CACJ,EAEOC,CAAQF,CAAAA,ECXf,IAAMC,CAAmC,CAAA,CACrC,mBAAoB,EACpB,CAAA,kBAAA,CAAoB,GACpB,oBAAsB,CAAA,EAAA,CACtB,mBAAoB,EACpB,CAAA,oBAAA,CAAsB,EACtB,CAAA,YAAA,CAAc,GACd,aAAe,CAAA,EAAA,CACf,eAAgB,EAChB,CAAA,aAAA,CAAe,GACf,UAAY,CAAA,EAAA,CACZ,SAAW,CAAA,EAAA,CACX,eAAgB,wBAChB,CAAA,aAAA,CAAe,GACf,YAAc,CAAA,EAAA,CACd,iBAAkB,EAClB,CAAA,4BAAA,CAA8B,EAC9B,CAAA,8BAAA,CAAgC,GAChC,gCAAkC,CAAA,EAAA,CAClC,iBAAkB,EAClB,CAAA,cAAA,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messages: Record<string, string>;\n\n public constructor(messages: Record<string, string>) {\n super(JSON.stringify(messages));\n\n this.messages = messages;\n this.name = 'ValidationError';\n }\n}\n\nexport default ValidationError;\n","const messages: Record<string, string> = {\n 'alternatives.all': '',\n 'alternatives.any': '',\n 'alternatives.match': '',\n 'alternatives.one': '',\n 'alternatives.types': '',\n 'any.custom': '',\n 'any.default': '',\n 'any.failover': '',\n 'any.invalid': '',\n 'any.only': '',\n 'any.ref': '',\n 'any.required': '{{#label}} is required',\n 'any.unknown': '',\n 'array.base': '',\n 'array.excludes': '',\n 'array.includesRequiredBoth': '',\n 'array.includesRequiredKnowns': '',\n 'array.includesRequiredUnknowns': '',\n 'array.includes': '',\n 'array.length': '',\n 'array.max': '',\n 'array.min': '',\n 'array.orderedLength': '',\n 'array.sort': '',\n 'array.sort.mismatching': '',\n 'array.sort.unsupported': '',\n 'array.sparse': '',\n 'array.unique': '',\n 'array.hasKnown': '',\n 'array.hasUnknown': '',\n 'binary.base': '',\n 'binary.length': '',\n 'binary.max': '',\n 'binary.min': '',\n 'boolean.base': '',\n 'date.base': '',\n 'date.format': '',\n 'date.greater': '',\n 'date.less': '',\n 'date.max': '',\n 'date.min': '',\n 'date.strict': '',\n 'function.arity': '',\n 'function.class': '',\n 'function.maxArity': '',\n 'function.minArity': '',\n 'number.base': '{{#label}} should be a number',\n 'number.greater': '',\n 'number.infinity': '',\n 'number.integer': '',\n 'number.less': '',\n 'number.max': '',\n 'number.min': '{{#label}} should be greater than or equal to {{#limit}}',\n 'number.multiple': '',\n 'number.negative': '',\n 'number.port': '',\n 'number.positive': '',\n 'number.precision': '',\n 'number.unsafe': '',\n 'object.unknown': '',\n 'object.and': '',\n 'object.assert': '',\n 'object.base': '',\n 'object.length': '',\n 'object.max': '',\n 'object.min': '',\n 'object.missing': '',\n 'object.nand': '',\n 'object.pattern.match': '',\n 'object.refType': '',\n 'object.regex': '',\n 'object.rename.multiple': '',\n 'object.rename.override': '',\n 'object.schema': '',\n 'object.instance': '',\n 'object.with': '',\n 'object.without': '',\n 'object.xor': '',\n 'object.oxor': '',\n 'string.alphanum': '',\n 'string.base64': '',\n 'string.base': '',\n 'string.creditCard': '',\n 'string.dataUri': '',\n 'string.domain': '',\n 'string.email': '',\n 'string.empty': '{{#label}} is required',\n 'string.guid': '',\n 'string.hexAlign': '',\n 'string.hex': '',\n 'string.hostname': '',\n 'string.ipVersion': '',\n 'string.ip': '',\n 'string.isoDate': '',\n 'string.isoDuration': '',\n 'string.length': '',\n 'string.lowercase': '',\n 'string.max': '',\n 'string.min': '',\n 'string.normalize': '',\n 'string.pattern.base': '{{#label}} is not in the correct format',\n 'string.pattern.name': '',\n 'string.pattern.invert.base': '',\n 'string.pattern.invert.name': '',\n 'string.token': '',\n 'string.trim': '',\n 'string.uppercase': '',\n 'string.uri': '',\n 'string.uriCustomScheme': '',\n 'string.uriRelativeOnly': '',\n 'symbol.base': '',\n 'symbol.map': '',\n};\n\nexport default messages;\n","import type { Errorable } from '@sqrzro/interfaces';\nimport Joi from 'joi';\n\nimport lang from './lang';\nimport ValidationError from './ValidationError';\n\nexport function validate(): typeof Joi {\n return Joi;\n}\n\nexport type ValidationCustomHelpers<V = any> = Joi.CustomHelpers<V>; // eslint-disable-line @typescript-eslint/no-explicit-any\nexport type ValidationExternalHelpers<V = any> = Joi.ExternalHelpers<V>; // eslint-disable-line @typescript-eslint/no-explicit-any\nexport type ValidationErrorReport = Joi.ErrorReport;\n\nexport function getDefaultErrorMessages(): Record<string, string> {\n return lang;\n}\n\nfunction getErrorMessages(): Record<string, string> {\n return Object.entries(lang).reduce((acc, [key, value]) => {\n if (!value) {\n return acc;\n }\n return {\n ...acc,\n [key]: value,\n };\n }, {});\n}\n\nfunction transformErrors(error: Joi.ValidationError): ValidationError {\n const messages = error.details.reduce(\n (acc, cur) => ({\n ...acc,\n [cur.path.join('.')]: cur.message.replace(/\"/gu, ''),\n }),\n {}\n );\n return new ValidationError(messages);\n}\n\n/**\n * This function takes FormData and a schema. It then attempts to transform the FormData into an\n * object that matches `T`. This is because the FormData object is not typed and we want to be able\n * to validate it properly typed.\n *\n * Once transformed, the object is validated against the schema. This will result in either a\n * properly typed `T` object or an array of validation errors.\n * @param formData\n * @param validation\n * @returns\n */\nexport async function validateSchema<T>(\n formData: Partial<T>,\n validation: Joi.ObjectSchema<T>,\n messages?: Record<string, string>\n): Promise<Errorable<T>> {\n try {\n const validated = await validation.validateAsync(formData, {\n abortEarly: false,\n messages: messages || getErrorMessages(),\n stripUnknown: true,\n });\n\n return [validated, null];\n } catch (err) {\n if (err instanceof Joi.ValidationError) {\n return [null, transformErrors(err)];\n }\n\n if (err instanceof Error) {\n return [null, err];\n }\n\n return [null, new Error('Unknown validation error occured')];\n }\n}\n\nexport function createSchema<T>(schema: Joi.SchemaMap<T, true>): Joi.ObjectSchema<T> {\n return Joi.object<T>(schema);\n}\n\nexport function extendSchema<T, U extends T>(\n schema: Joi.ObjectSchema<T>,\n appends: Joi.PartialSchemaMap<U>\n): Joi.ObjectSchema<U> {\n return schema.append<U>(appends);\n}\n","/* eslint-disable max-statements */\n\nimport type { SerializedError, SerializedErrorable } from '@sqrzro/interfaces';\nimport type Joi from 'joi';\nimport { NextResponse } from 'next/server';\n\nimport ValidationError from './ValidationError';\nimport { validateSchema } from './ValidationService';\n\nfunction serializeError(err: Error): SerializedError {\n return {\n cause: err.cause,\n message: err.message,\n name: err.name,\n stack: err.stack,\n };\n}\n\ninterface SubmitFormArgs<F extends object> {\n formData: F;\n onSuccess?: (model: F) => Promise<void> | void;\n onValidationError?: (error: ValidationError) => void;\n request?: Joi.ObjectSchema<F>;\n}\n\ninterface SubmitFormArgsWithFn<F extends object, M> extends Omit<SubmitFormArgs<F>, 'onSuccess'> {\n fn: (data: F) => Promise<M | null>;\n onSuccess?: (model: M) => Promise<void> | void;\n}\n\nfunction hasFn<F extends object, M>(\n args: SubmitFormArgs<F> | SubmitFormArgsWithFn<F, M>\n): args is SubmitFormArgsWithFn<F, M> {\n return Boolean(Object.prototype.hasOwnProperty.call(args, 'fn'));\n}\n\nexport async function submitForm<F extends object>(\n args: SubmitFormArgs<F>\n): Promise<SerializedErrorable<F>>;\nexport async function submitForm<F extends object, M>(\n args: SubmitFormArgsWithFn<F, M>\n): Promise<SerializedErrorable<M>>;\n\nexport async function submitForm<F extends object, M>(\n args: SubmitFormArgs<F> | SubmitFormArgsWithFn<F, M>\n): Promise<[F, null] | [M, null] | [null, SerializedError]> {\n let data = { ...args.formData };\n\n if (args.request) {\n const [validated, validationError] = await validateSchema<F>(args.formData, args.request);\n\n if (validationError !== null) {\n if (validationError instanceof ValidationError) {\n args.onValidationError?.(validationError);\n }\n\n return [null, serializeError(validationError)];\n }\n\n data = validated;\n }\n\n if (!hasFn(args)) {\n await args.onSuccess?.(data);\n return [data, null];\n }\n\n let model: Awaited<M> | null = null;\n\n try {\n model = await args.fn(data);\n } catch (err: unknown) {\n if (err instanceof ValidationError) {\n args.onValidationError?.(err);\n return [null, serializeError(err)];\n }\n if (err instanceof Error) {\n throw err;\n }\n throw new Error('The function supplied to submitForm encountered an unknown error');\n }\n\n if (!model) {\n throw new Error('NO_MODEL');\n }\n\n await args.onSuccess?.(model);\n return [model, null];\n}\n\nexport async function submitAPIRequest<F extends object, M>(\n args: SubmitFormArgsWithFn<F, M>\n): Promise<[M, null] | [null, NextResponse]> {\n const [response, error] = await submitForm<F, M>(args);\n\n if (error !== null) {\n if (error.name === 'ValidationError') {\n try {\n const errors = JSON.parse(error.message) as Record<string, string>;\n return [null, NextResponse.json(errors, { status: 422 })];\n } catch (err) {\n return [\n null,\n NextResponse.json({ message: 'An unknown error occured' }, { status: 500 }),\n ];\n }\n }\n return [null, NextResponse.json({ message: error.message }, { status: 500 })];\n }\n\n return [response, null];\n}\n","'use server';\n\nimport type { Errorable } from '@sqrzro/interfaces';\n\nconst DEFAULT_TYPES = ['image/png', 'image/jpeg', 'image/jpg'];\n// 5MB\nconst DEFAULT_MAX_SIZE = 5242880;\n\ninterface ImageValidationConfig {\n maxSize?: number;\n types?: string[];\n}\n\nexport async function validateImage(\n image: File | null,\n config?: ImageValidationConfig\n): Promise<Errorable<File>> {\n if (!image) {\n return Promise.resolve([null, new Error('IMAGE_UNDEFINED')]);\n }\n\n if (!(image instanceof File)) {\n return Promise.resolve([null, new Error('IMAGE_NOT_VALID')]);\n }\n\n if (!(config?.types || DEFAULT_TYPES).includes(image.type)) {\n return Promise.resolve([null, new Error('IMAGE_TYPE_NOT_VALID')]);\n }\n\n if (image.size > (config?.maxSize || DEFAULT_MAX_SIZE)) {\n return Promise.resolve([null, new Error('IMAGE_TOO_HEAVY')]);\n }\n\n return Promise.resolve([image, null]);\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { SerializedErrorable, Errorable } from '@sqrzro/interfaces';
|
|
2
|
+
import Joi from 'joi';
|
|
3
|
+
import { NextResponse } from 'next/server';
|
|
4
|
+
|
|
5
|
+
declare class ValidationError extends Error {
|
|
6
|
+
messages: Record<string, string>;
|
|
7
|
+
constructor(messages: Record<string, string>);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface SubmitFormArgs<F extends object> {
|
|
11
|
+
formData: F;
|
|
12
|
+
onSuccess?: (model: F) => Promise<void> | void;
|
|
13
|
+
onValidationError?: (error: ValidationError) => void;
|
|
14
|
+
request?: Joi.ObjectSchema<F>;
|
|
15
|
+
}
|
|
16
|
+
interface SubmitFormArgsWithFn<F extends object, M> extends Omit<SubmitFormArgs<F>, 'onSuccess'> {
|
|
17
|
+
fn: (data: F) => Promise<M | null>;
|
|
18
|
+
onSuccess?: (model: M) => Promise<void> | void;
|
|
19
|
+
}
|
|
20
|
+
declare function submitForm<F extends object>(args: SubmitFormArgs<F>): Promise<SerializedErrorable<F>>;
|
|
21
|
+
declare function submitForm<F extends object, M>(args: SubmitFormArgsWithFn<F, M>): Promise<SerializedErrorable<M>>;
|
|
22
|
+
declare function submitAPIRequest<F extends object, M>(args: SubmitFormArgsWithFn<F, M>): Promise<[M, null] | [null, NextResponse]>;
|
|
23
|
+
|
|
24
|
+
interface ImageValidationConfig {
|
|
25
|
+
maxSize?: number;
|
|
26
|
+
types?: string[];
|
|
27
|
+
}
|
|
28
|
+
declare function validateImage(image: File | null, config?: ImageValidationConfig): Promise<Errorable<File>>;
|
|
29
|
+
|
|
30
|
+
declare function validate(): typeof Joi;
|
|
31
|
+
type ValidationCustomHelpers<V = any> = Joi.CustomHelpers<V>;
|
|
32
|
+
type ValidationExternalHelpers<V = any> = Joi.ExternalHelpers<V>;
|
|
33
|
+
type ValidationErrorReport = Joi.ErrorReport;
|
|
34
|
+
declare function getDefaultErrorMessages(): Record<string, string>;
|
|
35
|
+
/**
|
|
36
|
+
* This function takes FormData and a schema. It then attempts to transform the FormData into an
|
|
37
|
+
* object that matches `T`. This is because the FormData object is not typed and we want to be able
|
|
38
|
+
* to validate it properly typed.
|
|
39
|
+
*
|
|
40
|
+
* Once transformed, the object is validated against the schema. This will result in either a
|
|
41
|
+
* properly typed `T` object or an array of validation errors.
|
|
42
|
+
* @param formData
|
|
43
|
+
* @param validation
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
declare function validateSchema<T>(formData: Partial<T>, validation: Joi.ObjectSchema<T>, messages?: Record<string, string>): Promise<Errorable<T>>;
|
|
47
|
+
declare function createSchema<T>(schema: Joi.SchemaMap<T, true>): Joi.ObjectSchema<T>;
|
|
48
|
+
declare function extendSchema<T, U extends T>(schema: Joi.ObjectSchema<T>, appends: Joi.PartialSchemaMap<U>): Joi.ObjectSchema<U>;
|
|
49
|
+
|
|
50
|
+
export { type ValidationCustomHelpers, ValidationError, type ValidationErrorReport, type ValidationExternalHelpers, createSchema, extendSchema, getDefaultErrorMessages, submitAPIRequest, submitForm, validate, validateImage, validateSchema };
|
package/dist/forms/index.d.ts
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { SerializedErrorable, Errorable } from '@sqrzro/interfaces';
|
|
2
|
+
import Joi from 'joi';
|
|
3
|
+
import { NextResponse } from 'next/server';
|
|
4
|
+
|
|
5
|
+
declare class ValidationError extends Error {
|
|
6
|
+
messages: Record<string, string>;
|
|
7
|
+
constructor(messages: Record<string, string>);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface SubmitFormArgs<F extends object> {
|
|
11
|
+
formData: F;
|
|
12
|
+
onSuccess?: (model: F) => Promise<void> | void;
|
|
13
|
+
onValidationError?: (error: ValidationError) => void;
|
|
14
|
+
request?: Joi.ObjectSchema<F>;
|
|
15
|
+
}
|
|
16
|
+
interface SubmitFormArgsWithFn<F extends object, M> extends Omit<SubmitFormArgs<F>, 'onSuccess'> {
|
|
17
|
+
fn: (data: F) => Promise<M | null>;
|
|
18
|
+
onSuccess?: (model: M) => Promise<void> | void;
|
|
19
|
+
}
|
|
20
|
+
declare function submitForm<F extends object>(args: SubmitFormArgs<F>): Promise<SerializedErrorable<F>>;
|
|
21
|
+
declare function submitForm<F extends object, M>(args: SubmitFormArgsWithFn<F, M>): Promise<SerializedErrorable<M>>;
|
|
22
|
+
declare function submitAPIRequest<F extends object, M>(args: SubmitFormArgsWithFn<F, M>): Promise<[M, null] | [null, NextResponse]>;
|
|
23
|
+
|
|
24
|
+
interface ImageValidationConfig {
|
|
25
|
+
maxSize?: number;
|
|
26
|
+
types?: string[];
|
|
27
|
+
}
|
|
28
|
+
declare function validateImage(image: File | null, config?: ImageValidationConfig): Promise<Errorable<File>>;
|
|
29
|
+
|
|
30
|
+
declare function validate(): typeof Joi;
|
|
31
|
+
type ValidationCustomHelpers<V = any> = Joi.CustomHelpers<V>;
|
|
32
|
+
type ValidationExternalHelpers<V = any> = Joi.ExternalHelpers<V>;
|
|
33
|
+
type ValidationErrorReport = Joi.ErrorReport;
|
|
34
|
+
declare function getDefaultErrorMessages(): Record<string, string>;
|
|
35
|
+
/**
|
|
36
|
+
* This function takes FormData and a schema. It then attempts to transform the FormData into an
|
|
37
|
+
* object that matches `T`. This is because the FormData object is not typed and we want to be able
|
|
38
|
+
* to validate it properly typed.
|
|
39
|
+
*
|
|
40
|
+
* Once transformed, the object is validated against the schema. This will result in either a
|
|
41
|
+
* properly typed `T` object or an array of validation errors.
|
|
42
|
+
* @param formData
|
|
43
|
+
* @param validation
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
declare function validateSchema<T>(formData: Partial<T>, validation: Joi.ObjectSchema<T>, messages?: Record<string, string>): Promise<Errorable<T>>;
|
|
47
|
+
declare function createSchema<T>(schema: Joi.SchemaMap<T, true>): Joi.ObjectSchema<T>;
|
|
48
|
+
declare function extendSchema<T, U extends T>(schema: Joi.ObjectSchema<T>, appends: Joi.PartialSchemaMap<U>): Joi.ObjectSchema<U>;
|
|
49
|
+
|
|
50
|
+
export { type ValidationCustomHelpers, ValidationError, type ValidationErrorReport, type ValidationExternalHelpers, createSchema, extendSchema, getDefaultErrorMessages, submitAPIRequest, submitForm, validate, validateImage, validateSchema };
|