@thzero/library_server 0.15.9 → 0.15.17

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 (66) hide show
  1. package/README.md +89 -89
  2. package/boot/index.js +387 -384
  3. package/boot/koa/index.js +157 -157
  4. package/boot/plugins/admin/index.js +6 -6
  5. package/boot/plugins/admin/news.js +35 -35
  6. package/boot/plugins/admin/users.js +35 -35
  7. package/boot/plugins/api.js +58 -58
  8. package/boot/plugins/apiFront.js +31 -31
  9. package/boot/plugins/index.js +71 -71
  10. package/boot/plugins/news.js +46 -46
  11. package/boot/plugins/users.js +48 -48
  12. package/boot/plugins/usersExtended.js +32 -32
  13. package/constants.js +45 -45
  14. package/data/baseNews.js +42 -42
  15. package/data/baseSettingsUser.js +9 -9
  16. package/data/baseUser.js +28 -28
  17. package/data/index.js +24 -24
  18. package/data/named.js +20 -20
  19. package/errors/tokenExpired.js +7 -7
  20. package/license.md +8 -8
  21. package/middleware/authentication.js +67 -67
  22. package/middleware/authorization.js +180 -180
  23. package/package.json +50 -60
  24. package/repository/index.js +151 -151
  25. package/repository/usageMetrics/devnull.js +11 -11
  26. package/routes/admin/index.js +111 -111
  27. package/routes/admin/news.js +14 -14
  28. package/routes/admin/users.js +18 -18
  29. package/routes/baseNews.js +27 -27
  30. package/routes/baseUsers.js +106 -106
  31. package/routes/home.js +16 -16
  32. package/routes/index.js +31 -31
  33. package/routes/news.js +6 -6
  34. package/routes/plans.js +24 -24
  35. package/routes/users.js +6 -6
  36. package/routes/utility.js +34 -34
  37. package/routes/version.js +24 -24
  38. package/service/admin/baseNews.js +45 -45
  39. package/service/admin/index.js +130 -130
  40. package/service/admin/news.js +6 -6
  41. package/service/admin/users.js +107 -107
  42. package/service/baseSecurity.js +44 -44
  43. package/service/baseUser.js +122 -122
  44. package/service/communication.js +6 -6
  45. package/service/config.js +32 -32
  46. package/service/crypto.js +16 -16
  47. package/service/discovery/index.js +6 -6
  48. package/service/discovery/resources/index.js +101 -101
  49. package/service/external.js +19 -19
  50. package/service/externalRest.js +19 -19
  51. package/service/index.js +20 -20
  52. package/service/monitoring.js +13 -0
  53. package/service/news/base.js +49 -49
  54. package/service/news/index.js +6 -6
  55. package/service/news/validation/index.js +6 -6
  56. package/service/plans.js +27 -27
  57. package/service/restCommunication.js +21 -21
  58. package/service/usageMetrics.js +63 -63
  59. package/service/utility.js +37 -37
  60. package/service/version.js +32 -32
  61. package/utility/injector.js +59 -59
  62. package/utility/internalIp/index.js +48 -48
  63. package/utility/list/doubleLinked.js +88 -88
  64. package/utility/list/priorityQueue.js +109 -109
  65. package/utility/list/queue.js +72 -72
  66. package/utility/os.js +22 -22
@@ -1,14 +1,14 @@
1
- import LibraryConstants from '../../constants';
2
-
3
- import AdminRoute from './index'
4
-
5
- class NewsAdminRoute extends AdminRoute {
6
- constructor(urlFragment, role, serviceKey) {
7
- urlFragment = urlFragment ? urlFragment : 'news';
8
- role = role ? role : 'news';
9
- serviceKey = serviceKey ? serviceKey : LibraryConstants.InjectorKeys.SERVICE_ADMIN_NEWS;
10
- super(urlFragment, role, serviceKey);
11
- }
12
- }
13
-
14
- export default NewsAdminRoute;
1
+ import LibraryConstants from '../../constants';
2
+
3
+ import AdminRoute from './index'
4
+
5
+ class NewsAdminRoute extends AdminRoute {
6
+ constructor(urlFragment, role, serviceKey) {
7
+ urlFragment = urlFragment ? urlFragment : 'news';
8
+ role = role ? role : 'news';
9
+ serviceKey = serviceKey ? serviceKey : LibraryConstants.InjectorKeys.SERVICE_ADMIN_NEWS;
10
+ super(urlFragment, role, serviceKey);
11
+ }
12
+ }
13
+
14
+ export default NewsAdminRoute;
@@ -1,18 +1,18 @@
1
- import LibraryConstants from '../../constants';
2
-
3
- import AdminRoute from './index'
4
-
5
- class UsersAdminRoute extends AdminRoute {
6
- constructor(urlFragment, role, serviceKey) {
7
- urlFragment = urlFragment ? urlFragment : 'users';
8
- role = role ? role : 'users';
9
- serviceKey = serviceKey ? serviceKey : LibraryConstants.InjectorKeys.SERVICE_ADMIN_USERS;
10
- super(urlFragment, role, serviceKey);
11
- }
12
-
13
- _allowsCreate() {
14
- return false;
15
- }
16
- }
17
-
18
- export default UsersAdminRoute;
1
+ import LibraryConstants from '../../constants';
2
+
3
+ import AdminRoute from './index'
4
+
5
+ class UsersAdminRoute extends AdminRoute {
6
+ constructor(urlFragment, role, serviceKey) {
7
+ urlFragment = urlFragment ? urlFragment : 'users';
8
+ role = role ? role : 'users';
9
+ serviceKey = serviceKey ? serviceKey : LibraryConstants.InjectorKeys.SERVICE_ADMIN_USERS;
10
+ super(urlFragment, role, serviceKey);
11
+ }
12
+
13
+ _allowsCreate() {
14
+ return false;
15
+ }
16
+ }
17
+
18
+ export default UsersAdminRoute;
@@ -1,27 +1,27 @@
1
- import LibraryConstants from '../constants';
2
-
3
- import Utility from '@thzero/library_common/utility';
4
-
5
- import BaseRoute from './index';
6
-
7
- import authentication from '../middleware/authentication';
8
-
9
- class BaseNewsRoute extends BaseRoute {
10
- constructor(prefix) {
11
- super(prefix ? prefix : '/api/news');
12
- }
13
-
14
- _initializeRoutes(router) {
15
- router.get('/latest/:date',
16
- authentication(false),
17
- // eslint-disable-next-line
18
- async (ctx, next) => {
19
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
20
- const response = (await service.latest(ctx.correlationId, ctx.state.user, parseInt(ctx.params.date))).check(ctx);
21
- ctx.body = Utility.stringify(response);
22
- }
23
- );
24
- }
25
- }
26
-
27
- export default BaseNewsRoute;
1
+ import LibraryConstants from '../constants';
2
+
3
+ import Utility from '@thzero/library_common/utility';
4
+
5
+ import BaseRoute from './index';
6
+
7
+ import authentication from '../middleware/authentication';
8
+
9
+ class BaseNewsRoute extends BaseRoute {
10
+ constructor(prefix) {
11
+ super(prefix ? prefix : '/api/news');
12
+ }
13
+
14
+ _initializeRoutes(router) {
15
+ router.get('/latest/:date',
16
+ authentication(false),
17
+ // eslint-disable-next-line
18
+ async (ctx, next) => {
19
+ const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
20
+ const response = (await service.latest(ctx.correlationId, ctx.state.user, parseInt(ctx.params.date))).check(ctx);
21
+ ctx.body = Utility.stringify(response);
22
+ }
23
+ );
24
+ }
25
+ }
26
+
27
+ export default BaseNewsRoute;
@@ -1,106 +1,106 @@
1
- import koaBody from 'koa-body';
2
-
3
- import LibraryConstants from '../constants';
4
-
5
- import Utility from '@thzero/library_common/utility';
6
-
7
- import BaseRoute from './index';
8
-
9
- import authentication from '../middleware/authentication';
10
- import authorization from '../middleware/authorization';
11
-
12
- class BaseUsersRoute extends BaseRoute {
13
- constructor(prefix) {
14
- super(prefix ? prefix : '/api/users');
15
- }
16
-
17
- _initializeRoutes(router) {
18
- this._initializeRoutesGamerById(router);
19
- this._initializeRoutesGamerByTag(router);
20
- this._initializeRoutesRefreshSettings(router);
21
- this._initializeRoutesUpdate(router);
22
- this._initializeRoutesUpdateSettings(router);
23
- }
24
-
25
- _initializeRoutesGamerById(router) {
26
- return router.get('/gamerId/:gamerId',
27
- authentication(false),
28
- // authorization('user'),
29
- koaBody({
30
- text: false,
31
- }),
32
- // eslint-disable-next-line
33
- async (ctx, next) => {
34
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
35
- const response = (await service.fetchByGamerId(ctx.correlationId, ctx.params.gamerId)).check(ctx);
36
- ctx.body = Utility.stringify(response);
37
- }
38
- );
39
- }
40
-
41
- _initializeRoutesGamerByTag(router) {
42
- return router.get('/gamerTag/:gamerTag',
43
- authentication(false),
44
- // authorization('user'),
45
- koaBody({
46
- text: false,
47
- }),
48
- // eslint-disable-next-line
49
- async (ctx, next) => {
50
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
51
- const response = (await service.fetchByGamerTag(ctx.correlationId, ctx.params.gamerTag)).check(ctx);
52
- ctx.body = Utility.stringify(response);
53
- }
54
- );
55
- }
56
-
57
- _initializeRoutesRefreshSettings(router) {
58
- return router.post('/refresh/settings',
59
- authentication(true),
60
- authorization('user'),
61
- koaBody({
62
- text: false,
63
- }),
64
- // eslint-disable-next-line
65
- async (ctx, next) => {
66
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
67
- const response = (await service.refreshSettings(ctx.correlationId, ctx.request.body)).check(ctx);
68
- ctx.body = Utility.stringify(response);
69
- }
70
- );
71
- }
72
-
73
- _initializeRoutesUpdate(router) {
74
- return router.post('/update',
75
- authentication(true),
76
- authorization('user'),
77
- koaBody({
78
- text: false,
79
- }),
80
- // eslint-disable-next-line
81
- async (ctx, next) => {
82
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
83
- const response = (await service.update(ctx.correlationId, ctx.request.body)).check(ctx);
84
- ctx.body = Utility.stringify(response);
85
- }
86
- );
87
- }
88
-
89
- _initializeRoutesUpdateSettings(router) {
90
- return router.post('/update/settings',
91
- authentication(true),
92
- authorization('user'),
93
- koaBody({
94
- text: false,
95
- }),
96
- // eslint-disable-next-line
97
- async (ctx, next) => {
98
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
99
- const response = (await service.updateSettings(ctx.correlationId, ctx.request.body)).check(ctx);
100
- ctx.body = Utility.stringify(response);
101
- }
102
- );
103
- }
104
- }
105
-
106
- export default BaseUsersRoute;
1
+ import koaBody from 'koa-body';
2
+
3
+ import LibraryConstants from '../constants';
4
+
5
+ import Utility from '@thzero/library_common/utility';
6
+
7
+ import BaseRoute from './index';
8
+
9
+ import authentication from '../middleware/authentication';
10
+ import authorization from '../middleware/authorization';
11
+
12
+ class BaseUsersRoute extends BaseRoute {
13
+ constructor(prefix) {
14
+ super(prefix ? prefix : '/api/users');
15
+ }
16
+
17
+ _initializeRoutes(router) {
18
+ this._initializeRoutesGamerById(router);
19
+ this._initializeRoutesGamerByTag(router);
20
+ this._initializeRoutesRefreshSettings(router);
21
+ this._initializeRoutesUpdate(router);
22
+ this._initializeRoutesUpdateSettings(router);
23
+ }
24
+
25
+ _initializeRoutesGamerById(router) {
26
+ return router.get('/gamerId/:gamerId',
27
+ authentication(false),
28
+ // authorization('user'),
29
+ koaBody({
30
+ text: false,
31
+ }),
32
+ // eslint-disable-next-line
33
+ async (ctx, next) => {
34
+ const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
35
+ const response = (await service.fetchByGamerId(ctx.correlationId, ctx.params.gamerId)).check(ctx);
36
+ ctx.body = Utility.stringify(response);
37
+ }
38
+ );
39
+ }
40
+
41
+ _initializeRoutesGamerByTag(router) {
42
+ return router.get('/gamerTag/:gamerTag',
43
+ authentication(false),
44
+ // authorization('user'),
45
+ koaBody({
46
+ text: false,
47
+ }),
48
+ // eslint-disable-next-line
49
+ async (ctx, next) => {
50
+ const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
51
+ const response = (await service.fetchByGamerTag(ctx.correlationId, ctx.params.gamerTag)).check(ctx);
52
+ ctx.body = Utility.stringify(response);
53
+ }
54
+ );
55
+ }
56
+
57
+ _initializeRoutesRefreshSettings(router) {
58
+ return router.post('/refresh/settings',
59
+ authentication(true),
60
+ authorization('user'),
61
+ koaBody({
62
+ text: false,
63
+ }),
64
+ // eslint-disable-next-line
65
+ async (ctx, next) => {
66
+ const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
67
+ const response = (await service.refreshSettings(ctx.correlationId, ctx.request.body)).check(ctx);
68
+ ctx.body = Utility.stringify(response);
69
+ }
70
+ );
71
+ }
72
+
73
+ _initializeRoutesUpdate(router) {
74
+ return router.post('/update',
75
+ authentication(true),
76
+ authorization('user'),
77
+ koaBody({
78
+ text: false,
79
+ }),
80
+ // eslint-disable-next-line
81
+ async (ctx, next) => {
82
+ const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
83
+ const response = (await service.update(ctx.correlationId, ctx.request.body)).check(ctx);
84
+ ctx.body = Utility.stringify(response);
85
+ }
86
+ );
87
+ }
88
+
89
+ _initializeRoutesUpdateSettings(router) {
90
+ return router.post('/update/settings',
91
+ authentication(true),
92
+ authorization('user'),
93
+ koaBody({
94
+ text: false,
95
+ }),
96
+ // eslint-disable-next-line
97
+ async (ctx, next) => {
98
+ const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
99
+ const response = (await service.updateSettings(ctx.correlationId, ctx.request.body)).check(ctx);
100
+ ctx.body = Utility.stringify(response);
101
+ }
102
+ );
103
+ }
104
+ }
105
+
106
+ export default BaseUsersRoute;
package/routes/home.js CHANGED
@@ -1,16 +1,16 @@
1
- import BaseRoute from './index';
2
-
3
- class HomeRoute extends BaseRoute {
4
- constructor(prefix) {
5
- super(prefix ? prefix : '/api');
6
- }
7
-
8
- _initializeRoutes(router) {
9
- // eslint-disable-next-line
10
- router.get('/', (ctx, next) => {
11
- ctx.status = 404;
12
- });
13
- }
14
- }
15
-
16
- export default HomeRoute;
1
+ import BaseRoute from './index';
2
+
3
+ class HomeRoute extends BaseRoute {
4
+ constructor(prefix) {
5
+ super(prefix ? prefix : '/api');
6
+ }
7
+
8
+ _initializeRoutes(router) {
9
+ // eslint-disable-next-line
10
+ router.get('/', (ctx, next) => {
11
+ ctx.status = 404;
12
+ });
13
+ }
14
+ }
15
+
16
+ export default HomeRoute;
package/routes/index.js CHANGED
@@ -1,31 +1,31 @@
1
- import koaRouter from '@koa/router';
2
-
3
- class BaseRoute {
4
- constructor(prefix) {
5
- if (!prefix)
6
- throw Error('Invalid prefix');
7
-
8
- this._prefix = prefix;
9
- }
10
-
11
- get router() {
12
- return this._router;
13
- }
14
-
15
- async init(injector) {
16
- this._injector = injector;
17
-
18
- this._router = new koaRouter({
19
- prefix: this._prefix
20
- });
21
-
22
- this._initializeRoutes(this._router);
23
-
24
- return this._router;
25
- }
26
-
27
- _initializeRoutes(router) {
28
- }
29
- }
30
-
31
- export default BaseRoute;
1
+ import koaRouter from '@koa/router';
2
+
3
+ class BaseRoute {
4
+ constructor(prefix) {
5
+ if (!prefix)
6
+ throw Error('Invalid prefix');
7
+
8
+ this._prefix = prefix;
9
+ }
10
+
11
+ get router() {
12
+ return this._router;
13
+ }
14
+
15
+ async init(injector) {
16
+ this._injector = injector;
17
+
18
+ this._router = new koaRouter({
19
+ prefix: this._prefix
20
+ });
21
+
22
+ this._initializeRoutes(this._router);
23
+
24
+ return this._router;
25
+ }
26
+
27
+ _initializeRoutes(router) {
28
+ }
29
+ }
30
+
31
+ export default BaseRoute;
package/routes/news.js CHANGED
@@ -1,6 +1,6 @@
1
- import BaseNewsRoute from './baseNews';
2
-
3
- class NewsRoute extends BaseNewsRoute {
4
- }
5
-
6
- export default NewsRoute;
1
+ import BaseNewsRoute from './baseNews';
2
+
3
+ class NewsRoute extends BaseNewsRoute {
4
+ }
5
+
6
+ export default NewsRoute;
package/routes/plans.js CHANGED
@@ -1,24 +1,24 @@
1
- import LibraryConstants from '../constants';
2
-
3
- import Utility from '@thzero/library_common/utility';
4
-
5
- import BaseRoute from './index';
6
-
7
- class PlansRoute extends BaseRoute {
8
- constructor(prefix) {
9
- super(prefix ? prefix : '/api');
10
- }
11
-
12
- _initializeRoutes(router) {
13
- router.get('/plans',
14
- // eslint-disable-next-line
15
- async (ctx, next) => {
16
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_PLANS);
17
- const response = (await service.listing(ctx.correlationId)).check(ctx);
18
- ctx.body = Utility.stringify(response);
19
- }
20
- );
21
- }
22
- }
23
-
24
- export default PlansRoute;
1
+ import LibraryConstants from '../constants';
2
+
3
+ import Utility from '@thzero/library_common/utility';
4
+
5
+ import BaseRoute from './index';
6
+
7
+ class PlansRoute extends BaseRoute {
8
+ constructor(prefix) {
9
+ super(prefix ? prefix : '/api');
10
+ }
11
+
12
+ _initializeRoutes(router) {
13
+ router.get('/plans',
14
+ // eslint-disable-next-line
15
+ async (ctx, next) => {
16
+ const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_PLANS);
17
+ const response = (await service.listing(ctx.correlationId)).check(ctx);
18
+ ctx.body = Utility.stringify(response);
19
+ }
20
+ );
21
+ }
22
+ }
23
+
24
+ export default PlansRoute;
package/routes/users.js CHANGED
@@ -1,6 +1,6 @@
1
- import BaseUsersRoute from './baseUsers';
2
-
3
- class UsersRoute extends BaseUsersRoute {
4
- }
5
-
6
- export default UsersRoute;
1
+ import BaseUsersRoute from './baseUsers';
2
+
3
+ class UsersRoute extends BaseUsersRoute {
4
+ }
5
+
6
+ export default UsersRoute;
package/routes/utility.js CHANGED
@@ -1,34 +1,34 @@
1
- import koaBody from 'koa-body';
2
-
3
- import LibraryConstants from '../constants';
4
-
5
- import Utility from '@thzero/library_common/utility';
6
-
7
- import BaseRoute from './index';
8
-
9
- import authentication from '../middleware/authentication';
10
- // import authorization from '../middleware/authorization';
11
-
12
- class UtilityRoute extends BaseRoute {
13
- constructor(prefix) {
14
- super(prefix ? prefix : '/api/utility');
15
- }
16
-
17
- _initializeRoutes(router) {
18
- router.post('/logger',
19
- authentication(false),
20
- // authorization('utility'),
21
- // eslint-disable-next-line,
22
- koaBody({
23
- text: false,
24
- }),
25
- async (ctx, next) => {
26
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_UTILITY);
27
- const response = (await service.logger(ctx.correlationId, ctx.request.body)).check(ctx);
28
- ctx.body = Utility.stringify(response);
29
- }
30
- );
31
- }
32
- }
33
-
34
- export default UtilityRoute;
1
+ import koaBody from 'koa-body';
2
+
3
+ import LibraryConstants from '../constants';
4
+
5
+ import Utility from '@thzero/library_common/utility';
6
+
7
+ import BaseRoute from './index';
8
+
9
+ import authentication from '../middleware/authentication';
10
+ // import authorization from '../middleware/authorization';
11
+
12
+ class UtilityRoute extends BaseRoute {
13
+ constructor(prefix) {
14
+ super(prefix ? prefix : '/api/utility');
15
+ }
16
+
17
+ _initializeRoutes(router) {
18
+ router.post('/logger',
19
+ authentication(false),
20
+ // authorization('utility'),
21
+ // eslint-disable-next-line,
22
+ koaBody({
23
+ text: false,
24
+ }),
25
+ async (ctx, next) => {
26
+ const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_UTILITY);
27
+ const response = (await service.logger(ctx.correlationId, ctx.request.body)).check(ctx);
28
+ ctx.body = Utility.stringify(response);
29
+ }
30
+ );
31
+ }
32
+ }
33
+
34
+ export default UtilityRoute;
package/routes/version.js CHANGED
@@ -1,24 +1,24 @@
1
- import LibraryConstants from '../constants';
2
-
3
- import Utility from '@thzero/library_common/utility';
4
-
5
- import BaseRoute from './index';
6
-
7
- class VersionRoute extends BaseRoute {
8
- constructor(prefix) {
9
- super(prefix ? prefix : '/api');
10
- }
11
-
12
- _initializeRoutes(router) {
13
- router.get('/version',
14
- // eslint-disable-next-line
15
- async (ctx, next) => {
16
- const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_VERSION);
17
- const response = (await service.version(ctx.correlationId)).check(ctx);
18
- ctx.body = Utility.stringify(response);
19
- }
20
- );
21
- }
22
- }
23
-
24
- export default VersionRoute;
1
+ import LibraryConstants from '../constants';
2
+
3
+ import Utility from '@thzero/library_common/utility';
4
+
5
+ import BaseRoute from './index';
6
+
7
+ class VersionRoute extends BaseRoute {
8
+ constructor(prefix) {
9
+ super(prefix ? prefix : '/api');
10
+ }
11
+
12
+ _initializeRoutes(router) {
13
+ router.get('/version',
14
+ // eslint-disable-next-line
15
+ async (ctx, next) => {
16
+ const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_VERSION);
17
+ const response = (await service.version(ctx.correlationId)).check(ctx);
18
+ ctx.body = Utility.stringify(response);
19
+ }
20
+ );
21
+ }
22
+ }
23
+
24
+ export default VersionRoute;