@drax/identity-back 0.51.0 → 1.0.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/dist/controllers/UserController.js +1 -0
- package/dist/routes/RoleRoutes.js +3 -4
- package/dist/routes/TenantRoutes.js +1 -1
- package/dist/routes/UserLoginFailRoutes.js +1 -1
- package/dist/routes/UserRoutes.js +12 -12
- package/dist/routes/UserSessionRoutes.js +1 -1
- package/dist/schemas/RegisterSchema.js +6 -7
- package/dist/schemas/RoleSchema.js +4 -4
- package/dist/schemas/TenantSchema.js +4 -4
- package/dist/schemas/UserApiKeySchema.js +4 -4
- package/dist/schemas/UserLoginFailSchema.js +1 -1
- package/dist/schemas/UserSchema.js +10 -11
- package/dist/schemas/UserSessionSchema.js +1 -1
- package/package.json +8 -8
- package/src/controllers/UserController.ts +1 -0
- package/src/routes/RoleRoutes.ts +3 -4
- package/src/routes/TenantRoutes.ts +1 -1
- package/src/routes/UserLoginFailRoutes.ts +1 -1
- package/src/routes/UserRoutes.ts +12 -12
- package/src/routes/UserSessionRoutes.ts +1 -1
- package/src/schemas/RegisterSchema.ts +6 -7
- package/src/schemas/RoleSchema.ts +4 -4
- package/src/schemas/TenantSchema.ts +4 -4
- package/src/schemas/UserApiKeySchema.ts +4 -4
- package/src/schemas/UserLoginFailSchema.ts +1 -1
- package/src/schemas/UserSchema.ts +10 -11
- package/src/schemas/UserSessionSchema.ts +1 -1
- package/test/schemas/lab-schema.test.ts +1 -1
- package/test/service/role-service.test.ts +1 -2
- package/test/service/user-service.test.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/types/controllers/UserController.d.ts.map +1 -1
- package/types/routes/RoleRoutes.d.ts.map +1 -1
- package/types/schemas/LoginSchema.d.ts +2 -12
- package/types/schemas/LoginSchema.d.ts.map +1 -1
- package/types/schemas/PasswordSchema.d.ts +3 -17
- package/types/schemas/PasswordSchema.d.ts.map +1 -1
- package/types/schemas/RegisterSchema.d.ts +3 -21
- package/types/schemas/RegisterSchema.d.ts.map +1 -1
- package/types/schemas/RoleSchema.d.ts +9 -59
- package/types/schemas/RoleSchema.d.ts.map +1 -1
- package/types/schemas/SwitchTenantSchema.d.ts +2 -10
- package/types/schemas/SwitchTenantSchema.d.ts.map +1 -1
- package/types/schemas/TenantSchema.d.ts +5 -23
- package/types/schemas/TenantSchema.d.ts.map +1 -1
- package/types/schemas/TokenPayloadSchema.d.ts +1 -21
- package/types/schemas/TokenPayloadSchema.d.ts.map +1 -1
- package/types/schemas/UserApiKeySchema.d.ts +6 -29
- package/types/schemas/UserApiKeySchema.d.ts.map +1 -1
- package/types/schemas/UserLoginFailSchema.d.ts +3 -24
- package/types/schemas/UserLoginFailSchema.d.ts.map +1 -1
- package/types/schemas/UserSchema.d.ts +14 -157
- package/types/schemas/UserSchema.d.ts.map +1 -1
- package/types/schemas/UserSessionSchema.d.ts +4 -41
- package/types/schemas/UserSessionSchema.d.ts.map +1 -1
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import RoleController from "../controllers/RoleController.js";
|
|
2
2
|
import { CrudSchemaBuilder } from "@drax/crud-back";
|
|
3
3
|
import { RoleBaseSchema, RoleSchema } from "../schemas/RoleSchema.js";
|
|
4
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
5
4
|
import zod from "zod";
|
|
6
5
|
async function RoleRoutes(fastify, options) {
|
|
7
6
|
const controller = new RoleController();
|
|
8
|
-
const schemas = new CrudSchemaBuilder(RoleSchema, RoleBaseSchema, RoleBaseSchema, 'role', '
|
|
7
|
+
const schemas = new CrudSchemaBuilder(RoleSchema, RoleBaseSchema, RoleBaseSchema, 'role', 'openapi-3.0', ['Identity']);
|
|
9
8
|
fastify.get('/api/roles/search', { schema: schemas.searchSchema }, (req, rep) => controller.search(req, rep));
|
|
10
9
|
fastify.get('/api/roles/:id', { schema: schemas.findByIdSchema }, (req, rep) => controller.findById(req, rep));
|
|
11
10
|
fastify.get('/api/roles/all', { schema: schemas.allSchema }, (req, rep) => controller.all(req, rep));
|
|
@@ -18,7 +17,7 @@ async function RoleRoutes(fastify, options) {
|
|
|
18
17
|
schema: {
|
|
19
18
|
tags: ['Identity'],
|
|
20
19
|
response: {
|
|
21
|
-
200:
|
|
20
|
+
200: zod.toJSONSchema(zod.array(zod.string())),
|
|
22
21
|
401: schemas.jsonErrorBodyResponse,
|
|
23
22
|
403: schemas.jsonErrorBodyResponse,
|
|
24
23
|
}
|
|
@@ -27,7 +26,7 @@ async function RoleRoutes(fastify, options) {
|
|
|
27
26
|
fastify.get('/api/roles/name/:name', {
|
|
28
27
|
schema: {
|
|
29
28
|
tags: ['Identity'],
|
|
30
|
-
params:
|
|
29
|
+
params: zod.toJSONSchema(zod.object({ name: zod.string() })),
|
|
31
30
|
response: {
|
|
32
31
|
200: schemas.jsonEntitySchema,
|
|
33
32
|
401: schemas.jsonErrorBodyResponse,
|
|
@@ -3,7 +3,7 @@ import TenantController from '../controllers/TenantController.js';
|
|
|
3
3
|
import { TenantSchema, TenantBaseSchema } from '../schemas/TenantSchema.js';
|
|
4
4
|
async function TenantRoutes(fastify, options) {
|
|
5
5
|
const controller = new TenantController();
|
|
6
|
-
const schemas = new CrudSchemaBuilder(TenantSchema, TenantBaseSchema, TenantBaseSchema, 'tenant', '
|
|
6
|
+
const schemas = new CrudSchemaBuilder(TenantSchema, TenantBaseSchema, TenantBaseSchema, 'tenant', 'openapi-3.0', ['Identity']);
|
|
7
7
|
//Getters
|
|
8
8
|
fastify.get('/api/tenants/search', { schema: schemas.searchSchema }, (req, rep) => controller.search(req, rep));
|
|
9
9
|
fastify.get('/api/tenants/:id', { schema: schemas.findByIdSchema }, (req, rep) => controller.findById(req, rep));
|
|
@@ -3,7 +3,7 @@ import { CrudSchemaBuilder } from "@drax/crud-back";
|
|
|
3
3
|
import { UserLoginFailSchema, UserLoginFailBaseSchema } from '../schemas/UserLoginFailSchema.js';
|
|
4
4
|
async function UserLoginFailRoutes(fastify, options) {
|
|
5
5
|
const controller = new UserLoginFailController();
|
|
6
|
-
const schemas = new CrudSchemaBuilder(UserLoginFailSchema, UserLoginFailBaseSchema, UserLoginFailBaseSchema, 'UserLoginFail', '
|
|
6
|
+
const schemas = new CrudSchemaBuilder(UserLoginFailSchema, UserLoginFailBaseSchema, UserLoginFailBaseSchema, 'UserLoginFail', 'openapi-3.0', ['Identity']);
|
|
7
7
|
fastify.get('/api/user-login-fails', { schema: schemas.paginateSchema }, (req, rep) => controller.paginate(req, rep));
|
|
8
8
|
fastify.get('/api/user-login-fails/group-by', { schema: schemas.groupBySchema }, (req, rep) => controller.groupBy(req, rep));
|
|
9
9
|
fastify.get('/api/user-login-fails/export', { schema: schemas.exportSchema }, (req, rep) => controller.export(req, rep));
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import UserController from "../controllers/UserController.js";
|
|
2
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
2
|
import { CrudSchemaBuilder } from "@drax/crud-back";
|
|
4
3
|
import { LoginBodyRequestSchema, LoginBodyResponseSchema } from "../schemas/LoginSchema.js";
|
|
5
4
|
import { UserSchema, UserCreateSchema, UserUpdateSchema } from "../schemas/UserSchema.js";
|
|
6
5
|
import { RegisterBodyRequestSchema, RegisterBodyResponseSchema } from "../schemas/RegisterSchema.js";
|
|
7
6
|
import { MyPasswordBodyRequestSchema, PasswordBodyRequestSchema, PasswordBodyResponseSchema } from "../schemas/PasswordSchema.js";
|
|
8
7
|
import { SwitchTenantBodyRequestSchema, SwitchTenantBodyResponseSchema } from "../schemas/SwitchTenantSchema.js";
|
|
8
|
+
import zod from "zod";
|
|
9
9
|
async function UserRoutes(fastify, options) {
|
|
10
10
|
const controller = new UserController();
|
|
11
|
-
const schemas = new CrudSchemaBuilder(UserSchema, UserCreateSchema, UserUpdateSchema, 'tenant', '
|
|
11
|
+
const schemas = new CrudSchemaBuilder(UserSchema, UserCreateSchema, UserUpdateSchema, 'tenant', 'openapi-3.0', ['Identity']);
|
|
12
12
|
fastify.get('/api/users/search', { schema: schemas.searchSchema }, async (req, rep) => await controller.search(req, rep));
|
|
13
13
|
fastify.get('/api/users/group-by', { schema: schemas.groupBySchema }, async (req, rep) => await controller.groupBy(req, rep));
|
|
14
14
|
fastify.get('/api/users/export', { schema: schemas.exportSchema }, (req, rep) => controller.export(req, rep));
|
|
@@ -19,9 +19,9 @@ async function UserRoutes(fastify, options) {
|
|
|
19
19
|
fastify.post('/api/auth/login', {
|
|
20
20
|
schema: {
|
|
21
21
|
tags: ['Auth'],
|
|
22
|
-
body:
|
|
22
|
+
body: zod.toJSONSchema(LoginBodyRequestSchema),
|
|
23
23
|
response: {
|
|
24
|
-
200:
|
|
24
|
+
200: zod.toJSONSchema(LoginBodyResponseSchema),
|
|
25
25
|
400: schemas.jsonErrorBodyResponse,
|
|
26
26
|
},
|
|
27
27
|
},
|
|
@@ -39,9 +39,9 @@ async function UserRoutes(fastify, options) {
|
|
|
39
39
|
fastify.post('/api/auth/switch-tenant', {
|
|
40
40
|
schema: {
|
|
41
41
|
tags: ['Auth'],
|
|
42
|
-
body:
|
|
42
|
+
body: zod.toJSONSchema(SwitchTenantBodyRequestSchema),
|
|
43
43
|
response: {
|
|
44
|
-
200:
|
|
44
|
+
200: zod.toJSONSchema(SwitchTenantBodyResponseSchema),
|
|
45
45
|
400: schemas.jsonErrorBodyResponse,
|
|
46
46
|
},
|
|
47
47
|
},
|
|
@@ -49,9 +49,9 @@ async function UserRoutes(fastify, options) {
|
|
|
49
49
|
fastify.post('/api/users/register', {
|
|
50
50
|
schema: {
|
|
51
51
|
tags: ['Auth'],
|
|
52
|
-
body:
|
|
52
|
+
body: zod.toJSONSchema(RegisterBodyRequestSchema),
|
|
53
53
|
response: {
|
|
54
|
-
200:
|
|
54
|
+
200: zod.toJSONSchema(RegisterBodyResponseSchema),
|
|
55
55
|
400: schemas.jsonErrorBodyResponse,
|
|
56
56
|
500: schemas.jsonErrorBodyResponse,
|
|
57
57
|
},
|
|
@@ -70,8 +70,8 @@ async function UserRoutes(fastify, options) {
|
|
|
70
70
|
fastify.post('/api/users/password/change', {
|
|
71
71
|
schema: {
|
|
72
72
|
tags: ['Auth'],
|
|
73
|
-
body:
|
|
74
|
-
200:
|
|
73
|
+
body: zod.toJSONSchema(MyPasswordBodyRequestSchema),
|
|
74
|
+
200: zod.toJSONSchema(PasswordBodyResponseSchema),
|
|
75
75
|
400: schemas.jsonErrorBodyResponse,
|
|
76
76
|
500: schemas.jsonErrorBodyResponse,
|
|
77
77
|
}
|
|
@@ -79,8 +79,8 @@ async function UserRoutes(fastify, options) {
|
|
|
79
79
|
fastify.post('/api/users/password/change/:id', {
|
|
80
80
|
schema: {
|
|
81
81
|
tags: ['Auth'],
|
|
82
|
-
body:
|
|
83
|
-
200:
|
|
82
|
+
body: zod.toJSONSchema(PasswordBodyRequestSchema),
|
|
83
|
+
200: zod.toJSONSchema(PasswordBodyResponseSchema),
|
|
84
84
|
400: schemas.jsonErrorBodyResponse,
|
|
85
85
|
500: schemas.jsonErrorBodyResponse,
|
|
86
86
|
}
|
|
@@ -3,7 +3,7 @@ import { CrudSchemaBuilder } from "@drax/crud-back";
|
|
|
3
3
|
import { UserSessionSchema, UserSessionBaseSchema } from '../schemas/UserSessionSchema.js';
|
|
4
4
|
async function UserSessionRoutes(fastify, options) {
|
|
5
5
|
const controller = new UserSessionController();
|
|
6
|
-
const schemas = new CrudSchemaBuilder(UserSessionSchema, UserSessionBaseSchema, UserSessionBaseSchema, 'UserSession', '
|
|
6
|
+
const schemas = new CrudSchemaBuilder(UserSessionSchema, UserSessionBaseSchema, UserSessionBaseSchema, 'UserSession', 'openapi-3.0', ['Identity']);
|
|
7
7
|
fastify.get('/api/user-sessions', { schema: schemas.paginateSchema }, (req, rep) => controller.paginate(req, rep));
|
|
8
8
|
fastify.get('/api/user-sessions/group-by', { schema: schemas.groupBySchema }, (req, rep) => controller.groupBy(req, rep));
|
|
9
9
|
fastify.get('/api/user-sessions/export', { schema: schemas.exportSchema }, (req, rep) => controller.export(req, rep));
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import z, { string } from "zod";
|
|
1
|
+
import z, { string, email } from "zod";
|
|
2
2
|
const RegisterBodyRequestSchema = z.object({
|
|
3
|
-
name: string({
|
|
3
|
+
name: string({ error: "validation.required" })
|
|
4
4
|
.min(1, "validation.required"),
|
|
5
|
-
username: string({
|
|
5
|
+
username: string({ error: "validation.required" })
|
|
6
6
|
.min(1, "validation.required"),
|
|
7
|
-
email:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
password: string({ required_error: "validation.required" })
|
|
7
|
+
email: email("validation.email.invalid"),
|
|
8
|
+
phone: string({ error: "validation.required" }).optional(),
|
|
9
|
+
password: string({ error: "validation.required" })
|
|
11
10
|
.min(1, "validation.required")
|
|
12
11
|
.min(8, "validation.password.min8")
|
|
13
12
|
.max(64, "validation.password.max64"),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { object, string, array, boolean, iso } from "zod";
|
|
2
2
|
const RoleBaseSchema = object({
|
|
3
|
-
name: string({
|
|
3
|
+
name: string({ error: "validation.required" })
|
|
4
4
|
.min(1, "validation.required")
|
|
5
5
|
.regex(/^[A-Z]/, "validation.startWithUpperCase"),
|
|
6
6
|
permissions: array(string()).optional(),
|
|
@@ -20,8 +20,8 @@ const RoleSchema = RoleBaseSchema.extend({
|
|
|
20
20
|
id: string().optional(),
|
|
21
21
|
name: string()
|
|
22
22
|
})).optional(),
|
|
23
|
-
createdAt:
|
|
24
|
-
updatedAt:
|
|
23
|
+
createdAt: iso.datetime().optional(),
|
|
24
|
+
updatedAt: iso.datetime().optional()
|
|
25
25
|
});
|
|
26
26
|
export default RoleSchema;
|
|
27
27
|
export { RoleSchema, RoleBaseSchema };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { object, string,
|
|
1
|
+
import { object, string, record, any, iso } from "zod";
|
|
2
2
|
const TenantBaseSchema = object({
|
|
3
|
-
name: string({
|
|
3
|
+
name: string({ error: "validation.required" })
|
|
4
4
|
.min(1, "validation.required")
|
|
5
5
|
//.regex(/^[A-Z]/, "validation.startWithUpperCase"),
|
|
6
6
|
});
|
|
@@ -8,7 +8,7 @@ const TenantSchema = TenantBaseSchema.extend({
|
|
|
8
8
|
_id: string(),
|
|
9
9
|
id: string().optional(),
|
|
10
10
|
custom: record(string(), any()).optional(),
|
|
11
|
-
createdAt:
|
|
12
|
-
updatedAt:
|
|
11
|
+
createdAt: iso.datetime().optional(),
|
|
12
|
+
updatedAt: iso.datetime().optional()
|
|
13
13
|
});
|
|
14
14
|
export { TenantSchema, TenantBaseSchema };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { array, object, string } from "zod";
|
|
1
|
+
import { array, object, string, ipv4, ipv6 } from "zod";
|
|
2
2
|
const UserApiKeyBaseSchema = object({
|
|
3
|
-
name: string({
|
|
3
|
+
name: string({ error: "validation.required" })
|
|
4
4
|
.min(1, "validation.required"),
|
|
5
|
-
ipv4: array(
|
|
6
|
-
ipv6: array(
|
|
5
|
+
ipv4: array(ipv4({ message: 'validation.invalidIpv4' })),
|
|
6
|
+
ipv6: array(ipv6({ message: 'validation.invalidIpv6' })),
|
|
7
7
|
});
|
|
8
8
|
const UserApiKeySchema = UserApiKeyBaseSchema.extend({
|
|
9
9
|
_id: string(),
|
|
@@ -7,7 +7,7 @@ const UserLoginFailBaseSchema = z.object({
|
|
|
7
7
|
const UserLoginFailSchema = UserLoginFailBaseSchema
|
|
8
8
|
.extend({
|
|
9
9
|
_id: z.string(),
|
|
10
|
-
createdAt: z.
|
|
10
|
+
createdAt: z.iso.datetime().nullable().optional()
|
|
11
11
|
});
|
|
12
12
|
export default UserLoginFailSchema;
|
|
13
13
|
export { UserLoginFailSchema, UserLoginFailBaseSchema };
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { email, iso, object, string, boolean, array, record, any } from "zod";
|
|
2
2
|
const UserBaseSchema = object({
|
|
3
|
-
name: string({
|
|
3
|
+
name: string({ error: "validation.required" })
|
|
4
4
|
.min(1, "validation.required"),
|
|
5
|
-
username: string({
|
|
5
|
+
username: string({ error: "validation.required" })
|
|
6
6
|
.min(1, "validation.required"),
|
|
7
|
-
email:
|
|
8
|
-
|
|
9
|
-
phone: string({ required_error: "validation.required" }).optional(),
|
|
7
|
+
email: email("validation.email.invalid"),
|
|
8
|
+
phone: string({ error: "validation.required" }).optional(),
|
|
10
9
|
active: boolean().optional(),
|
|
11
|
-
role: string({
|
|
10
|
+
role: string({ error: "validation.required" })
|
|
12
11
|
.min(1, "validation.required"),
|
|
13
|
-
tenant: string({
|
|
12
|
+
tenant: string({ error: "validation.required" }).nullable().optional()
|
|
14
13
|
});
|
|
15
14
|
const UserCreateSchema = UserBaseSchema.extend({
|
|
16
|
-
password: string({
|
|
15
|
+
password: string({ error: "validation.required" })
|
|
17
16
|
.min(1, "validation.required")
|
|
18
17
|
.min(8, "validation.password.min8")
|
|
19
18
|
.max(64, "validation.password.max64"),
|
|
@@ -37,8 +36,8 @@ const UserSchema = UserBaseSchema
|
|
|
37
36
|
id: string().optional(),
|
|
38
37
|
name: string(),
|
|
39
38
|
custom: record(string(), any()).optional(),
|
|
40
|
-
}).
|
|
41
|
-
createdAt:
|
|
39
|
+
}).nullish(),
|
|
40
|
+
createdAt: iso.datetime().optional(),
|
|
42
41
|
avatar: string().optional()
|
|
43
42
|
});
|
|
44
43
|
export { UserBaseSchema, UserSchema, UserCreateSchema, UserUpdateSchema, };
|
|
@@ -9,7 +9,7 @@ const UserSessionSchema = UserSessionBaseSchema
|
|
|
9
9
|
.extend({
|
|
10
10
|
_id: z.string(),
|
|
11
11
|
user: z.object({ _id: z.string(), username: z.string() }),
|
|
12
|
-
createdAt: z.
|
|
12
|
+
createdAt: z.iso.datetime().nullable().optional()
|
|
13
13
|
});
|
|
14
14
|
export default UserSessionSchema;
|
|
15
15
|
export { UserSessionSchema, UserSessionBaseSchema };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "1.0.0",
|
|
7
7
|
"description": "Identity module for user management, authentication and authorization.",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "types/index.d.ts",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"author": "Cristian Incarnato & Drax Team",
|
|
29
29
|
"license": "ISC",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@drax/common-back": "^0.
|
|
32
|
-
"@drax/crud-back": "^0.
|
|
33
|
-
"@drax/crud-share": "^0.
|
|
34
|
-
"@drax/email-back": "^0.
|
|
35
|
-
"@drax/identity-share": "^0.
|
|
31
|
+
"@drax/common-back": "^1.0.0",
|
|
32
|
+
"@drax/crud-back": "^1.0.0",
|
|
33
|
+
"@drax/crud-share": "^1.0.0",
|
|
34
|
+
"@drax/email-back": "^1.0.0",
|
|
35
|
+
"@drax/identity-share": "^1.0.0",
|
|
36
36
|
"bcryptjs": "^2.4.3",
|
|
37
37
|
"graphql": "^16.8.2",
|
|
38
38
|
"jsonwebtoken": "^9.0.2"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"mongoose": "^8.21.0",
|
|
44
44
|
"mongoose-paginate-v2": "^1.8.3",
|
|
45
45
|
"mongoose-unique-validator": "^5.0.1",
|
|
46
|
-
"zod": "^3.
|
|
46
|
+
"zod": "^4.3.5"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/bcryptjs": "^2.4.6",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"debug": "0"
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "8e60f7548448f339e7e9bb665ceacd3e051ef32e"
|
|
67
67
|
}
|
|
@@ -180,6 +180,7 @@ class UserController extends AbstractFastifyController<IUser, IUserCreate, IUser
|
|
|
180
180
|
item.password = undefined
|
|
181
181
|
delete item.password
|
|
182
182
|
}
|
|
183
|
+
console.log("Paginated users: ", JSON.stringify(paginateResult,null,4))
|
|
183
184
|
return paginateResult
|
|
184
185
|
} catch (e) {
|
|
185
186
|
this.handleError(e, reply)
|
package/src/routes/RoleRoutes.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import RoleController from "../controllers/RoleController.js";
|
|
2
2
|
import {CrudSchemaBuilder} from "@drax/crud-back";
|
|
3
3
|
import {RoleBaseSchema, RoleSchema} from "../schemas/RoleSchema.js";
|
|
4
|
-
import {zodToJsonSchema} from "zod-to-json-schema";
|
|
5
4
|
import zod from "zod";
|
|
6
5
|
|
|
7
6
|
async function RoleRoutes(fastify, options) {
|
|
8
7
|
|
|
9
8
|
const controller: RoleController = new RoleController()
|
|
10
|
-
const schemas = new CrudSchemaBuilder(RoleSchema, RoleBaseSchema, RoleBaseSchema, 'role','
|
|
9
|
+
const schemas = new CrudSchemaBuilder(RoleSchema, RoleBaseSchema, RoleBaseSchema, 'role','openapi-3.0', ['Identity']);
|
|
11
10
|
|
|
12
11
|
fastify.get('/api/roles/search', {schema: schemas.searchSchema}, (req, rep) => controller.search(req, rep))
|
|
13
12
|
|
|
@@ -29,7 +28,7 @@ async function RoleRoutes(fastify, options) {
|
|
|
29
28
|
schema: {
|
|
30
29
|
tags: ['Identity'],
|
|
31
30
|
response: {
|
|
32
|
-
200:
|
|
31
|
+
200: zod.toJSONSchema(zod.array(zod.string())),
|
|
33
32
|
401: schemas.jsonErrorBodyResponse,
|
|
34
33
|
403: schemas.jsonErrorBodyResponse,
|
|
35
34
|
}
|
|
@@ -39,7 +38,7 @@ async function RoleRoutes(fastify, options) {
|
|
|
39
38
|
fastify.get('/api/roles/name/:name', {
|
|
40
39
|
schema: {
|
|
41
40
|
tags: ['Identity'],
|
|
42
|
-
params:
|
|
41
|
+
params: zod.toJSONSchema(zod.object({name: zod.string()})),
|
|
43
42
|
response: {
|
|
44
43
|
200: schemas.jsonEntitySchema,
|
|
45
44
|
401: schemas.jsonErrorBodyResponse,
|
|
@@ -7,7 +7,7 @@ import {TenantSchema, TenantBaseSchema} from '../schemas/TenantSchema.js'
|
|
|
7
7
|
async function TenantRoutes(fastify, options) {
|
|
8
8
|
|
|
9
9
|
const controller: TenantController = new TenantController()
|
|
10
|
-
const schemas = new CrudSchemaBuilder(TenantSchema, TenantBaseSchema,TenantBaseSchema, 'tenant', '
|
|
10
|
+
const schemas = new CrudSchemaBuilder(TenantSchema, TenantBaseSchema,TenantBaseSchema, 'tenant', 'openapi-3.0', ['Identity']);
|
|
11
11
|
|
|
12
12
|
//Getters
|
|
13
13
|
fastify.get('/api/tenants/search', {schema: schemas.searchSchema}, (req, rep) => controller.search(req, rep))
|
|
@@ -6,7 +6,7 @@ import {UserLoginFailSchema, UserLoginFailBaseSchema} from '../schemas/UserLogin
|
|
|
6
6
|
async function UserLoginFailRoutes(fastify, options) {
|
|
7
7
|
|
|
8
8
|
const controller: UserLoginFailController = new UserLoginFailController()
|
|
9
|
-
const schemas = new CrudSchemaBuilder(UserLoginFailSchema, UserLoginFailBaseSchema,UserLoginFailBaseSchema, 'UserLoginFail', '
|
|
9
|
+
const schemas = new CrudSchemaBuilder(UserLoginFailSchema, UserLoginFailBaseSchema,UserLoginFailBaseSchema, 'UserLoginFail', 'openapi-3.0', ['Identity']);
|
|
10
10
|
|
|
11
11
|
fastify.get('/api/user-login-fails', {schema: schemas.paginateSchema}, (req,rep) => controller.paginate(req,rep))
|
|
12
12
|
|
package/src/routes/UserRoutes.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import UserController from "../controllers/UserController.js";
|
|
2
|
-
import {zodToJsonSchema} from "zod-to-json-schema";
|
|
3
2
|
import {CrudSchemaBuilder} from "@drax/crud-back";
|
|
4
3
|
import {LoginBodyRequestSchema, LoginBodyResponseSchema} from "../schemas/LoginSchema.js"
|
|
5
4
|
import {UserSchema, UserCreateSchema, UserUpdateSchema} from "../schemas/UserSchema.js";
|
|
@@ -10,11 +9,12 @@ import {
|
|
|
10
9
|
PasswordBodyResponseSchema
|
|
11
10
|
} from "../schemas/PasswordSchema.js";
|
|
12
11
|
import {SwitchTenantBodyRequestSchema, SwitchTenantBodyResponseSchema} from "../schemas/SwitchTenantSchema.js";
|
|
12
|
+
import zod from "zod"
|
|
13
13
|
|
|
14
14
|
async function UserRoutes(fastify, options) {
|
|
15
15
|
|
|
16
16
|
const controller: UserController = new UserController()
|
|
17
|
-
const schemas = new CrudSchemaBuilder(UserSchema, UserCreateSchema, UserUpdateSchema, 'tenant', '
|
|
17
|
+
const schemas = new CrudSchemaBuilder(UserSchema, UserCreateSchema, UserUpdateSchema, 'tenant', 'openapi-3.0', ['Identity']);
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
fastify.get('/api/users/search', {schema: schemas.searchSchema}, async (req, rep) => await controller.search(req, rep))
|
|
@@ -35,9 +35,9 @@ async function UserRoutes(fastify, options) {
|
|
|
35
35
|
{
|
|
36
36
|
schema: {
|
|
37
37
|
tags: ['Auth'],
|
|
38
|
-
body:
|
|
38
|
+
body: zod.toJSONSchema(LoginBodyRequestSchema),
|
|
39
39
|
response: {
|
|
40
|
-
200:
|
|
40
|
+
200: zod.toJSONSchema(LoginBodyResponseSchema),
|
|
41
41
|
400: schemas.jsonErrorBodyResponse,
|
|
42
42
|
},
|
|
43
43
|
},
|
|
@@ -59,9 +59,9 @@ async function UserRoutes(fastify, options) {
|
|
|
59
59
|
{
|
|
60
60
|
schema: {
|
|
61
61
|
tags: ['Auth'],
|
|
62
|
-
body:
|
|
62
|
+
body: zod.toJSONSchema(SwitchTenantBodyRequestSchema),
|
|
63
63
|
response: {
|
|
64
|
-
200:
|
|
64
|
+
200: zod.toJSONSchema(SwitchTenantBodyResponseSchema),
|
|
65
65
|
400: schemas.jsonErrorBodyResponse,
|
|
66
66
|
},
|
|
67
67
|
},
|
|
@@ -72,9 +72,9 @@ async function UserRoutes(fastify, options) {
|
|
|
72
72
|
fastify.post('/api/users/register', {
|
|
73
73
|
schema: {
|
|
74
74
|
tags: ['Auth'],
|
|
75
|
-
body:
|
|
75
|
+
body: zod.toJSONSchema(RegisterBodyRequestSchema),
|
|
76
76
|
response: {
|
|
77
|
-
200:
|
|
77
|
+
200: zod.toJSONSchema(RegisterBodyResponseSchema),
|
|
78
78
|
400: schemas.jsonErrorBodyResponse,
|
|
79
79
|
500: schemas.jsonErrorBodyResponse,
|
|
80
80
|
},
|
|
@@ -96,8 +96,8 @@ async function UserRoutes(fastify, options) {
|
|
|
96
96
|
fastify.post('/api/users/password/change', {
|
|
97
97
|
schema: {
|
|
98
98
|
tags: ['Auth'],
|
|
99
|
-
body:
|
|
100
|
-
200:
|
|
99
|
+
body: zod.toJSONSchema(MyPasswordBodyRequestSchema),
|
|
100
|
+
200: zod.toJSONSchema(PasswordBodyResponseSchema),
|
|
101
101
|
400: schemas.jsonErrorBodyResponse,
|
|
102
102
|
500: schemas.jsonErrorBodyResponse,
|
|
103
103
|
}
|
|
@@ -106,8 +106,8 @@ async function UserRoutes(fastify, options) {
|
|
|
106
106
|
fastify.post('/api/users/password/change/:id', {
|
|
107
107
|
schema: {
|
|
108
108
|
tags: ['Auth'],
|
|
109
|
-
body:
|
|
110
|
-
200:
|
|
109
|
+
body: zod.toJSONSchema(PasswordBodyRequestSchema),
|
|
110
|
+
200: zod.toJSONSchema(PasswordBodyResponseSchema),
|
|
111
111
|
400: schemas.jsonErrorBodyResponse,
|
|
112
112
|
500: schemas.jsonErrorBodyResponse,
|
|
113
113
|
}
|
|
@@ -6,7 +6,7 @@ import {UserSessionSchema, UserSessionBaseSchema} from '../schemas/UserSessionSc
|
|
|
6
6
|
async function UserSessionRoutes(fastify, options) {
|
|
7
7
|
|
|
8
8
|
const controller: UserSessionController = new UserSessionController()
|
|
9
|
-
const schemas = new CrudSchemaBuilder(UserSessionSchema, UserSessionBaseSchema,UserSessionBaseSchema, 'UserSession', '
|
|
9
|
+
const schemas = new CrudSchemaBuilder(UserSessionSchema, UserSessionBaseSchema,UserSessionBaseSchema, 'UserSession', 'openapi-3.0', ['Identity']);
|
|
10
10
|
|
|
11
11
|
fastify.get('/api/user-sessions', {schema: schemas.paginateSchema}, (req,rep) => controller.paginate(req,rep))
|
|
12
12
|
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import z, {string} from "zod"
|
|
1
|
+
import z, {string, email} from "zod"
|
|
2
2
|
|
|
3
3
|
const RegisterBodyRequestSchema = z.object({
|
|
4
|
-
name: string({
|
|
4
|
+
name: string({ error: "validation.required" })
|
|
5
5
|
.min(1, "validation.required"),
|
|
6
|
-
username: string({
|
|
6
|
+
username: string({ error: "validation.required" })
|
|
7
7
|
.min(1, "validation.required"),
|
|
8
|
-
email:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
password: string({ required_error: "validation.required" })
|
|
8
|
+
email: email("validation.email.invalid"),
|
|
9
|
+
phone: string({ error: "validation.required" }).optional(),
|
|
10
|
+
password: string({ error: "validation.required" })
|
|
12
11
|
.min(1, "validation.required")
|
|
13
12
|
.min(8, "validation.password.min8")
|
|
14
13
|
.max(64, "validation.password.max64"),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { object, string, array, boolean, iso} from "zod"
|
|
2
2
|
|
|
3
3
|
const RoleBaseSchema = object({
|
|
4
|
-
name: string({
|
|
4
|
+
name: string({ error: "validation.required" })
|
|
5
5
|
.min(1, "validation.required")
|
|
6
6
|
.regex(/^[A-Z]/, "validation.startWithUpperCase"),
|
|
7
7
|
permissions: array(string()).optional(),
|
|
@@ -22,8 +22,8 @@ const RoleSchema = RoleBaseSchema.extend({
|
|
|
22
22
|
id: string().optional(),
|
|
23
23
|
name: string()
|
|
24
24
|
})).optional(),
|
|
25
|
-
createdAt:
|
|
26
|
-
updatedAt:
|
|
25
|
+
createdAt: iso.datetime().optional(),
|
|
26
|
+
updatedAt: iso.datetime().optional()
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { object, string,
|
|
1
|
+
import { object, string, record, any, iso } from "zod"
|
|
2
2
|
|
|
3
3
|
const TenantBaseSchema = object({
|
|
4
|
-
name: string({
|
|
4
|
+
name: string({ error: "validation.required" })
|
|
5
5
|
.min(1, "validation.required")
|
|
6
6
|
//.regex(/^[A-Z]/, "validation.startWithUpperCase"),
|
|
7
7
|
})
|
|
@@ -11,8 +11,8 @@ const TenantSchema = TenantBaseSchema.extend({
|
|
|
11
11
|
_id: string(),
|
|
12
12
|
id: string().optional(),
|
|
13
13
|
custom: record(string(), any()).optional(),
|
|
14
|
-
createdAt:
|
|
15
|
-
updatedAt:
|
|
14
|
+
createdAt: iso.datetime().optional(),
|
|
15
|
+
updatedAt: iso.datetime().optional()
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {array, object, string} from "zod"
|
|
1
|
+
import {array, object, string, ipv4, ipv6} from "zod"
|
|
2
2
|
|
|
3
3
|
const UserApiKeyBaseSchema = object({
|
|
4
|
-
name: string({
|
|
4
|
+
name: string({ error: "validation.required" })
|
|
5
5
|
.min(1, "validation.required"),
|
|
6
|
-
ipv4: array(
|
|
7
|
-
ipv6: array(
|
|
6
|
+
ipv4: array(ipv4({ message: 'validation.invalidIpv4'})),
|
|
7
|
+
ipv6: array(ipv6({ message: 'validation.invalidIpv6'})),
|
|
8
8
|
|
|
9
9
|
})
|
|
10
10
|
|
|
@@ -11,7 +11,7 @@ const UserLoginFailBaseSchema = z.object({
|
|
|
11
11
|
const UserLoginFailSchema = UserLoginFailBaseSchema
|
|
12
12
|
.extend({
|
|
13
13
|
_id: z.string(),
|
|
14
|
-
createdAt: z.
|
|
14
|
+
createdAt: z.iso.datetime().nullable().optional()
|
|
15
15
|
})
|
|
16
16
|
|
|
17
17
|
export default UserLoginFailSchema;
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {email, iso, object, string, boolean, array, record, any} from "zod"
|
|
2
2
|
|
|
3
3
|
const UserBaseSchema = object({
|
|
4
|
-
name: string({
|
|
4
|
+
name: string({error: "validation.required"})
|
|
5
5
|
.min(1, "validation.required"),
|
|
6
|
-
username: string({
|
|
6
|
+
username: string({error: "validation.required"})
|
|
7
7
|
.min(1, "validation.required"),
|
|
8
|
-
email:
|
|
9
|
-
|
|
10
|
-
phone: string({required_error: "validation.required"}).optional(),
|
|
8
|
+
email: email("validation.email.invalid"),
|
|
9
|
+
phone: string({error: "validation.required"}).optional(),
|
|
11
10
|
active: boolean().optional(),
|
|
12
|
-
role: string({
|
|
11
|
+
role: string({error: "validation.required"})
|
|
13
12
|
.min(1, "validation.required"),
|
|
14
|
-
tenant: string({
|
|
13
|
+
tenant: string({error: "validation.required"}).nullable().optional()
|
|
15
14
|
|
|
16
15
|
|
|
17
16
|
})
|
|
18
17
|
|
|
19
18
|
const UserCreateSchema = UserBaseSchema.extend({
|
|
20
|
-
password: string({
|
|
19
|
+
password: string({error: "validation.required"})
|
|
21
20
|
.min(1, "validation.required")
|
|
22
21
|
.min(8, "validation.password.min8")
|
|
23
22
|
.max(64, "validation.password.max64"),
|
|
@@ -44,8 +43,8 @@ const UserSchema = UserBaseSchema
|
|
|
44
43
|
id: string().optional(),
|
|
45
44
|
name: string(),
|
|
46
45
|
custom: record(string(), any()).optional(),
|
|
47
|
-
}).
|
|
48
|
-
createdAt:
|
|
46
|
+
}).nullish(),
|
|
47
|
+
createdAt: iso.datetime().optional(),
|
|
49
48
|
avatar: string().optional()
|
|
50
49
|
});
|
|
51
50
|
|
|
@@ -13,7 +13,7 @@ const UserSessionSchema = UserSessionBaseSchema
|
|
|
13
13
|
.extend({
|
|
14
14
|
_id: z.string(),
|
|
15
15
|
user: z.object({_id: z.string(), username: z.string()}),
|
|
16
|
-
createdAt: z.
|
|
16
|
+
createdAt: z.iso.datetime().nullable().optional()
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
export default UserSessionSchema;
|
|
@@ -37,7 +37,7 @@ describe("Test Schema", function () {
|
|
|
37
37
|
}).optional().nullable()
|
|
38
38
|
})
|
|
39
39
|
|
|
40
|
-
let jsonSchema = zodToJsonSchema(zSchema,{target:'
|
|
40
|
+
let jsonSchema = zodToJsonSchema(zSchema,{target:'openapi-3.0'})
|
|
41
41
|
console.log("jsonUserSchema", JSON.stringify(jsonSchema, null,4))
|
|
42
42
|
|
|
43
43
|
let row1 = {
|