@volcanicminds/backend 0.2.28 → 0.2.30
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 +0 -7
- package/dist/index.js +39 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/api/auth/controller/auth.js +136 -17
- package/dist/lib/api/auth/controller/auth.js.map +1 -1
- package/dist/lib/api/auth/routes.js +107 -13
- package/dist/lib/api/auth/routes.js.map +1 -1
- package/dist/lib/api/health/routes.js +2 -2
- package/dist/lib/api/health/routes.js.map +1 -1
- package/dist/lib/api/users/routes.js +12 -14
- package/dist/lib/api/users/routes.js.map +1 -1
- package/dist/lib/hooks/onRequest.js +21 -17
- package/dist/lib/hooks/onRequest.js.map +1 -1
- package/dist/lib/loader/plugins.js +0 -1
- package/dist/lib/loader/plugins.js.map +1 -1
- package/dist/lib/loader/router.js +66 -35
- package/dist/lib/loader/router.js.map +1 -1
- package/dist/lib/loader/schemas.js +8 -3
- package/dist/lib/loader/schemas.js.map +1 -1
- package/dist/lib/middleware/isAdmin.js +5 -4
- package/dist/lib/middleware/isAdmin.js.map +1 -1
- package/dist/lib/middleware/isAuthenticated.js +7 -6
- package/dist/lib/middleware/isAuthenticated.js.map +1 -1
- package/dist/lib/middleware/postAuth.js +19 -0
- package/dist/lib/middleware/postAuth.js.map +1 -0
- package/dist/lib/middleware/preAuth.js +17 -0
- package/dist/lib/middleware/preAuth.js.map +1 -0
- package/dist/lib/util/generate.js +10 -0
- package/dist/lib/util/generate.js.map +1 -0
- package/dist/lib/util/regexp.js +13 -13
- package/dist/lib/util/regexp.js.map +1 -1
- package/index.d.ts +2 -1
- package/index.ts +50 -2
- package/lib/api/auth/controller/auth.ts +118 -23
- package/lib/api/auth/routes.ts +107 -14
- package/lib/api/health/routes.ts +2 -2
- package/lib/api/users/routes.ts +12 -14
- package/lib/hooks/onRequest.ts +21 -27
- package/lib/loader/plugins.ts +0 -1
- package/lib/loader/router.ts +71 -34
- package/lib/loader/schemas.ts +7 -3
- package/lib/middleware/isAdmin.ts +3 -3
- package/lib/middleware/isAuthenticated.ts +5 -5
- package/lib/middleware/postAuth.ts +5 -0
- package/lib/middleware/preAuth.ts +3 -0
- package/lib/util/generate.ts +6 -0
- package/lib/util/regexp.ts +34 -32
- package/package.json +1 -1
- package/types/global.d.ts +15 -1
- package/dist/lib/api/auth/controller/password.js +0 -23
- package/dist/lib/api/auth/controller/password.js.map +0 -1
- package/dist/lib/middleware/example.js +0 -13
- package/dist/lib/middleware/example.js.map +0 -1
- package/lib/api/auth/controller/password.ts +0 -21
- package/lib/middleware/example.ts +0 -12
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { FastifyReply, FastifyRequest } from 'fastify'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
module.exports = (req: FastifyRequest, res: FastifyReply, next: any) => {
|
|
3
|
+
export function preHandler(req: FastifyRequest, res: FastifyReply, done: any) {
|
|
5
4
|
try {
|
|
6
5
|
if (!!req.user?.id) {
|
|
7
|
-
return
|
|
6
|
+
return done()
|
|
8
7
|
}
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
throw new Error('Unauthorized')
|
|
10
10
|
} catch (err) {
|
|
11
11
|
log.e && log.error(`Upps, something just happened ${err}`)
|
|
12
|
-
res.code(
|
|
12
|
+
return res.code(401).send(err) // must be authorized first
|
|
13
13
|
}
|
|
14
14
|
}
|
package/lib/util/regexp.ts
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* min 3 max 33, one special character (. _ -) only in the middle
|
|
3
|
+
* username can have uppercase or lowercase chars
|
|
4
|
+
*/
|
|
5
|
+
export const username = /(?=^.{3,33}$)^[a-z][a-z0-9]*[._-]?[a-z0-9]+$/gi
|
|
6
|
+
export const emailAlt =
|
|
7
|
+
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* email can have multiple words
|
|
11
|
+
* email can use . - or + for smart labeling
|
|
12
|
+
*/
|
|
13
|
+
export const email = /^\w+([\.+-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* password must contain 1 number (0-9)
|
|
17
|
+
* password must contain 1 uppercase chars
|
|
18
|
+
* password must contain 1 lowercase chars
|
|
19
|
+
* password must contain 1 non-alpha number
|
|
20
|
+
* password is 8-64 characters with no space
|
|
21
|
+
*/
|
|
22
|
+
export const password = /^(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^\w\d\s:])([^\s]){8,16}$/
|
|
23
|
+
export const zipCode = /(^\d{5}$)|(^\d{5}-\d{4}$)/
|
|
24
|
+
export const taxCodePersona =
|
|
25
|
+
/^[a-zA-Z]{6}[0-9]{2}[abcdehlmprstABCDEHLMPRST]{1}[0-9]{2}([a-zA-Z]{1}[0-9]{3})[a-zA-Z]{1}$/
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* taxCode can have 2 letter (IT,DE,..) and 11 digits
|
|
29
|
+
*/
|
|
30
|
+
export const taxCodeCompany = /^([A-Z]{2}|)[0-9]{11}$/
|
|
31
|
+
export const iban = /^[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}$/
|
|
32
|
+
export const mobilePhone = /^((00|\+)39)?3[0-9]{8,9}$/
|
|
33
|
+
export const landLinePhone = /^(((00|\+)39))?[\s]?(0{1}[1-9]{1,3})[\s]?(\d{4,6})$/
|
|
34
|
+
export const tollFreePhone = /^((00|\+)39)?(800|803|167)\d{3,6}$/
|
package/package.json
CHANGED
package/types/global.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { FastifyRequest, FastifyReply } from 'fastify'
|
|
|
2
2
|
|
|
3
3
|
export interface AuthenticatedUser {
|
|
4
4
|
id: number
|
|
5
|
-
|
|
5
|
+
username: string
|
|
6
6
|
email: string
|
|
7
7
|
roles: Role[]
|
|
8
8
|
}
|
|
@@ -68,6 +68,20 @@ export interface ConfiguredRoute {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
export interface UserManagement {
|
|
72
|
+
createUser(data: any): any | null
|
|
73
|
+
resetExternalId(data: any): any | null
|
|
74
|
+
updateUserById(id: string, user: any): any | null
|
|
75
|
+
retrieveUserById(id: string): any | null
|
|
76
|
+
retrieveUserByEmail(email: string): any | null
|
|
77
|
+
retrieveUserByExternalId(externalId: string): any | null
|
|
78
|
+
retrieveUserByPassword(email: string, password: string): any | null
|
|
79
|
+
changePassword(email: string, password: string, oldPassword: string): any | null
|
|
80
|
+
enableUserById(id: string): any | null
|
|
81
|
+
disableUserById(id: string): any | null
|
|
82
|
+
isValidUser(data: any): boolean
|
|
83
|
+
}
|
|
84
|
+
|
|
71
85
|
declare module 'fastify' {
|
|
72
86
|
export interface FastifyRequest {
|
|
73
87
|
user?: AuthenticatedUser
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.newAuthCode = exports.valid = exports.compare = exports.hash = void 0;
|
|
4
|
-
const { customAlphabet } = require('nanoid');
|
|
5
|
-
const nanoid = customAlphabet('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789');
|
|
6
|
-
const bcrypt = require('bcrypt');
|
|
7
|
-
function hash(password) {
|
|
8
|
-
return bcrypt.hashSync(password, bcrypt.genSaltSync());
|
|
9
|
-
}
|
|
10
|
-
exports.hash = hash;
|
|
11
|
-
function compare(password, encryptedPassword) {
|
|
12
|
-
return bcrypt.compareSync(password, encryptedPassword);
|
|
13
|
-
}
|
|
14
|
-
exports.compare = compare;
|
|
15
|
-
function valid(password) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
exports.valid = valid;
|
|
19
|
-
function newAuthCode() {
|
|
20
|
-
return nanoid(Number(process.env.AUTH_CODE_SIZE) || 10);
|
|
21
|
-
}
|
|
22
|
-
exports.newAuthCode = newAuthCode;
|
|
23
|
-
//# sourceMappingURL=password.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"password.js","sourceRoot":"","sources":["../../../../../lib/api/auth/controller/password.ts"],"names":[],"mappings":";;;AAAA,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAC5C,MAAM,MAAM,GAAG,cAAc,CAAC,gEAAgE,CAAC,CAAA;AAE/F,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAGhC,SAAgB,IAAI,CAAC,QAAgB;IACnC,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;AACxD,CAAC;AAFD,oBAEC;AAED,SAAgB,OAAO,CAAC,QAAgB,EAAE,iBAAyB;IACjE,OAAO,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAA;AACxD,CAAC;AAFD,0BAEC;AAED,SAAgB,KAAK,CAAC,QAAgB;IACpC,OAAO,IAAI,CAAA;AACb,CAAC;AAFD,sBAEC;AAED,SAAgB,WAAW;IACzB,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAA;AACzD,CAAC;AAFD,kCAEC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const log = global.log;
|
|
4
|
-
module.exports = (req, res, next) => {
|
|
5
|
-
try {
|
|
6
|
-
return next();
|
|
7
|
-
}
|
|
8
|
-
catch (err) {
|
|
9
|
-
log.e && log.error(`Upps, something just happened ${err}`);
|
|
10
|
-
res.code(403).send(err);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=example.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"example.js","sourceRoot":"","sources":["../../../lib/middleware/example.ts"],"names":[],"mappings":";;AAEA,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAA;AACtB,MAAM,CAAC,OAAO,GAAG,CAAC,GAAmB,EAAE,GAAiB,EAAE,IAAS,EAAE,EAAE;IACrE,IAAI;QAEF,OAAO,IAAI,EAAE,CAAA;KACd;IAAC,OAAO,GAAG,EAAE;QACZ,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,iCAAiC,GAAG,EAAE,CAAC,CAAA;QAC1D,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;KACxB;AACH,CAAC,CAAA"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const { customAlphabet } = require('nanoid')
|
|
2
|
-
const nanoid = customAlphabet('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789')
|
|
3
|
-
|
|
4
|
-
const bcrypt = require('bcrypt')
|
|
5
|
-
// const validator = require('../../../loader/validator')
|
|
6
|
-
|
|
7
|
-
export function hash(password: string): string {
|
|
8
|
-
return bcrypt.hashSync(password, bcrypt.genSaltSync())
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function compare(password: string, encryptedPassword: string): boolean {
|
|
12
|
-
return bcrypt.compareSync(password, encryptedPassword)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function valid(password: string): boolean {
|
|
16
|
-
return true //password?.length > 7 && validator.password(password)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function newAuthCode() {
|
|
20
|
-
return nanoid(Number(process.env.AUTH_CODE_SIZE) || 10)
|
|
21
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { FastifyReply, FastifyRequest } from 'fastify'
|
|
2
|
-
|
|
3
|
-
const log = global.log
|
|
4
|
-
module.exports = (req: FastifyRequest, res: FastifyReply, next: any) => {
|
|
5
|
-
try {
|
|
6
|
-
// TODO: do something and then you can throw an exception or call next()..
|
|
7
|
-
return next()
|
|
8
|
-
} catch (err) {
|
|
9
|
-
log.e && log.error(`Upps, something just happened ${err}`)
|
|
10
|
-
res.code(403).send(err)
|
|
11
|
-
}
|
|
12
|
-
}
|