@volcanicminds/backend 0.3.6 → 0.5.1
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/.mocharc.json +3 -0
- package/README.md +2 -1
- package/TODO.md +0 -2
- package/dist/index.js +47 -36
- package/dist/index.js.map +1 -1
- package/dist/lib/api/auth/controller/auth.js +49 -50
- package/dist/lib/api/auth/controller/auth.js.map +1 -1
- package/dist/lib/api/health/controller/health.js +1 -12
- package/dist/lib/api/health/controller/health.js.map +1 -1
- package/dist/lib/api/token/controller/token.js +4 -4
- package/dist/lib/api/token/controller/token.js.map +1 -1
- package/dist/lib/api/tool/controller/tool.js +25 -0
- package/dist/lib/api/tool/controller/tool.js.map +1 -0
- package/dist/lib/api/tool/routes.js +26 -0
- package/dist/lib/api/tool/routes.js.map +1 -0
- package/dist/lib/api/users/controller/user.js +4 -17
- package/dist/lib/api/users/controller/user.js.map +1 -1
- package/dist/lib/hooks/onRequest.js +1 -7
- package/dist/lib/hooks/onRequest.js.map +1 -1
- package/dist/lib/loader/translation.js +53 -0
- package/dist/lib/loader/translation.js.map +1 -0
- package/dist/lib/locales/en.json +12 -0
- package/dist/lib/locales/it.json +12 -0
- package/dist/lib/util/errors.js +19 -0
- package/dist/lib/util/errors.js.map +1 -0
- package/dist/nodemon.json +7 -0
- package/dist/package.json +100 -0
- package/dist/tsconfig.json +32 -0
- package/index.ts +47 -38
- package/lib/api/auth/controller/auth.ts +52 -53
- package/lib/api/health/controller/health.ts +1 -1
- package/lib/api/token/controller/token.ts +4 -4
- package/lib/api/tool/controller/tool.ts +13 -0
- package/lib/api/tool/routes.ts +24 -0
- package/lib/api/users/controller/user.ts +2 -2
- package/lib/loader/translation.ts +67 -0
- package/lib/locales/en.json +12 -0
- package/lib/locales/it.json +12 -0
- package/lib/util/errors.ts +20 -0
- package/package.json +13 -7
- package/test/common/api.ts +80 -0
- package/test/common/bootstrap.ts +33 -0
- package/test/demo/demo.ts +9 -0
- package/test/demo/index.ts +14 -0
- package/test/e2e/index.ts +14 -0
- package/test/index.spec.ts +20 -0
- package/test/unit/index.ts +14 -0
- package/test/unit/semver.ts +24 -0
- package/test/unit/translation.ts +77 -0
- package/tsconfig.json +2 -1
- package/types/global.d.ts +5 -0
- package/test/example.test.js +0 -5
- package/test/semver.test.js +0 -16
|
@@ -36,7 +36,7 @@ function create(req, reply) {
|
|
|
36
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
37
|
const data = req.data();
|
|
38
38
|
if (!data.name) {
|
|
39
|
-
return reply.status(404).send(Error('Token name not valid'));
|
|
39
|
+
return reply.status(404).send(new Error('Token name not valid'));
|
|
40
40
|
}
|
|
41
41
|
const publicRole = ((_b = (_a = global.roles) === null || _a === void 0 ? void 0 : _a.public) === null || _b === void 0 ? void 0 : _b.code) || 'public';
|
|
42
42
|
data.roles = (data.requiredRoles || []).map((r) => { var _a; return (_a = global.roles[r]) === null || _a === void 0 ? void 0 : _a.code; }).filter((r) => !!r);
|
|
@@ -45,13 +45,13 @@ function create(req, reply) {
|
|
|
45
45
|
}
|
|
46
46
|
let token = yield req.server['tokenManager'].createToken(data);
|
|
47
47
|
if (!token || !token.getId() || !token.externalId) {
|
|
48
|
-
return reply.status(400).send(Error('Token not registered'));
|
|
48
|
+
return reply.status(400).send(new Error('Token not registered'));
|
|
49
49
|
}
|
|
50
50
|
const bearerToken = yield reply.jwtSign({ sub: token.externalId }, {
|
|
51
51
|
sign: { expiresIn: (data === null || data === void 0 ? void 0 : data.expiresIn) || undefined }
|
|
52
52
|
});
|
|
53
53
|
if (!bearerToken) {
|
|
54
|
-
return reply.status(400).send(Error('Token not signed'));
|
|
54
|
+
return reply.status(400).send(new Error('Token not signed'));
|
|
55
55
|
}
|
|
56
56
|
token = yield req.server['tokenManager'].updateTokenById(token.getId(), { token: bearerToken });
|
|
57
57
|
return token;
|
|
@@ -66,7 +66,7 @@ function remove(req, reply) {
|
|
|
66
66
|
}
|
|
67
67
|
let token = yield req.server['tokenManager'].retrieveTokenById(id);
|
|
68
68
|
if (!token) {
|
|
69
|
-
return reply.status(403).send(Error('Token not found'));
|
|
69
|
+
return reply.status(403).send(new Error('Token not found'));
|
|
70
70
|
}
|
|
71
71
|
token = yield req.server['tokenManager'].removeTokenById(id);
|
|
72
72
|
return { ok: true };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../../../lib/api/token/controller/token.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,SAAsB,KAAK,CAAC,GAAmB,EAAE,KAAmB;;QAClE,OAAO,MAAM,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;IAChE,CAAC;CAAA;AAFD,sBAEC;AAED,SAAsB,IAAI,CAAC,GAAmB,EAAE,KAAmB;;QACjE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;QACnF,OAAO,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACtE,CAAC;CAAA;AAHD,oBAGC;AAED,SAAsB,OAAO,CAAC,GAAmB,EAAE,KAAmB;;QACpE,MAAM,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,UAAU,EAAE,CAAA;QAE/B,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAA;QACpE,OAAO,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;IAC1C,CAAC;CAAA;AALD,0BAKC;AAED,SAAsB,MAAM,CAAC,GAAmB,EAAE,KAAmB;;;QACnE,MAAM,IA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OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE;YAC/D,OAAO,KAAK;iBACT,MAAM,CAAC,GAAG,CAAC;iBACX,IAAI,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,+BAA+B,EAAE,CAAC,CAAA;SACjG;QAED,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,UAAU,EAAE,CAAA;QACvC,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QACtE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAA;IAC/B,CAAC;CAAA;AAVD,0BAUC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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.synchronizeSchemas = void 0;
|
|
13
|
+
function synchronizeSchemas(req, reply) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
if (!req.server['dataBaseManager'].isImplemented()) {
|
|
16
|
+
throw new Error('Not implemented');
|
|
17
|
+
}
|
|
18
|
+
reply.send({ ok: true });
|
|
19
|
+
log.warn('Database schema synchronization started');
|
|
20
|
+
yield req.server['dataBaseManager'].synchronizeSchemas();
|
|
21
|
+
log.warn('Database schema synchronization finished');
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.synchronizeSchemas = synchronizeSchemas;
|
|
25
|
+
//# sourceMappingURL=tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../../../lib/api/tool/controller/tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,SAAsB,kBAAkB,CAAC,GAAmB,EAAE,KAAmB;;QAC/E,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,aAAa,EAAE,EAAE;YAClD,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;SACnC;QAED,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;QAExB,GAAG,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAA;QACnD,MAAM,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,kBAAkB,EAAE,CAAA;QACxD,GAAG,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAA;IACtD,CAAC;CAAA;AAVD,gDAUC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = {
|
|
3
|
+
config: {
|
|
4
|
+
title: 'Tool functions',
|
|
5
|
+
description: 'Tool functions',
|
|
6
|
+
controller: 'controller',
|
|
7
|
+
tags: ['tool']
|
|
8
|
+
},
|
|
9
|
+
routes: [
|
|
10
|
+
{
|
|
11
|
+
method: 'POST',
|
|
12
|
+
path: '/synchronize-schemas',
|
|
13
|
+
roles: [roles.admin],
|
|
14
|
+
handler: 'tool.synchronizeSchemas',
|
|
15
|
+
middlewares: ['global.isAuthenticated'],
|
|
16
|
+
config: {
|
|
17
|
+
title: 'Synchronize database schema',
|
|
18
|
+
description: 'Synchronize database schema',
|
|
19
|
+
response: {
|
|
20
|
+
200: { $ref: 'defaultResponse#' }
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../../../lib/api/tool/routes.ts"],"names":[],"mappings":";AAAA,MAAM,CAAC,OAAO,GAAG;IACf,MAAM,EAAE;QACN,KAAK,EAAE,gBAAgB;QACvB,WAAW,EAAE,gBAAgB;QAC7B,UAAU,EAAE,YAAY;QACxB,IAAI,EAAE,CAAC,MAAM,CAAC;KACf;IACD,MAAM,EAAE;QACN;YACE,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,sBAAsB;YAC5B,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC;YACpB,OAAO,EAAE,yBAAyB;YAClC,WAAW,EAAE,CAAC,wBAAwB,CAAC;YACvC,MAAM,EAAE;gBACN,KAAK,EAAE,6BAA6B;gBACpC,WAAW,EAAE,6BAA6B;gBAC1C,QAAQ,EAAE;oBACR,GAAG,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE;iBAClC;aACF;SACF;KACF;CACF,CAAA"}
|
|
@@ -1,27 +1,14 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.isAdmin = exports.user = void 0;
|
|
13
4
|
function user(req, reply) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
reply.send(user ? Object.assign(Object.assign({}, user), { roles: req.roles() }) : {});
|
|
17
|
-
});
|
|
5
|
+
const user = req.user;
|
|
6
|
+
reply.send(user ? Object.assign(Object.assign({}, user), { roles: req.roles() }) : {});
|
|
18
7
|
}
|
|
19
8
|
exports.user = user;
|
|
20
9
|
function isAdmin(req, reply) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
reply.send({ isAdmin: (user === null || user === void 0 ? void 0 : user.getId()) && req.hasRole(roles.admin) });
|
|
24
|
-
});
|
|
10
|
+
const user = req.user;
|
|
11
|
+
reply.send({ isAdmin: (user === null || user === void 0 ? void 0 : user.getId()) && req.hasRole(roles.admin) });
|
|
25
12
|
}
|
|
26
13
|
exports.isAdmin = isAdmin;
|
|
27
14
|
//# sourceMappingURL=user.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../../../lib/api/users/controller/user.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../../../lib/api/users/controller/user.ts"],"names":[],"mappings":";;;AAGA,SAAgB,IAAI,CAAC,GAAmB,EAAE,KAAmB;IAC3D,MAAM,IAAI,GAAkC,GAAG,CAAC,IAAI,CAAA;IACpD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,iCAAM,IAAI,KAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,IAAG,CAAC,CAAC,EAAE,CAAC,CAAA;AACzD,CAAC;AAHD,oBAGC;AAED,SAAgB,OAAO,CAAC,GAAmB,EAAE,KAAmB;IAC9D,MAAM,IAAI,GAAkC,GAAG,CAAC,IAAI,CAAA;IACpD,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,EAAE,KAAI,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;AACpE,CAAC;AAHD,0BAGC"}
|
|
@@ -35,13 +35,7 @@ module.exports = (req, reply) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
35
35
|
if (user) {
|
|
36
36
|
const isValid = yield req.server['userManager'].isValidUser(user);
|
|
37
37
|
if (!isValid) {
|
|
38
|
-
return reply.status(
|
|
39
|
-
}
|
|
40
|
-
const isPasswordToBeChanged = yield req.server['userManager'].isPasswordToBeChanged(user);
|
|
41
|
-
if (isPasswordToBeChanged) {
|
|
42
|
-
return reply
|
|
43
|
-
.status(403)
|
|
44
|
-
.send({ statusCode: 403, code: 'PASSWORD_TO_BE_CHANGED', message: 'The password is expired' });
|
|
38
|
+
return reply.status(404).send({ statusCode: 404, code: 'USER_NOT_VALID', message: 'User not valid' });
|
|
45
39
|
}
|
|
46
40
|
req.user = user;
|
|
47
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onRequest.js","sourceRoot":"","sources":["../../../lib/hooks/onRequest.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2CAAmD;AAGnD,MAAM,CAAC,OAAO,GAAG,CAAO,GAAG,EAAE,KAAK,EAAE,EAAE;;IAEpC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,CAAA;IACrC,GAAG,CAAC,IAAI,GAAG,GAAG,EAAE,CAAC,IAAA,gBAAO,EAAC,GAAG,CAAC,CAAA;IAC7B,GAAG,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAA;IACrC,GAAG,CAAC,KAAK,GAAG,GAAG,EAAE,C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M,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,GAAG,EAAE,EAAE,aAAa,EAAE,GAAG,GAAG,CAAC,WAAW,CAAA;QAChE,MAAM,SAAS,GAAa,CAAC,MAAA,CAAC,CAAA,MAAA,GAAG,CAAC,IAAI,0CAAE,KAAK,MAAI,MAAA,GAAG,CAAC,KAAK,0CAAE,KAAK,CAAA,CAAC,0CAAE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAc,KAAI;YACtG,CAAA,MAAA,KAAK,CAAC,MAAM,0CAAE,IAAI,KAAI,QAAQ;SAC/B,CAAA;QACD,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QAEzG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE;YACzB,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,uBAAuB,MAAM,CAAC,WAAW,EAAE,IAAI,GAAG,EAAE,CAAC,CAAA;YACvE,OAAO,KAAK;iBACT,MAAM,CAAC,GAAG,CAAC;iBACX,IAAI,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,gCAAgC,EAAE,CAAC,CAAA;SAClG;KACF;AACH,CAAC,CAAA,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.load = void 0;
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const glob = require('glob');
|
|
6
|
+
const { I18n } = require('i18n');
|
|
7
|
+
function load() {
|
|
8
|
+
const i18n = new I18n({
|
|
9
|
+
locales: ['en', 'it'],
|
|
10
|
+
defaultLocale: 'en',
|
|
11
|
+
autoReload: false,
|
|
12
|
+
updateFiles: false,
|
|
13
|
+
syncFiles: false,
|
|
14
|
+
extension: '.json',
|
|
15
|
+
prefix: '',
|
|
16
|
+
objectNotation: true,
|
|
17
|
+
logDebugFn: (msg) => log.debug(msg),
|
|
18
|
+
logWarnFn: (msg) => log.warn(msg),
|
|
19
|
+
logErrorFn: (msg) => log.error(msg)
|
|
20
|
+
});
|
|
21
|
+
const basePath = path.join(__dirname, '..', 'locales', '*.json').replaceAll('\\', '/');
|
|
22
|
+
glob.sync(basePath).forEach((f) => {
|
|
23
|
+
log.info('* Loading base dictionary %s', path.parse(f).base);
|
|
24
|
+
try {
|
|
25
|
+
const content = require(f);
|
|
26
|
+
addLocaleFile(i18n, path.parse(f).name, content);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
log.error(err);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const addPath = path.join(process.cwd(), 'src', 'locales', '*.json').replaceAll('\\', '/');
|
|
33
|
+
glob.sync(addPath).forEach((f) => {
|
|
34
|
+
log.info('* Loading additional dictionary %s', path.parse(f).base);
|
|
35
|
+
try {
|
|
36
|
+
const content = require(f);
|
|
37
|
+
addLocaleFile(i18n, path.parse(f).name, content);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
log.error(err);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
i18n.setLocale(i18n.defaultLocale || 'en');
|
|
44
|
+
return i18n;
|
|
45
|
+
}
|
|
46
|
+
exports.load = load;
|
|
47
|
+
function addLocaleFile(i18n, locale, content) {
|
|
48
|
+
let catalog = i18n && i18n.getCatalog();
|
|
49
|
+
if (catalog && locale && content) {
|
|
50
|
+
catalog[locale] = catalog[locale] ? Object.assign(Object.assign({}, catalog[locale]), content) : content;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=translation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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CAAA;KACjF;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TranslatedError = void 0;
|
|
4
|
+
class TranslatedError extends Error {
|
|
5
|
+
constructor({ translationCode, data = {}, locale = 'en', defaultMessage = null, status = 400 }) {
|
|
6
|
+
var _a;
|
|
7
|
+
super();
|
|
8
|
+
this.name = ((_a = this.constructor) === null || _a === void 0 ? void 0 : _a.name) || 'TranslatedError';
|
|
9
|
+
this.locale = locale;
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.translationCode = translationCode;
|
|
12
|
+
this.translatedMessage = global.t.__({ phrase: translationCode || defaultMessage, locale: locale || 'en' }, data);
|
|
13
|
+
this.message = this.translatedMessage || defaultMessage || 'generic error';
|
|
14
|
+
this.data = data;
|
|
15
|
+
Error.captureStackTrace(this, this.constructor || TranslatedError);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.TranslatedError = TranslatedError;
|
|
19
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../lib/util/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAgB,SAAQ,KAAK;IAOxC,YAAY,EAAE,eAAe,EAAE,IAAI,GAAG,EAAE,EAAE,MAAM,GAAG,IAAI,EAAE,cAAc,GAAG,IAAI,EAAE,MAAM,GAAG,GAAG,EAAE;;QAC5F,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,IAAI,GAAG,CAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,KAAI,iBAAiB,CAAA;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,eAAe,IAAI,cAAc,EAAE,MAAM,EAAE,MAAM,IAAI,IAAI,EAAE,EAAE,IAAI,CAAC,CAAA;QACjH,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,iBAAiB,IAAI,cAAc,IAAI,eAAe,CAAA;QAC1E,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAEhB,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,IAAI,eAAe,CAAC,CAAA;IACpE,CAAC;CACF;AAnBD,0CAmBC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@volcanicminds/backend",
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"codename": "turin",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "The volcanic (minds) backend",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"volcanic",
|
|
9
|
+
"open source",
|
|
10
|
+
"api",
|
|
11
|
+
"framework",
|
|
12
|
+
"backend",
|
|
13
|
+
"http",
|
|
14
|
+
"https",
|
|
15
|
+
"fastify",
|
|
16
|
+
"apollo",
|
|
17
|
+
"swagger",
|
|
18
|
+
"graphql",
|
|
19
|
+
"helmet",
|
|
20
|
+
"json",
|
|
21
|
+
"typescript",
|
|
22
|
+
"javascript",
|
|
23
|
+
"rest",
|
|
24
|
+
"restful",
|
|
25
|
+
"graphql",
|
|
26
|
+
"pino",
|
|
27
|
+
"rate limit",
|
|
28
|
+
"jest"
|
|
29
|
+
],
|
|
30
|
+
"main": "dist/index",
|
|
31
|
+
"typings": "dist/index",
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=16"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"clean": "rm -rf dist esm",
|
|
37
|
+
"prebuild": "npm run clean",
|
|
38
|
+
"build:esm": "tsc --target es2018 --outDir esm",
|
|
39
|
+
"build:cjs": "tsc --target es2015 --module commonjs --outDir dist",
|
|
40
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
41
|
+
"compile": "npm run build",
|
|
42
|
+
"preprod": "npm run build",
|
|
43
|
+
"prod": "cd dist && node server.js",
|
|
44
|
+
"server": "cd dist && node server.js",
|
|
45
|
+
"start": "ts-node server.ts",
|
|
46
|
+
"dev": "nodemon --exec \"ts-node\" server.ts",
|
|
47
|
+
"test": "yarn test:full",
|
|
48
|
+
"test:full": "cross-env PORT=2231 NODE_ENV=memory BROWSER=false mocha ./test/index.spec.ts -t 100000",
|
|
49
|
+
"reset": "yarn && yarn upgrade && yarn compile",
|
|
50
|
+
"upgrade-deps": "yarn upgrade-interactive"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@apollo/server": "^4.3.3",
|
|
54
|
+
"@as-integrations/fastify": "^1.2.0",
|
|
55
|
+
"@fastify/compress": "^6.2.0",
|
|
56
|
+
"@fastify/cors": "^8.2.0",
|
|
57
|
+
"@fastify/helmet": "^10.1.0",
|
|
58
|
+
"@fastify/jwt": "^6.5.0",
|
|
59
|
+
"@fastify/rate-limit": "^7.6.0",
|
|
60
|
+
"@fastify/swagger": "^8.2.0",
|
|
61
|
+
"@fastify/swagger-ui": "^1.3.0",
|
|
62
|
+
"@types/node": "^20.3.1",
|
|
63
|
+
"dotenv": "^16.0.3",
|
|
64
|
+
"fastify": "^4.13.0",
|
|
65
|
+
"glob": "^8.0.3",
|
|
66
|
+
"graphql": "^16.6.0",
|
|
67
|
+
"i18n": "^0.15.1",
|
|
68
|
+
"nanoid": "^4.0.1",
|
|
69
|
+
"object-sizeof": "^1.6.3",
|
|
70
|
+
"pino": "^8.10.0",
|
|
71
|
+
"pino-pretty": "^9.1.1",
|
|
72
|
+
"root-require": "^0.3.1",
|
|
73
|
+
"semver": "^7.3.8"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@types/mocha": "^10.0.1",
|
|
77
|
+
"cross-env": "^7.0.3",
|
|
78
|
+
"expect": "^29.5.0",
|
|
79
|
+
"mocha": "^10.2.0",
|
|
80
|
+
"nodemon": "^2.0.20",
|
|
81
|
+
"ts-node": "^10.9.1",
|
|
82
|
+
"typescript": "^4.9.3"
|
|
83
|
+
},
|
|
84
|
+
"repository": {
|
|
85
|
+
"type": "git",
|
|
86
|
+
"url": "git+https://github.com/volcanicminds/volcanic-backend.git"
|
|
87
|
+
},
|
|
88
|
+
"homepage": "https://volcanicminds.com",
|
|
89
|
+
"bugs": {
|
|
90
|
+
"url": "https://github.com/volcanicminds/volcanic-backend/issues"
|
|
91
|
+
},
|
|
92
|
+
"author": "Volcanic Minds <developers@volcanicminds.com> (https://volcanicminds.com)",
|
|
93
|
+
"maintainers": [
|
|
94
|
+
"Developers <developers@volcanicminds.com> (https://volcanicminds.com)"
|
|
95
|
+
],
|
|
96
|
+
"directories": {
|
|
97
|
+
"lib": "lib",
|
|
98
|
+
"test": "test"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "ts-node/node16/tsconfig.json",
|
|
3
|
+
"ts-node": {
|
|
4
|
+
"files": true,
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"module": "commonjs"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"compilerOptions": {
|
|
10
|
+
"module": "commonjs",
|
|
11
|
+
"moduleResolution": "node",
|
|
12
|
+
"declaration": false,
|
|
13
|
+
"noImplicitAny": false,
|
|
14
|
+
"noUnusedLocals": false,
|
|
15
|
+
"removeComments": true,
|
|
16
|
+
"noLib": false,
|
|
17
|
+
"emitDecoratorMetadata": true,
|
|
18
|
+
"experimentalDecorators": true,
|
|
19
|
+
"useUnknownInCatchVariables": false,
|
|
20
|
+
"target": "es6",
|
|
21
|
+
"sourceMap": true,
|
|
22
|
+
"allowJs": true,
|
|
23
|
+
"outDir": "dist",
|
|
24
|
+
"lib": ["es7"],
|
|
25
|
+
"resolveJsonModule": true,
|
|
26
|
+
"paths": {
|
|
27
|
+
"@types": ["./types"]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"include": ["*.ts", "*.d.ts", "*.json", "lib/**/*", "lib/**/*.json", "types/*"],
|
|
31
|
+
"exclude": ["node_modules", "test/**/*"]
|
|
32
|
+
}
|
package/index.ts
CHANGED
|
@@ -6,11 +6,13 @@ dotenv.config()
|
|
|
6
6
|
import yn from './lib/util/yn'
|
|
7
7
|
import logger from './lib/util/logger'
|
|
8
8
|
import * as mark from './lib/util/mark'
|
|
9
|
+
import { TranslatedError } from './lib/util/errors'
|
|
9
10
|
import * as loaderPlugins from './lib/loader/plugins'
|
|
10
11
|
import * as loaderRoles from './lib/loader/roles'
|
|
11
12
|
import * as loaderRouter from './lib/loader/router'
|
|
12
13
|
import * as loaderHooks from './lib/loader/hooks'
|
|
13
14
|
import * as loaderSchemas from './lib/loader/schemas'
|
|
15
|
+
import * as loaderTranslation from './lib/loader/translation'
|
|
14
16
|
|
|
15
17
|
import Fastify, { FastifyInstance } from 'fastify'
|
|
16
18
|
import jwtValidator from '@fastify/jwt'
|
|
@@ -27,7 +29,7 @@ import fastifyApollo, { fastifyApolloDrainPlugin } from '@as-integrations/fastif
|
|
|
27
29
|
import { myContextFunction, MyContext } from './lib/apollo/context'
|
|
28
30
|
import resolvers from './lib/apollo/resolvers'
|
|
29
31
|
import typeDefs from './lib/apollo/type-defs'
|
|
30
|
-
import { UserManagement, TokenManagement } from './types/global'
|
|
32
|
+
import { UserManagement, TokenManagement, DataBaseManagement } from './types/global'
|
|
31
33
|
|
|
32
34
|
global.log = logger
|
|
33
35
|
|
|
@@ -129,7 +131,7 @@ async function addFastifySwagger(fastify: FastifyInstance) {
|
|
|
129
131
|
theme: {
|
|
130
132
|
title: SWAGGER_TITLE
|
|
131
133
|
}
|
|
132
|
-
}
|
|
134
|
+
})
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
137
|
|
|
@@ -137,6 +139,7 @@ const start = async (decorators) => {
|
|
|
137
139
|
const begin = new Date().getTime()
|
|
138
140
|
mark.print(logger)
|
|
139
141
|
global.roles = loaderRoles.load()
|
|
142
|
+
global.t = loaderTranslation.load()
|
|
140
143
|
|
|
141
144
|
const opts = yn(process.env.LOG_FASTIFY, false) ? { logger: logger } : {}
|
|
142
145
|
const fastify = await Fastify(opts)
|
|
@@ -187,64 +190,61 @@ const start = async (decorators) => {
|
|
|
187
190
|
return false
|
|
188
191
|
},
|
|
189
192
|
isValidUser(data: any) {
|
|
190
|
-
throw Error('Not implemented')
|
|
193
|
+
throw new Error('Not implemented')
|
|
191
194
|
},
|
|
192
195
|
createUser(data: any) {
|
|
193
|
-
throw Error('Not implemented')
|
|
196
|
+
throw new Error('Not implemented')
|
|
194
197
|
},
|
|
195
198
|
resetExternalId(data: any) {
|
|
196
|
-
throw Error('Not implemented')
|
|
199
|
+
throw new Error('Not implemented')
|
|
197
200
|
},
|
|
198
201
|
updateUserById(id: string, user: any) {
|
|
199
|
-
throw Error('Not implemented')
|
|
202
|
+
throw new Error('Not implemented')
|
|
200
203
|
},
|
|
201
204
|
retrieveUserById(id: string) {
|
|
202
|
-
throw Error('Not implemented')
|
|
205
|
+
throw new Error('Not implemented')
|
|
203
206
|
},
|
|
204
207
|
retrieveUserByEmail(email: string) {
|
|
205
|
-
throw Error('Not implemented')
|
|
208
|
+
throw new Error('Not implemented')
|
|
206
209
|
},
|
|
207
210
|
retrieveUserByConfirmationToken(code: string) {
|
|
208
|
-
throw Error('Not implemented')
|
|
211
|
+
throw new Error('Not implemented')
|
|
209
212
|
},
|
|
210
213
|
retrieveUserByResetPasswordToken(code: string) {
|
|
211
|
-
throw Error('Not implemented')
|
|
214
|
+
throw new Error('Not implemented')
|
|
212
215
|
},
|
|
213
216
|
retrieveUserByUsername(username: string) {
|
|
214
|
-
throw Error('Not implemented')
|
|
217
|
+
throw new Error('Not implemented')
|
|
215
218
|
},
|
|
216
219
|
retrieveUserByExternalId(externalId: string) {
|
|
217
|
-
throw Error('Not implemented')
|
|
220
|
+
throw new Error('Not implemented')
|
|
218
221
|
},
|
|
219
222
|
retrieveUserByPassword(email: string, password: string) {
|
|
220
|
-
throw Error('Not implemented')
|
|
223
|
+
throw new Error('Not implemented')
|
|
221
224
|
},
|
|
222
225
|
changePassword(email: string, password: string, oldPassword: string) {
|
|
223
|
-
throw Error('Not implemented')
|
|
226
|
+
throw new Error('Not implemented')
|
|
224
227
|
},
|
|
225
228
|
forgotPassword(email: string) {
|
|
226
|
-
throw Error('Not implemented')
|
|
229
|
+
throw new Error('Not implemented')
|
|
227
230
|
},
|
|
228
231
|
userConfirmation(user: any) {
|
|
229
|
-
throw Error('Not implemented')
|
|
232
|
+
throw new Error('Not implemented')
|
|
230
233
|
},
|
|
231
234
|
resetPassword(user: any, password: string) {
|
|
232
|
-
throw Error('Not implemented')
|
|
235
|
+
throw new Error('Not implemented')
|
|
233
236
|
},
|
|
234
237
|
blockUserById(id: string, reason: string) {
|
|
235
|
-
throw Error('Not implemented')
|
|
238
|
+
throw new Error('Not implemented')
|
|
236
239
|
},
|
|
237
240
|
unblockUserById(data: any) {
|
|
238
|
-
throw Error('Not implemented')
|
|
241
|
+
throw new Error('Not implemented')
|
|
239
242
|
},
|
|
240
243
|
countQuery(data: any) {
|
|
241
|
-
throw Error('Not implemented')
|
|
244
|
+
throw new Error('Not implemented')
|
|
242
245
|
},
|
|
243
246
|
findQuery(data: any) {
|
|
244
|
-
throw Error('Not implemented')
|
|
245
|
-
},
|
|
246
|
-
isPasswordToBeChanged(data: any) {
|
|
247
|
-
throw Error('Not implemented')
|
|
247
|
+
throw new Error('Not implemented')
|
|
248
248
|
}
|
|
249
249
|
} as UserManagement,
|
|
250
250
|
tokenManager: {
|
|
@@ -252,39 +252,47 @@ const start = async (decorators) => {
|
|
|
252
252
|
return false
|
|
253
253
|
},
|
|
254
254
|
isValidToken(data: any) {
|
|
255
|
-
throw Error('Not implemented')
|
|
255
|
+
throw new Error('Not implemented')
|
|
256
256
|
},
|
|
257
257
|
createToken(data: any) {
|
|
258
|
-
throw Error('Not implemented')
|
|
258
|
+
throw new Error('Not implemented')
|
|
259
259
|
},
|
|
260
260
|
resetExternalId(id: string) {
|
|
261
|
-
throw Error('Not implemented')
|
|
261
|
+
throw new Error('Not implemented')
|
|
262
262
|
},
|
|
263
263
|
updateTokenById(id: string, token: any) {
|
|
264
|
-
throw Error('Not implemented')
|
|
264
|
+
throw new Error('Not implemented')
|
|
265
265
|
},
|
|
266
266
|
retrieveTokenById(id: string) {
|
|
267
|
-
throw Error('Not implemented')
|
|
267
|
+
throw new Error('Not implemented')
|
|
268
268
|
},
|
|
269
269
|
retrieveTokenByExternalId(id: string) {
|
|
270
|
-
throw Error('Not implemented')
|
|
270
|
+
throw new Error('Not implemented')
|
|
271
271
|
},
|
|
272
272
|
blockTokenById(id: string, reason: string) {
|
|
273
|
-
throw Error('Not implemented')
|
|
273
|
+
throw new Error('Not implemented')
|
|
274
274
|
},
|
|
275
275
|
unblockTokenById(id: string) {
|
|
276
|
-
throw Error('Not implemented')
|
|
276
|
+
throw new Error('Not implemented')
|
|
277
277
|
},
|
|
278
278
|
countQuery(data: any) {
|
|
279
|
-
throw Error('Not implemented')
|
|
279
|
+
throw new Error('Not implemented')
|
|
280
280
|
},
|
|
281
281
|
findQuery(data: any) {
|
|
282
|
-
throw Error('Not implemented')
|
|
282
|
+
throw new Error('Not implemented')
|
|
283
283
|
},
|
|
284
284
|
removeTokenById(id: string) {
|
|
285
|
-
throw Error('Not implemented')
|
|
285
|
+
throw new Error('Not implemented')
|
|
286
286
|
}
|
|
287
287
|
} as TokenManagement,
|
|
288
|
+
dataBaseManager: {
|
|
289
|
+
isImplemented() {
|
|
290
|
+
return true
|
|
291
|
+
},
|
|
292
|
+
synchronizeSchemas() {
|
|
293
|
+
throw new Error('Not implemented')
|
|
294
|
+
}
|
|
295
|
+
} as DataBaseManagement,
|
|
288
296
|
...decorators
|
|
289
297
|
}
|
|
290
298
|
|
|
@@ -339,6 +347,7 @@ export {
|
|
|
339
347
|
* - `import server from '@volcanicminds/backend'`
|
|
340
348
|
* - `import server, { TSC_definition } from '@volcanicminds/backend'`
|
|
341
349
|
*/
|
|
342
|
-
|
|
343
|
-
module.exports
|
|
344
|
-
module.exports.
|
|
350
|
+
export { yn, start, TranslatedError }
|
|
351
|
+
module.exports = { yn, start, TranslatedError }
|
|
352
|
+
module.exports.server = { yn, start, TranslatedError }
|
|
353
|
+
module.exports.default = { yn, start, TranslatedError }
|