@volcanicminds/backend 0.2.28 → 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.
Files changed (55) hide show
  1. package/README.md +0 -7
  2. package/dist/index.js +39 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/lib/api/auth/controller/auth.js +136 -17
  5. package/dist/lib/api/auth/controller/auth.js.map +1 -1
  6. package/dist/lib/api/auth/routes.js +107 -13
  7. package/dist/lib/api/auth/routes.js.map +1 -1
  8. package/dist/lib/api/health/routes.js +2 -2
  9. package/dist/lib/api/health/routes.js.map +1 -1
  10. package/dist/lib/api/users/routes.js +12 -14
  11. package/dist/lib/api/users/routes.js.map +1 -1
  12. package/dist/lib/hooks/onRequest.js +13 -9
  13. package/dist/lib/hooks/onRequest.js.map +1 -1
  14. package/dist/lib/loader/plugins.js +0 -1
  15. package/dist/lib/loader/plugins.js.map +1 -1
  16. package/dist/lib/loader/router.js +66 -35
  17. package/dist/lib/loader/router.js.map +1 -1
  18. package/dist/lib/loader/schemas.js +8 -3
  19. package/dist/lib/loader/schemas.js.map +1 -1
  20. package/dist/lib/middleware/isAdmin.js +5 -4
  21. package/dist/lib/middleware/isAdmin.js.map +1 -1
  22. package/dist/lib/middleware/isAuthenticated.js +7 -6
  23. package/dist/lib/middleware/isAuthenticated.js.map +1 -1
  24. package/dist/lib/middleware/postAuth.js +19 -0
  25. package/dist/lib/middleware/postAuth.js.map +1 -0
  26. package/dist/lib/middleware/preAuth.js +17 -0
  27. package/dist/lib/middleware/preAuth.js.map +1 -0
  28. package/dist/lib/util/generate.js +10 -0
  29. package/dist/lib/util/generate.js.map +1 -0
  30. package/dist/lib/util/regexp.js +13 -13
  31. package/dist/lib/util/regexp.js.map +1 -1
  32. package/index.d.ts +2 -1
  33. package/index.ts +50 -2
  34. package/lib/api/auth/controller/auth.ts +118 -23
  35. package/lib/api/auth/routes.ts +107 -14
  36. package/lib/api/health/routes.ts +2 -2
  37. package/lib/api/users/routes.ts +12 -14
  38. package/lib/hooks/onRequest.ts +13 -19
  39. package/lib/loader/plugins.ts +0 -1
  40. package/lib/loader/router.ts +71 -34
  41. package/lib/loader/schemas.ts +7 -3
  42. package/lib/middleware/isAdmin.ts +3 -3
  43. package/lib/middleware/isAuthenticated.ts +5 -5
  44. package/lib/middleware/postAuth.ts +5 -0
  45. package/lib/middleware/preAuth.ts +3 -0
  46. package/lib/util/generate.ts +6 -0
  47. package/lib/util/regexp.ts +34 -32
  48. package/package.json +1 -1
  49. package/types/global.d.ts +15 -1
  50. package/dist/lib/api/auth/controller/password.js +0 -23
  51. package/dist/lib/api/auth/controller/password.js.map +0 -1
  52. package/dist/lib/middleware/example.js +0 -13
  53. package/dist/lib/middleware/example.js.map +0 -1
  54. package/lib/api/auth/controller/password.ts +0 -21
  55. package/lib/middleware/example.ts +0 -12
@@ -8,14 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.apply = exports.load = void 0;
16
+ const yn_1 = __importDefault(require("../util/yn"));
13
17
  const glob = require('glob');
14
18
  const path = require('path');
15
19
  const methods = ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'PATCH', 'OPTIONS'];
16
20
  function load() {
17
21
  const validRoutes = [];
18
22
  const patterns = [`${__dirname}/../api/**/routes.{ts,js}`, `${process.cwd()}/src/api/**/routes.{ts,js}`];
23
+ const authMiddlewares = ['global.isAuthenticated', 'global.isAdmin'];
19
24
  patterns.forEach((pattern) => {
20
25
  log.t && log.trace('Looking for ' + pattern);
21
26
  glob.sync(pattern).forEach((f, index, values) => {
@@ -24,22 +29,17 @@ function load() {
24
29
  const file = path.join(dir, path.basename(f));
25
30
  const routesjs = require(f);
26
31
  const { routes = [], config: defaultConfig = {} } = routesjs || {};
27
- if (!defaultConfig.enable)
28
- defaultConfig.enable = true;
29
- if (defaultConfig.deprecated == null)
30
- defaultConfig.deprecated = false;
31
- if (defaultConfig.controller == null)
32
- defaultConfig.controller = 'controller';
33
32
  log.t && log.trace(`* Add ${routes.length} routes from ${file}`);
34
33
  routes.forEach((route, index) => {
35
34
  const errors = [];
36
- const { method: methodCase, path: pathName = '/', handler, config = {}, middlewares = [], roles: requiredRole = [] } = route;
37
- if (!(config === null || config === void 0 ? void 0 : config.security) &&
38
- (requiredRole.some((r) => r.code !== roles.public.code) ||
39
- middlewares.some((m) => m === 'global.isAuthenticated'))) {
35
+ const { method: methodCase, path: pathName = '/', handler, config = {}, middlewares = [], roles: rs = [] } = route;
36
+ const requiredRoles = !rs.length ? [roles.public] : rs;
37
+ const reqAuth = middlewares.some((m) => authMiddlewares.includes(m)) ||
38
+ requiredRoles.every((r) => r.code !== roles.public.code);
39
+ if (!(config === null || config === void 0 ? void 0 : config.security) && reqAuth) {
40
40
  config.security = 'bearer';
41
41
  }
42
- const { title = '', description = '', enable = defaultConfig.enable || true, deprecated = defaultConfig.deprecated || false, tags = defaultConfig.tags || false, version = defaultConfig.version || '', security = defaultConfig.security || undefined, query, params, body, response } = config || {};
42
+ const { title = '', description = '', enable = (0, yn_1.default)(defaultConfig.enable, true), deprecated = (0, yn_1.default)(defaultConfig.deprecated, false), tags = defaultConfig.tags, version = defaultConfig.version || '', security = defaultConfig.security, query, params, body, response } = config || {};
43
43
  const endpoint = `${dir}${pathName.replace(/\/+$/, '')}`;
44
44
  const method = methodCase.toUpperCase();
45
45
  const num = index + 1;
@@ -62,20 +62,21 @@ function load() {
62
62
  log.e && errors.forEach((error) => log.error(error));
63
63
  }
64
64
  }
65
- if (errors.length == 0) {
66
- enable
67
- ? log.t &&
68
- log.trace(`* Method [${method}] path ${endpoint} handler ${handler} enabled with ${(middlewares === null || middlewares === void 0 ? void 0 : middlewares.length) || 0} middlewares`)
69
- : log.w && log.warn(`* Method [${method}] path ${endpoint} handler ${handler} disabled. Skip.`);
65
+ const toAdd = enable && errors.length === 0;
66
+ toAdd
67
+ ? log.t &&
68
+ log.trace(`* Method [${method}] path ${endpoint} handler ${handler} enabled with ${(middlewares === null || middlewares === void 0 ? void 0 : middlewares.length) || 0} middlewares`)
69
+ : log.w && log.warn(`* Method [${method}] path ${endpoint} handler ${handler} disabled. Skip.`);
70
+ toAdd &&
70
71
  validRoutes.push({
71
72
  handler,
72
73
  method,
73
74
  path: '/' + endpoint,
74
75
  middlewares,
75
- roles: requiredRole,
76
+ roles: requiredRoles,
76
77
  enable,
77
78
  base,
78
- file: path.join(base, defaultConfig.controller, handlerParts[0]),
79
+ file: path.join(base, defaultConfig.controller || 'controller', handlerParts[0]),
79
80
  func: handlerParts[1],
80
81
  doc: {
81
82
  summary: title,
@@ -90,7 +91,6 @@ function load() {
90
91
  response
91
92
  }
92
93
  });
93
- }
94
94
  });
95
95
  });
96
96
  });
@@ -98,27 +98,59 @@ function load() {
98
98
  return validRoutes;
99
99
  }
100
100
  exports.load = load;
101
- function normalizeMiddlewarePath(base, middleware = '') {
102
- const key = 'global.';
103
- const idx = middleware.indexOf(key);
104
- return idx == 0
105
- ? path.resolve(__dirname + '/../middleware/' + middleware.substring(key.length))
106
- : path.resolve(base + '/middleware/' + middleware);
101
+ function tryToLoadFile(fileName) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ return new Promise((resolve, reject) => {
104
+ try {
105
+ const required = fileName ? require(fileName) : null;
106
+ resolve(required);
107
+ }
108
+ catch (err) {
109
+ reject(err);
110
+ }
111
+ });
112
+ });
113
+ }
114
+ function loadMiddleware(base, middleware = '') {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ const key = 'global.';
117
+ const isGlobal = middleware.indexOf(key) > -1;
118
+ let required = null;
119
+ if (isGlobal) {
120
+ const name = middleware.substring(key.length);
121
+ required = yield tryToLoadFile(path.resolve(process.cwd() + '/src/middleware/' + name)).catch(() => __awaiter(this, void 0, void 0, function* () {
122
+ return yield tryToLoadFile(path.resolve(__dirname + '/../middleware/' + name));
123
+ }));
124
+ }
125
+ else {
126
+ required = yield tryToLoadFile(path.resolve(base + '/middleware/' + middleware));
127
+ }
128
+ if (!required) {
129
+ log.error(`Middleware ${middleware} not loaded`);
130
+ throw new Error(`Middleware ${middleware} not loaded`);
131
+ }
132
+ return required;
133
+ });
134
+ }
135
+ function loadMiddlewares(base, middlewares = []) {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ const midds = {};
138
+ yield Promise.all(middlewares.map((m) => __awaiter(this, void 0, void 0, function* () {
139
+ const middleware = yield loadMiddleware(base, m);
140
+ Object.keys(middleware).map((name) => (midds[name] = [...(midds[name] || []), middleware[name]]));
141
+ })));
142
+ return midds;
143
+ });
107
144
  }
108
145
  function apply(server, routes) {
109
146
  log.t && log.trace(`Apply ${routes.length} routes to server with pid ${process.pid}`);
110
147
  routes.forEach(({ handler, method, path, middlewares, roles, enable, base, file, func, doc }) => __awaiter(this, void 0, void 0, function* () {
111
148
  if (enable) {
112
149
  log.t && log.trace(`* Add path ${method} ${path} on handle ${handler}`);
113
- server.route({
114
- method: method,
115
- path: path,
116
- schema: doc,
117
- preHandler: (middlewares || []).map((m) => require(normalizeMiddlewarePath(base, m))),
118
- config: {
150
+ const midds = yield loadMiddlewares(base, middlewares);
151
+ server.route(Object.assign(Object.assign({ method: method, path: path, schema: doc }, midds), { config: {
119
152
  requiredRoles: roles || []
120
- },
121
- handler: function (req, reply) {
153
+ }, handler: function (req, reply) {
122
154
  try {
123
155
  return require(file)[func](req, reply);
124
156
  }
@@ -126,8 +158,7 @@ function apply(server, routes) {
126
158
  log.e && log.error(`Cannot find ${file} or method ${func}: ${err}`);
127
159
  return reply.code(500).send(`Invalid handler ${handler}`);
128
160
  }
129
- }
130
- });
161
+ } }));
131
162
  }
132
163
  }));
133
164
  }
@@ -1 +1 @@
1
- {"version":3,"file":"router.js","sourceR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AC,CAAA;wBACnE,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,mBAAmB,OAAO,EAAE,CAAC,CAAA;qBAC1D;gBACH,CAAC,IACD,CAAA;SACH;IACH,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC;AA3BD,sBA2BC"}
@@ -15,9 +15,14 @@ function apply(server) {
15
15
  schemaNames.map((name) => {
16
16
  const schema = schemaClass[name];
17
17
  if (schema != null) {
18
- log.trace(`* Schema [${schema.$id}] loaded from ${schemaFileName}`);
19
- server.addSchema(schema);
20
- schemaCount++;
18
+ if (schema === null || schema === void 0 ? void 0 : schema.$id) {
19
+ log.trace(`* Schema [${schema.$id}] loaded from ${schemaFileName}`);
20
+ server.addSchema(schema);
21
+ schemaCount++;
22
+ }
23
+ else {
24
+ log.warn(`* Schema [${schema.$id}] not loaded from ${schemaFileName}`);
25
+ }
21
26
  }
22
27
  });
23
28
  });
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../lib/loader/schemas.ts"],"names":[],"mappings":";;;AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B,SAAgB,KAAK,CAAC,MAAW;IAC/B,MAAM,QAAQ,GAAG,CAAC,GAAG,SAAS,uBAAuB,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;IAEhG,IAAI,WAAW,GAAG,CAAC,CAAA;IACnB,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,cAAc,GAAG,OAAO,CAAC,CAAA;QAC5C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAS,EAAE,EAAE;YACvC,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,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EAAE,EAAE;YACvC,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;YACvC,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;YAC9B,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;YAE5C,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;gBACvB,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAA;gBAChC,IAAI,MAAM,IAAI,IAAI,EAAE;oBAClB,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,EAAE;wBACf,GAAG,CAAC,KAAK,CAAC,aAAa,MAAM,CAAC,GAAG,iBAAiB,cAAc,EAAE,CAAC,CAAA;wBACnE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;wBACxB,WAAW,EAAE,CAAA;qBACd;yBAAM;wBACL,GAAG,CAAC,IAAI,CAAC,aAAa,MAAM,CAAC,GAAG,qBAAqB,cAAc,EAAE,CAAC,CAAA;qBACvE;iBACF;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,mBAAmB,WAAW,wBAAwB,CAAC,CAAA;AAC5E,CAAC;AA3BD,sBA2BC"}
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const log = global.log;
4
- module.exports = (req, res, next) => {
3
+ exports.preHandler = void 0;
4
+ function preHandler(req, res, done) {
5
5
  try {
6
6
  if (req.user && req.user.id && req.hasRole(roles.admin)) {
7
- return next();
7
+ return done();
8
8
  }
9
9
  throw new Error('User without this privilege');
10
10
  }
@@ -12,5 +12,6 @@ module.exports = (req, res, next) => {
12
12
  log.e && log.error(`Upps, something just happened ${err}`);
13
13
  res.code(403).send(err);
14
14
  }
15
- };
15
+ }
16
+ exports.preHandler = preHandler;
16
17
  //# sourceMappingURL=isAdmin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"isAdmin.js","sourceRoot":"","sources":["../../../lib/middleware/isAdmin.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;QACF,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YACvD,OAAO,IAAI,EAAE,CAAA;SACd;QACD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;KAC/C;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
+ {"version":3,"file":"isAdmin.js","sourceRoot":"","sources":["../../../lib/middleware/isAdmin.ts"],"names":[],"mappings":";;;AAEA,SAAgB,UAAU,CAAC,GAAmB,EAAE,GAAiB,EAAE,IAAS;IAC1E,IAAI;QACF,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YACvD,OAAO,IAAI,EAAE,CAAA;SACd;QAED,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;KAC/C;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;AAXD,gCAWC"}
@@ -1,17 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const log = global.log;
4
- module.exports = (req, res, next) => {
3
+ exports.preHandler = void 0;
4
+ function preHandler(req, res, done) {
5
5
  var _a;
6
6
  try {
7
7
  if (!!((_a = req.user) === null || _a === void 0 ? void 0 : _a.id)) {
8
- return next();
8
+ return done();
9
9
  }
10
- throw new Error('User not authenticated');
10
+ throw new Error('Unauthorized');
11
11
  }
12
12
  catch (err) {
13
13
  log.e && log.error(`Upps, something just happened ${err}`);
14
- res.code(403).send(err);
14
+ return res.code(401).send(err);
15
15
  }
16
- };
16
+ }
17
+ exports.preHandler = preHandler;
17
18
  //# sourceMappingURL=isAuthenticated.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"isAuthenticated.js","sourceRoot":"","sources":["../../../lib/middleware/isAuthenticated.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;QACF,IAAI,CAAC,CAAC,CAAA,MAAA,GAAG,CAAC,IAAI,0CAAE,EAAE,CAAA,EAAE;YAClB,OAAO,IAAI,EAAE,CAAA;SACd;QACD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;KAC1C;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
+ {"version":3,"file":"isAuthenticated.js","sourceRoot":"","sources":["../../../lib/middleware/isAuthenticated.ts"],"names":[],"mappings":";;;AAEA,SAAgB,UAAU,CAAC,GAAmB,EAAE,GAAiB,EAAE,IAAS;;IAC1E,IAAI;QACF,IAAI,CAAC,CAAC,CAAA,MAAA,GAAG,CAAC,IAAI,0CAAE,EAAE,CAAA,EAAE;YAClB,OAAO,IAAI,EAAE,CAAA;SACd;QAED,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAA;KAChC;IAAC,OAAO,GAAG,EAAE;QACZ,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,iCAAiC,GAAG,EAAE,CAAC,CAAA;QAC1D,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;KAC/B;AACH,CAAC;AAXD,gCAWC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.preSerialization = void 0;
13
+ function preSerialization(req, res, payload) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ return payload;
16
+ });
17
+ }
18
+ exports.preSerialization = preSerialization;
19
+ //# sourceMappingURL=postAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postAuth.js","sourceRoot":"","sources":["../../../lib/middleware/postAuth.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,SAAsB,gBAAgB,CAAC,GAAmB,EAAE,GAAiB,EAAE,OAAO;;QACpF,OAAO,OAAO,CAAA;IAChB,CAAC;CAAA;AAFD,4CAEC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.preHandler = void 0;
13
+ function preHandler(req, res) {
14
+ return __awaiter(this, void 0, void 0, function* () { });
15
+ }
16
+ exports.preHandler = preHandler;
17
+ //# sourceMappingURL=preAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preAuth.js","sourceRoot":"","sources":["../../../lib/middleware/preAuth.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,SAAsB,UAAU,CAAC,GAAmB,EAAE,GAAiB;0DAAG,CAAC;CAAA;AAA3E,gCAA2E"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.newAuthCode = void 0;
4
+ const { customAlphabet } = require('nanoid');
5
+ const nanoid = customAlphabet('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789');
6
+ function newAuthCode() {
7
+ return nanoid(Number(process.env.AUTH_CODE_SIZE) || 10);
8
+ }
9
+ exports.newAuthCode = newAuthCode;
10
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../lib/util/generate.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,SAAgB,WAAW;IACzB,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAA;AACzD,CAAC;AAFD,kCAEC"}
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
- module.exports = {
3
- username: /(?=^.{3,33}$)^[a-z][a-z0-9]*[._-]?[a-z0-9]+$/gi,
4
- emailAlt: /^(([^<>()\[\]\\.,;:\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,}))$/,
5
- email: /^\w+([\.+-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/,
6
- password: /^(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^\w\d\s:])([^\s]){8,64}$/gi,
7
- zipCode: /(^\d{5}$)|(^\d{5}-\d{4}$)/,
8
- taxCodePersona: /^[a-zA-Z]{6}[0-9]{2}[abcdehlmprstABCDEHLMPRST]{1}[0-9]{2}([a-zA-Z]{1}[0-9]{3})[a-zA-Z]{1}$/,
9
- taxCodeCompany: /^([A-Z]{2}|)[0-9]{11}$/,
10
- iban: /^[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}$/,
11
- mobilePhone: /^((00|\+)39)?3[0-9]{8,9}$/,
12
- landLinePhone: /^(((00|\+)39))?[\s]?(0{1}[1-9]{1,3})[\s]?(\d{4,6})$/,
13
- tollFreePhone: /^((00|\+)39)?(800|803|167)\d{3,6}$/
14
- };
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tollFreePhone = exports.landLinePhone = exports.mobilePhone = exports.iban = exports.taxCodeCompany = exports.taxCodePersona = exports.zipCode = exports.password = exports.email = exports.emailAlt = exports.username = void 0;
4
+ exports.username = /(?=^.{3,33}$)^[a-z][a-z0-9]*[._-]?[a-z0-9]+$/gi;
5
+ exports.emailAlt = /^(([^<>()\[\]\\.,;:\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,}))$/;
6
+ exports.email = /^\w+([\.+-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
7
+ exports.password = /^(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^\w\d\s:])([^\s]){8,16}$/;
8
+ exports.zipCode = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
9
+ exports.taxCodePersona = /^[a-zA-Z]{6}[0-9]{2}[abcdehlmprstABCDEHLMPRST]{1}[0-9]{2}([a-zA-Z]{1}[0-9]{3})[a-zA-Z]{1}$/;
10
+ exports.taxCodeCompany = /^([A-Z]{2}|)[0-9]{11}$/;
11
+ exports.iban = /^[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}$/;
12
+ exports.mobilePhone = /^((00|\+)39)?3[0-9]{8,9}$/;
13
+ exports.landLinePhone = /^(((00|\+)39))?[\s]?(0{1}[1-9]{1,3})[\s]?(\d{4,6})$/;
14
+ exports.tollFreePhone = /^((00|\+)39)?(800|803|167)\d{3,6}$/;
15
15
  //# sourceMappingURL=regexp.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"regexp.js","sourceRoot":"","sources":["../../../lib/util/regexp.ts"],"names":[],"mappings":";AAAA,MAAM,CAAC,OAAO,GAAG;IAKf,QAAQ,EAAE,gDAAgD;IAC1D,QAAQ,EACN,yJAAyJ;IAK3J,KAAK,EAAE,gDAAgD;IAQvD,QAAQ,EAAE,iEAAiE;IAC3E,OAAO,EAAE,2BAA2B;IACpC,cAAc,EAAE,4FAA4F;IAI5G,cAAc,EAAE,wBAAwB;IACxC,IAAI,EAAE,iEAAiE;IACvE,WAAW,EAAE,2BAA2B;IACxC,aAAa,EAAE,qDAAqD;IACpE,aAAa,EAAE,oCAAoC;CACpD,CAAA"}
1
+ {"version":3,"file":"regexp.js","sourceRoot":"","sources":["../../../lib/util/regexp.ts"],"names":[],"mappings":";;;AAIa,QAAA,QAAQ,GAAG,gDAAgD,CAAA;AAC3D,QAAA,QAAQ,GACnB,yJAAyJ,CAAA;AAM9I,QAAA,KAAK,GAAG,gDAAgD,CAAA;AASxD,QAAA,QAAQ,GAAG,+DAA+D,CAAA;AAC1E,QAAA,OAAO,GAAG,2BAA2B,CAAA;AACrC,QAAA,cAAc,GACzB,4FAA4F,CAAA;AAKjF,QAAA,cAAc,GAAG,wBAAwB,CAAA;AACzC,QAAA,IAAI,GAAG,iEAAiE,CAAA;AACxE,QAAA,WAAW,GAAG,2BAA2B,CAAA;AACzC,QAAA,aAAa,GAAG,qDAAqD,CAAA;AACrE,QAAA,aAAa,GAAG,oCAAoC,CAAA"}
package/index.d.ts CHANGED
@@ -8,5 +8,6 @@ export {
8
8
  Roles,
9
9
  Route,
10
10
  RouteConfig,
11
- ConfiguredRoute
11
+ ConfiguredRoute,
12
+ UserManagement
12
13
  } from './types/global'
package/index.ts CHANGED
@@ -27,6 +27,7 @@ import fastifyApollo, { fastifyApolloDrainPlugin } from '@as-integrations/fastif
27
27
  import { myContextFunction, MyContext } from './lib/apollo/context'
28
28
  import resolvers from './lib/apollo/resolvers'
29
29
  import typeDefs from './lib/apollo/type-defs'
30
+ import { UserManagement } from './types/global'
30
31
 
31
32
  global.log = logger
32
33
 
@@ -132,7 +133,7 @@ async function addFastifySwagger(fastify: FastifyInstance) {
132
133
  }
133
134
  }
134
135
 
135
- const start = async () => {
136
+ const start = async (decorators) => {
136
137
  const begin = new Date().getTime()
137
138
  mark.print(logger)
138
139
  global.roles = loaderRoles.load()
@@ -164,6 +165,52 @@ const start = async () => {
164
165
  await addApolloRouting(fastify, apollo)
165
166
  await addFastifyRouting(fastify)
166
167
 
168
+ // defaults
169
+ decorators = {
170
+ userManager: {
171
+ createUser(data: any) {
172
+ throw Error('Not implemented')
173
+ },
174
+ resetExternalId(data: any) {
175
+ throw Error('Not implemented')
176
+ },
177
+ updateUserById(id: string, user: any) {
178
+ throw Error('Not implemented')
179
+ },
180
+ retrieveUserById(id: string) {
181
+ throw Error('Not implemented')
182
+ },
183
+ retrieveUserByEmail(email: string) {
184
+ throw Error('Not implemented')
185
+ },
186
+ retrieveUserByExternalId(externalId: string) {
187
+ throw Error('Not implemented')
188
+ },
189
+ retrieveUserByPassword(email: string, password: string) {
190
+ throw Error('Not implemented')
191
+ },
192
+ changePassword(email: string, password: string, oldPassword: string) {
193
+ throw Error('Not implemented')
194
+ },
195
+ enableUserById(id: string) {
196
+ throw Error('Not implemented')
197
+ },
198
+ disableUserById(id: string) {
199
+ throw Error('Not implemented')
200
+ },
201
+ isValidUser(data: any) {
202
+ throw Error('Not implemented')
203
+ }
204
+ } as UserManagement,
205
+ ...decorators
206
+ }
207
+
208
+ await Promise.all(
209
+ Object.keys(decorators || {}).map(async (key) => {
210
+ await fastify.decorate(key, decorators[key])
211
+ })
212
+ )
213
+
167
214
  await fastify
168
215
  .listen({
169
216
  port: Number(port),
@@ -192,7 +239,8 @@ export {
192
239
  Roles,
193
240
  Route,
194
241
  RouteConfig,
195
- ConfiguredRoute
242
+ ConfiguredRoute,
243
+ UserManagement
196
244
  } from './types/global'
197
245
 
198
246
  /**
@@ -1,31 +1,126 @@
1
1
  import { FastifyReply, FastifyRequest } from 'fastify'
2
- import { AuthenticatedUser } from '../../../../types/global'
2
+ import * as regExp from '../../../util/regexp'
3
+
4
+ export async function register(req: FastifyRequest, reply: FastifyReply) {
5
+ const { password1: password, password2, ...data } = req.data()
6
+
7
+ if (!data.username) {
8
+ return reply.status(404).send(Error('Username not valid'))
9
+ }
10
+ if (!data.email || !regExp.email.test(data.email)) {
11
+ return reply.status(404).send(Error('Email not valid'))
12
+ }
13
+ if (!password || !regExp.password.test(password)) {
14
+ return reply.status(404).send(Error('Password not valid'))
15
+ }
16
+ if (!password2 || password2 !== password) {
17
+ return reply.status(404).send(Error('Repeated password not match'))
18
+ }
19
+
20
+ // public is the default
21
+ const publicRole = global.roles?.public?.code || 'public'
22
+ data.roles = (data.requiredRoles || []).map((r) => global.roles[r]?.code).filter((r) => !!r)
23
+ if (!data.roles.includes(publicRole)) {
24
+ data.roles.push(publicRole)
25
+ }
26
+
27
+ const user = await req.server['userManager'].createUser({ ...data, password: password })
28
+ if (!user) {
29
+ return reply.status(400).send(Error('User not registered'))
30
+ }
31
+
32
+ return user
33
+ }
34
+
35
+ export async function unregister(req: FastifyRequest, reply: FastifyReply) {
36
+ const { email, password } = req.data()
37
+
38
+ let user = await req.server['userManager'].retrieveUserByPassword(email, password)
39
+ let isValid = await req.server['userManager'].isValidUser(user)
40
+
41
+ if (!isValid) {
42
+ return reply.status(403).send(Error('Wrong credentials'))
43
+ }
44
+
45
+ if (!user.enabled) {
46
+ return reply.status(403).send(Error('User not enabled'))
47
+ }
48
+
49
+ user = await req.server['userManager'].disableUserById(user?.id)
50
+ isValid = await req.server['userManager'].isValidUser(user)
51
+
52
+ if (!isValid) {
53
+ return reply.status(400).send(Error('User not valid'))
54
+ }
55
+
56
+ return { ok: true }
57
+ }
58
+
59
+ export async function changePassword(req: FastifyRequest, reply: FastifyReply) {
60
+ const { email, oldPassword, newPassword1, newPassword2 } = req.data()
61
+
62
+ if (!newPassword1 || !regExp.password.test(newPassword1)) {
63
+ return reply.status(404).send(Error('New password not valid'))
64
+ }
65
+
66
+ if (!newPassword2 || newPassword2 !== newPassword1) {
67
+ return reply.status(404).send(Error('Repeated new password not match'))
68
+ }
69
+
70
+ let user = await req.server['userManager'].retrieveUserByPassword(email, oldPassword)
71
+ let isValid = await req.server['userManager'].isValidUser(user)
72
+
73
+ if (!isValid) {
74
+ return reply.status(403).send(Error('Wrong credentials'))
75
+ }
76
+
77
+ if (!user.enabled) {
78
+ return reply.status(403).send(Error('User not enabled'))
79
+ }
80
+
81
+ user = await req.server['userManager'].changePassword(email, newPassword1, oldPassword)
82
+ isValid = await req.server['userManager'].isValidUser(user)
83
+ return { ok: isValid }
84
+ }
3
85
 
4
86
  export async function login(req: FastifyRequest, reply: FastifyReply) {
5
- const { email = '', password = '' } = req.data()
6
-
7
- // TODO: use UserManagement.find and check password
8
- // demo code here
9
- const username = email.substr(0, email.indexOf('@')) || 'jerry'
10
- const roleList = [username === 'admin' ? roles.admin : username === 'vminds' ? roles.backoffice : roles.public]
11
- const user =
12
- username !== null
13
- ? ({
14
- id: 306, // user id
15
- name: username, // optional
16
- email: email,
17
- roles: roleList
18
- } as AuthenticatedUser)
19
- : null
20
-
21
- // TODO: review if email is important to include in token (for a security purpose)
87
+ const { email, password } = req.data()
88
+
89
+ if (!email || !regExp.email.test(email)) {
90
+ return reply.status(404).send(Error('Email not valid'))
91
+ }
92
+ if (!password || !regExp.password.test(password)) {
93
+ return reply.status(404).send(Error('Password not valid'))
94
+ }
95
+
96
+ const user = await req.server['userManager'].retrieveUserByPassword(email, password)
97
+ const isValid = await req.server['userManager'].isValidUser(user)
98
+
99
+ if (!isValid) {
100
+ return reply.status(403).send(Error('Wrong credentials'))
101
+ }
102
+
103
+ if (!user.enabled) {
104
+ return reply.status(403).send(Error('User not enabled'))
105
+ }
106
+
107
+ // log.trace('User: ' + JSON.stringify(user) + ' ' + roles)
22
108
  // https://www.iana.org/assignments/jwt/jwt.xhtml
23
- const token = user !== null ? await reply.jwtSign({ sub: user.id, name: user.name, email: user.email }) : null
24
- reply.send({ ...user, token: token || null, roles: roleList.map((r) => r.code) })
109
+ const token = user !== null ? await reply.jwtSign({ sub: user.externalId }) : null
110
+ return {
111
+ ...user,
112
+ token: token || null,
113
+ roles: (user.roles || [global.role?.public?.code || 'public']).map((r) => r?.code || r)
114
+ }
25
115
  }
26
116
 
27
- export async function demo(req: FastifyRequest, reply: FastifyReply) {
28
- // JSON.stringify(req.user)
117
+ export async function invalidateTokens(req: FastifyRequest, reply: FastifyReply) {
118
+ let isValid = await req.server['userManager'].isValidUser(req.user)
119
+ if (!isValid) {
120
+ return reply.status(403).send(Error('User not linked'))
121
+ }
29
122
 
30
- reply.send({ ok: req.user })
123
+ const user = await req.server['userManager'].resetExternalId(req.user?.id)
124
+ isValid = await req.server['userManager'].isValidUser(user)
125
+ return { ok: isValid }
31
126
  }