@volcanicminds/backend 0.2.27 → 0.2.29
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 +26 -18
- package/TODO.md +0 -1
- package/dist/index.js +46 -20
- 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/config/plugins.js +24 -0
- package/dist/lib/config/plugins.js.map +1 -0
- package/dist/lib/hooks/onRequest.js +13 -9
- package/dist/lib/hooks/onRequest.js.map +1 -1
- package/dist/lib/loader/plugins.js +23 -0
- package/dist/lib/loader/plugins.js.map +1 -0
- 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 +57 -33
- 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/config/plugins.ts +24 -0
- package/lib/hooks/onRequest.ts +13 -19
- package/lib/loader/plugins.ts +22 -0
- 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
package/lib/loader/router.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import yn from '../util/yn'
|
|
1
2
|
import { Route, ConfiguredRoute, RouteConfig } from '../../types/global'
|
|
2
3
|
import { FastifyReply, FastifyRequest } from 'fastify'
|
|
3
4
|
|
|
@@ -8,6 +9,7 @@ const methods = ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'PATCH', 'OPTIONS']
|
|
|
8
9
|
export function load(): ConfiguredRoute[] {
|
|
9
10
|
const validRoutes: ConfiguredRoute[] = []
|
|
10
11
|
const patterns = [`${__dirname}/../api/**/routes.{ts,js}`, `${process.cwd()}/src/api/**/routes.{ts,js}`]
|
|
12
|
+
const authMiddlewares = ['global.isAuthenticated', 'global.isAdmin']
|
|
11
13
|
|
|
12
14
|
patterns.forEach((pattern) => {
|
|
13
15
|
log.t && log.trace('Looking for ' + pattern)
|
|
@@ -20,11 +22,6 @@ export function load(): ConfiguredRoute[] {
|
|
|
20
22
|
const routesjs = require(f)
|
|
21
23
|
const { routes = [], config: defaultConfig = {} } = routesjs || {}
|
|
22
24
|
|
|
23
|
-
// adjust default config
|
|
24
|
-
if (!defaultConfig.enable) defaultConfig.enable = true
|
|
25
|
-
if (defaultConfig.deprecated == null) defaultConfig.deprecated = false
|
|
26
|
-
if (defaultConfig.controller == null) defaultConfig.controller = 'controller'
|
|
27
|
-
|
|
28
25
|
log.t && log.trace(`* Add ${routes.length} routes from ${file}`)
|
|
29
26
|
|
|
30
27
|
routes.forEach((route: Route, index: number) => {
|
|
@@ -35,14 +32,15 @@ export function load(): ConfiguredRoute[] {
|
|
|
35
32
|
handler,
|
|
36
33
|
config = {} as RouteConfig,
|
|
37
34
|
middlewares = [],
|
|
38
|
-
roles:
|
|
35
|
+
roles: rs = []
|
|
39
36
|
} = route
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
const requiredRoles = !rs.length ? [roles.public] : rs
|
|
39
|
+
const reqAuth: boolean =
|
|
40
|
+
middlewares.some((m) => authMiddlewares.includes(m)) ||
|
|
41
|
+
requiredRoles.every((r) => r.code !== roles.public.code)
|
|
42
|
+
|
|
43
|
+
if (!config?.security && reqAuth) {
|
|
46
44
|
config.security = 'bearer'
|
|
47
45
|
}
|
|
48
46
|
|
|
@@ -50,11 +48,11 @@ export function load(): ConfiguredRoute[] {
|
|
|
50
48
|
const {
|
|
51
49
|
title = '',
|
|
52
50
|
description = '',
|
|
53
|
-
enable = defaultConfig.enable
|
|
54
|
-
deprecated = defaultConfig.deprecated
|
|
55
|
-
tags = defaultConfig.tags
|
|
51
|
+
enable = yn(defaultConfig.enable, true),
|
|
52
|
+
deprecated = yn(defaultConfig.deprecated, false),
|
|
53
|
+
tags = defaultConfig.tags,
|
|
56
54
|
version = defaultConfig.version || '',
|
|
57
|
-
security = defaultConfig.security
|
|
55
|
+
security = defaultConfig.security,
|
|
58
56
|
query,
|
|
59
57
|
params,
|
|
60
58
|
body,
|
|
@@ -90,25 +88,26 @@ export function load(): ConfiguredRoute[] {
|
|
|
90
88
|
}
|
|
91
89
|
}
|
|
92
90
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
91
|
+
const toAdd = enable && errors.length === 0
|
|
92
|
+
toAdd
|
|
93
|
+
? log.t &&
|
|
94
|
+
log.trace(
|
|
95
|
+
`* Method [${method}] path ${endpoint} handler ${handler} enabled with ${
|
|
96
|
+
middlewares?.length || 0
|
|
97
|
+
} middlewares`
|
|
98
|
+
)
|
|
99
|
+
: log.w && log.warn(`* Method [${method}] path ${endpoint} handler ${handler} disabled. Skip.`)
|
|
100
|
+
|
|
101
|
+
toAdd &&
|
|
103
102
|
validRoutes.push({
|
|
104
103
|
handler,
|
|
105
104
|
method,
|
|
106
105
|
path: '/' + endpoint,
|
|
107
106
|
middlewares,
|
|
108
|
-
roles:
|
|
107
|
+
roles: requiredRoles,
|
|
109
108
|
enable,
|
|
110
109
|
base,
|
|
111
|
-
file: path.join(base, defaultConfig.controller, handlerParts[0]),
|
|
110
|
+
file: path.join(base, defaultConfig.controller || 'controller', handlerParts[0]),
|
|
112
111
|
func: handlerParts[1],
|
|
113
112
|
// swagger: doc
|
|
114
113
|
doc: {
|
|
@@ -124,7 +123,6 @@ export function load(): ConfiguredRoute[] {
|
|
|
124
123
|
response
|
|
125
124
|
}
|
|
126
125
|
})
|
|
127
|
-
}
|
|
128
126
|
})
|
|
129
127
|
})
|
|
130
128
|
})
|
|
@@ -133,26 +131,65 @@ export function load(): ConfiguredRoute[] {
|
|
|
133
131
|
return validRoutes
|
|
134
132
|
}
|
|
135
133
|
|
|
136
|
-
function
|
|
134
|
+
async function tryToLoadFile(fileName: string) {
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
try {
|
|
137
|
+
const required = fileName ? require(fileName) : null
|
|
138
|
+
resolve(required)
|
|
139
|
+
} catch (err) {
|
|
140
|
+
reject(err)
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function loadMiddleware(base: string, middleware: string = '') {
|
|
137
146
|
const key = 'global.'
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
147
|
+
const isGlobal = middleware.indexOf(key) > -1
|
|
148
|
+
let required: any = null
|
|
149
|
+
|
|
150
|
+
if (isGlobal) {
|
|
151
|
+
const name = middleware.substring(key.length)
|
|
152
|
+
required = await tryToLoadFile(path.resolve(process.cwd() + '/src/middleware/' + name)).catch(async () => {
|
|
153
|
+
return await tryToLoadFile(path.resolve(__dirname + '/../middleware/' + name))
|
|
154
|
+
})
|
|
155
|
+
} else {
|
|
156
|
+
required = await tryToLoadFile(path.resolve(base + '/middleware/' + middleware))
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (!required) {
|
|
160
|
+
log.error(`Middleware ${middleware} not loaded`)
|
|
161
|
+
throw new Error(`Middleware ${middleware} not loaded`)
|
|
162
|
+
}
|
|
163
|
+
return required
|
|
142
164
|
}
|
|
143
165
|
|
|
166
|
+
async function loadMiddlewares(base: string, middlewares: string[] = []) {
|
|
167
|
+
const midds = {}
|
|
168
|
+
await Promise.all(
|
|
169
|
+
middlewares.map(async (m) => {
|
|
170
|
+
const middleware = await loadMiddleware(base, m)
|
|
171
|
+
Object.keys(middleware).map((name) => (midds[name] = [...(midds[name] || []), middleware[name]]))
|
|
172
|
+
})
|
|
173
|
+
)
|
|
174
|
+
// log.debug(base + ' middleware ' + middlewares.length + ' -> ' + Object.keys(midds))
|
|
175
|
+
return midds
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// preParsing, preValidation, preHandler, preSerialization, ..
|
|
179
|
+
|
|
144
180
|
export function apply(server: any, routes: ConfiguredRoute[]): void {
|
|
145
181
|
log.t && log.trace(`Apply ${routes.length} routes to server with pid ${process.pid}`)
|
|
146
182
|
|
|
147
183
|
routes.forEach(async ({ handler, method, path, middlewares, roles, enable, base, file, func, doc }) => {
|
|
148
184
|
if (enable) {
|
|
149
185
|
log.t && log.trace(`* Add path ${method} ${path} on handle ${handler}`)
|
|
186
|
+
const midds = await loadMiddlewares(base, middlewares)
|
|
150
187
|
|
|
151
188
|
server.route({
|
|
152
189
|
method: method,
|
|
153
190
|
path: path,
|
|
154
191
|
schema: doc,
|
|
155
|
-
|
|
192
|
+
...midds,
|
|
156
193
|
config: {
|
|
157
194
|
requiredRoles: roles || []
|
|
158
195
|
},
|
package/lib/loader/schemas.ts
CHANGED
|
@@ -15,9 +15,13 @@ export function apply(server: any): void {
|
|
|
15
15
|
schemaNames.map((name) => {
|
|
16
16
|
const schema = schemaClass[name]
|
|
17
17
|
if (schema != null) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
if (schema?.$id) {
|
|
19
|
+
log.trace(`* Schema [${schema.$id}] loaded from ${schemaFileName}`)
|
|
20
|
+
server.addSchema(schema)
|
|
21
|
+
schemaCount++
|
|
22
|
+
} else {
|
|
23
|
+
log.warn(`* Schema [${schema.$id}] not loaded from ${schemaFileName}`)
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
26
|
})
|
|
23
27
|
})
|
|
@@ -1,11 +1,11 @@
|
|
|
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 && req.user.id && req.hasRole(roles.admin)) {
|
|
7
|
-
return
|
|
6
|
+
return done()
|
|
8
7
|
}
|
|
8
|
+
|
|
9
9
|
throw new Error('User without this privilege')
|
|
10
10
|
} catch (err) {
|
|
11
11
|
log.e && log.error(`Upps, something just happened ${err}`)
|
|
@@ -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
|
-
}
|