@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,71 +1,71 @@
1
- class BootPlugin {
2
- async init(config, injector) {
3
- this._config = config;
4
- this._injector = injector;
5
-
6
- }
7
-
8
- async initRoutes(routes) {
9
- this._routes = routes;
10
-
11
- await this._initRoutesPre();
12
-
13
- await this._initRoutes();
14
-
15
- await this._initRoutesPost();
16
- }
17
-
18
- async initRepositories(repositories) {
19
- this._repositories = repositories;
20
-
21
- await this._initRepositories();
22
- }
23
-
24
- async initServices(services) {
25
- this._services = services;
26
-
27
- await this._initServices();
28
- }
29
-
30
- async initServicesSecondary(services) {
31
- this._services = services;
32
-
33
- await this._initServicesSecondary();
34
- }
35
-
36
- _initRoute(route) {
37
- this._routes.push(route);
38
- }
39
-
40
- async _initRoutes() {
41
- }
42
-
43
- async _initRoutesPost() {
44
- }
45
-
46
- async _initRoutesPre() {
47
- }
48
-
49
- async _initRepositories() {
50
- }
51
-
52
- _injectRepository(key, repository) {
53
- console.log(`repositories.inject - ${key}`);
54
- this._repositories.set(key, repository);
55
- this._injector.addSingleton(key, repository);
56
- }
57
-
58
- _injectService(key, service) {
59
- console.log(`services.inject - ${key}`);
60
- this._services.set(key, service);
61
- this._injector.addSingleton(key, service);
62
- }
63
-
64
- async _initServices() {
65
- }
66
-
67
- async _initServicesSecondary() {
68
- }
69
- }
70
-
71
- export default BootPlugin;
1
+ class BootPlugin {
2
+ async init(config, injector) {
3
+ this._config = config;
4
+ this._injector = injector;
5
+
6
+ }
7
+
8
+ async initRoutes(routes) {
9
+ this._routes = routes;
10
+
11
+ await this._initRoutesPre();
12
+
13
+ await this._initRoutes();
14
+
15
+ await this._initRoutesPost();
16
+ }
17
+
18
+ async initRepositories(repositories) {
19
+ this._repositories = repositories;
20
+
21
+ await this._initRepositories();
22
+ }
23
+
24
+ async initServices(services) {
25
+ this._services = services;
26
+
27
+ await this._initServices();
28
+ }
29
+
30
+ async initServicesSecondary(services) {
31
+ this._services = services;
32
+
33
+ await this._initServicesSecondary();
34
+ }
35
+
36
+ _initRoute(route) {
37
+ this._routes.push(route);
38
+ }
39
+
40
+ async _initRoutes() {
41
+ }
42
+
43
+ async _initRoutesPost() {
44
+ }
45
+
46
+ async _initRoutesPre() {
47
+ }
48
+
49
+ async _initRepositories() {
50
+ }
51
+
52
+ _injectRepository(key, repository) {
53
+ console.log(`repositories.inject - ${key}`);
54
+ this._repositories.set(key, repository);
55
+ this._injector.addSingleton(key, repository);
56
+ }
57
+
58
+ _injectService(key, service) {
59
+ console.log(`services.inject - ${key}`);
60
+ this._services.set(key, service);
61
+ this._injector.addSingleton(key, service);
62
+ }
63
+
64
+ async _initServices() {
65
+ }
66
+
67
+ async _initServicesSecondary() {
68
+ }
69
+ }
70
+
71
+ export default BootPlugin;
@@ -1,46 +1,46 @@
1
- import LibraryConstants from '../../constants';
2
-
3
- import NotImplementedError from '@thzero/library_common/errors/notImplemented';
4
-
5
- import BootPlugin from './index';
6
-
7
- import newsRoute from '../../routes/news';
8
-
9
- class NewsApiBootPlugin extends BootPlugin {
10
- async _initRoutes() {
11
- await super._initRoutes();
12
-
13
- this._initRoute(this._initRoutesNews());
14
- }
15
-
16
- async _initRepositories() {
17
- await super._initRepositories();
18
-
19
- this._injectRepository(LibraryConstants.InjectorKeys.REPOSITORY_NEWS, this._initRepositoriesNews());
20
- }
21
-
22
- async _initServices() {
23
- await super._initServices();
24
-
25
- this._injectService(LibraryConstants.InjectorKeys.SERVICE_NEWS, this._initServicesNews());
26
- this._injectService(LibraryConstants.InjectorKeys.SERVICE_VALIDATION_NEWS, this._initServicesNewsValidation());
27
- }
28
-
29
- _initRepositoriesNews() {
30
- throw new NotImplementedError();
31
- }
32
-
33
- _initRoutesNews() {
34
- return new newsRoute();
35
- }
36
-
37
- _initServicesNews() {
38
- throw new NotImplementedError();
39
- }
40
-
41
- _initServicesNewsValidation() {
42
- throw new NotImplementedError();
43
- }
44
- }
45
-
46
- export default NewsApiBootPlugin;
1
+ import LibraryConstants from '../../constants';
2
+
3
+ import NotImplementedError from '@thzero/library_common/errors/notImplemented';
4
+
5
+ import BootPlugin from './index';
6
+
7
+ import newsRoute from '../../routes/news';
8
+
9
+ class NewsApiBootPlugin extends BootPlugin {
10
+ async _initRoutes() {
11
+ await super._initRoutes();
12
+
13
+ this._initRoute(this._initRoutesNews());
14
+ }
15
+
16
+ async _initRepositories() {
17
+ await super._initRepositories();
18
+
19
+ this._injectRepository(LibraryConstants.InjectorKeys.REPOSITORY_NEWS, this._initRepositoriesNews());
20
+ }
21
+
22
+ async _initServices() {
23
+ await super._initServices();
24
+
25
+ this._injectService(LibraryConstants.InjectorKeys.SERVICE_NEWS, this._initServicesNews());
26
+ this._injectService(LibraryConstants.InjectorKeys.SERVICE_VALIDATION_NEWS, this._initServicesNewsValidation());
27
+ }
28
+
29
+ _initRepositoriesNews() {
30
+ throw new NotImplementedError();
31
+ }
32
+
33
+ _initRoutesNews() {
34
+ return new newsRoute();
35
+ }
36
+
37
+ _initServicesNews() {
38
+ throw new NotImplementedError();
39
+ }
40
+
41
+ _initServicesNewsValidation() {
42
+ throw new NotImplementedError();
43
+ }
44
+ }
45
+
46
+ export default NewsApiBootPlugin;
@@ -1,48 +1,48 @@
1
- import LibraryConstants from '../../constants';
2
-
3
- import NotImplementedError from '@thzero/library_common/errors/notImplemented';
4
-
5
- import BootPlugin from './index';
6
-
7
- import usersRoute from '../../routes/users';
8
-
9
- class UsersApiBootPlugin extends BootPlugin {
10
- async _initRoutes() {
11
- await super._initRoutes();
12
-
13
- const usersRoute = this._initRoutesUsers();
14
- if (usersRoute)
15
- this._initRoute(usersRoute);
16
- }
17
-
18
- async _initRepositories() {
19
- await super._initRepositories();
20
-
21
- this._injectRepository(LibraryConstants.InjectorKeys.REPOSITORY_USERS, this._initRepositoriesUsers());
22
- }
23
-
24
- async _initServices() {
25
- await super._initServices();
26
-
27
- this._injectService(LibraryConstants.InjectorKeys.SERVICE_AUTH, this._initServicesAuth());
28
- this._injectService(LibraryConstants.InjectorKeys.SERVICE_USERS, this._initServicesUser());
29
- }
30
-
31
- _initRepositoriesUsers() {
32
- throw new NotImplementedError();
33
- }
34
-
35
- _initRoutesUsers() {
36
- return new usersRoute();
37
- }
38
-
39
- _initServicesAuth() {
40
- throw new NotImplementedError();
41
- }
42
-
43
- _initServicesUser() {
44
- throw new NotImplementedError();
45
- }
46
- }
47
-
48
- export default UsersApiBootPlugin;
1
+ import LibraryConstants from '../../constants';
2
+
3
+ import NotImplementedError from '@thzero/library_common/errors/notImplemented';
4
+
5
+ import BootPlugin from './index';
6
+
7
+ import usersRoute from '../../routes/users';
8
+
9
+ class UsersApiBootPlugin extends BootPlugin {
10
+ async _initRoutes() {
11
+ await super._initRoutes();
12
+
13
+ const usersRoute = this._initRoutesUsers();
14
+ if (usersRoute)
15
+ this._initRoute(usersRoute);
16
+ }
17
+
18
+ async _initRepositories() {
19
+ await super._initRepositories();
20
+
21
+ this._injectRepository(LibraryConstants.InjectorKeys.REPOSITORY_USERS, this._initRepositoriesUsers());
22
+ }
23
+
24
+ async _initServices() {
25
+ await super._initServices();
26
+
27
+ this._injectService(LibraryConstants.InjectorKeys.SERVICE_AUTH, this._initServicesAuth());
28
+ this._injectService(LibraryConstants.InjectorKeys.SERVICE_USERS, this._initServicesUser());
29
+ }
30
+
31
+ _initRepositoriesUsers() {
32
+ throw new NotImplementedError();
33
+ }
34
+
35
+ _initRoutesUsers() {
36
+ return new usersRoute();
37
+ }
38
+
39
+ _initServicesAuth() {
40
+ throw new NotImplementedError();
41
+ }
42
+
43
+ _initServicesUser() {
44
+ throw new NotImplementedError();
45
+ }
46
+ }
47
+
48
+ export default UsersApiBootPlugin;
@@ -1,32 +1,32 @@
1
- import LibraryConstants from '../../constants';
2
-
3
- import NotImplementedError from '@thzero/library_common/errors/notImplemented';
4
-
5
- import UsersApiBootPlugin from './users';
6
-
7
- import plansService from '../../service/plans';
8
-
9
- class ExtendedUsersApiBootPlugin extends UsersApiBootPlugin {
10
- async _initRepositories() {
11
- await super._initRepositories();
12
-
13
- this._injectRepository(LibraryConstants.InjectorKeys.REPOSITORY_PLANS, this._initRepositoriesPlans());
14
- }
15
-
16
- async _initServices() {
17
- await super._initServices();
18
-
19
- this._injectService(LibraryConstants.InjectorKeys.SERVICE_PLANS, this._initServicesPlans());
20
- this._injectService(LibraryConstants.InjectorKeys.SERVICE_SECURITY, this._initServicesSecurity());
21
- }
22
-
23
- _initRepositoriesPlans() {
24
- throw new NotImplementedError();
25
- }
26
-
27
- _initServicesPlans() {
28
- return new plansService();
29
- }
30
- }
31
-
32
- export default ExtendedUsersApiBootPlugin;
1
+ import LibraryConstants from '../../constants';
2
+
3
+ import NotImplementedError from '@thzero/library_common/errors/notImplemented';
4
+
5
+ import UsersApiBootPlugin from './users';
6
+
7
+ import plansService from '../../service/plans';
8
+
9
+ class ExtendedUsersApiBootPlugin extends UsersApiBootPlugin {
10
+ async _initRepositories() {
11
+ await super._initRepositories();
12
+
13
+ this._injectRepository(LibraryConstants.InjectorKeys.REPOSITORY_PLANS, this._initRepositoriesPlans());
14
+ }
15
+
16
+ async _initServices() {
17
+ await super._initServices();
18
+
19
+ this._injectService(LibraryConstants.InjectorKeys.SERVICE_PLANS, this._initServicesPlans());
20
+ this._injectService(LibraryConstants.InjectorKeys.SERVICE_SECURITY, this._initServicesSecurity());
21
+ }
22
+
23
+ _initRepositoriesPlans() {
24
+ throw new NotImplementedError();
25
+ }
26
+
27
+ _initServicesPlans() {
28
+ return new plansService();
29
+ }
30
+ }
31
+
32
+ export default ExtendedUsersApiBootPlugin;
package/constants.js CHANGED
@@ -1,45 +1,45 @@
1
- const LibraryConstants = {
2
- InjectorKeys: {
3
- REPOSITORY_ADMIN_NEWS: 'repositoryAdminNews',
4
- REPOSITORY_ADMIN_USERS: 'repositoryAdminUsers',
5
- REPOSITORY_NEWS: 'repositoryNews',
6
- REPOSITORY_PLANS: 'repositoryPlans',
7
- REPOSITORY_USAGE_METRIC: 'repositoryUsageMetrics',
8
- REPOSITORY_USERS: 'repositoryUsers',
9
- SERVICE_ADMIN_NEWS: 'serviceAdminNews',
10
- SERVICE_ADMIN_USERS: 'serviceAdminUsers',
11
- SERVICE_AUTH: 'serviceAuth',
12
- SERVICE_COMMUNICATION_REST: 'serviceCommunicationRest',
13
- SERVICE_CRYPTO: 'serviceCrypto',
14
- SERVICE_DISCOVERY_MDNS: 'serviceMdns',
15
- SERVICE_DISCOVERY_RESOURCES: 'serviceDiscoveryResources',
16
- SERVICE_NEWS: 'serviceNews',
17
- SERVICE_PLANS: 'servicePlans',
18
- SERVICE_SECURITY: 'serviceSecurity',
19
- SERVICE_USAGE_METRIC: 'serviceUsageMetric',
20
- SERVICE_USERS: 'serviceUser',
21
- SERVICE_UTILITY: 'serviceUtility',
22
- SERVICE_VALIDATION_NEWS: 'serviceNewsValidation',
23
- SERVICE_VERSION: 'serviceVersion'
24
- },
25
- HealthCheck: {
26
- DefaultPath: '/healthcheck'
27
- },
28
- Headers: {
29
- AuthKeys: {
30
- API: 'x-api-key',
31
- AUTH: 'authorization',
32
- AUTH_BEARER: 'bearer'
33
- },
34
- CorrelationId: 'correlation-id'
35
- },
36
- NewsStatus: {
37
- ACTIVE: 'active',
38
- DISABLED: 'disabled'
39
- },
40
- NewsTypes: {
41
- MAIN: 'main'
42
- }
43
- }
44
-
45
- export default LibraryConstants;
1
+ const LibraryConstants = {
2
+ InjectorKeys: {
3
+ REPOSITORY_ADMIN_NEWS: 'repositoryAdminNews',
4
+ REPOSITORY_ADMIN_USERS: 'repositoryAdminUsers',
5
+ REPOSITORY_NEWS: 'repositoryNews',
6
+ REPOSITORY_PLANS: 'repositoryPlans',
7
+ REPOSITORY_USAGE_METRIC: 'repositoryUsageMetrics',
8
+ REPOSITORY_USERS: 'repositoryUsers',
9
+ SERVICE_ADMIN_NEWS: 'serviceAdminNews',
10
+ SERVICE_ADMIN_USERS: 'serviceAdminUsers',
11
+ SERVICE_AUTH: 'serviceAuth',
12
+ SERVICE_COMMUNICATION_REST: 'serviceCommunicationRest',
13
+ SERVICE_CRYPTO: 'serviceCrypto',
14
+ SERVICE_DISCOVERY_MDNS: 'serviceMdns',
15
+ SERVICE_DISCOVERY_RESOURCES: 'serviceDiscoveryResources',
16
+ SERVICE_NEWS: 'serviceNews',
17
+ SERVICE_PLANS: 'servicePlans',
18
+ SERVICE_SECURITY: 'serviceSecurity',
19
+ SERVICE_USAGE_METRIC: 'serviceUsageMetric',
20
+ SERVICE_USERS: 'serviceUser',
21
+ SERVICE_UTILITY: 'serviceUtility',
22
+ SERVICE_VALIDATION_NEWS: 'serviceNewsValidation',
23
+ SERVICE_VERSION: 'serviceVersion'
24
+ },
25
+ HealthCheck: {
26
+ DefaultPath: '/healthcheck'
27
+ },
28
+ Headers: {
29
+ AuthKeys: {
30
+ API: 'x-api-key',
31
+ AUTH: 'authorization',
32
+ AUTH_BEARER: 'bearer'
33
+ },
34
+ CorrelationId: 'correlation-id'
35
+ },
36
+ NewsStatus: {
37
+ ACTIVE: 'active',
38
+ DISABLED: 'disabled'
39
+ },
40
+ NewsTypes: {
41
+ MAIN: 'main'
42
+ }
43
+ }
44
+
45
+ export default LibraryConstants;
package/data/baseNews.js CHANGED
@@ -1,42 +1,42 @@
1
- import Data from './index';
2
-
3
- import NotImplementedError from '@thzero/library_common/errors/notImplemented';
4
-
5
- class BaseNewsData extends Data {
6
- constructor() {
7
- super();
8
-
9
- this.article = '';
10
- this.gameSystemId = null;
11
- this.requiresAuth = false;
12
- this.status = this._defaultStatus();
13
- this.sticky = false;
14
- this.timestamp = null;
15
- this.title = '';
16
- this.type = this._defaultType();
17
- }
18
-
19
- map(requested) {
20
- if (!requested)
21
- return;
22
-
23
- this.article = requested.article;
24
- this.gameSystemId = requested.gameSystemId;
25
- this.requiresAuth = requested.requiresAuth;
26
- this.status = requested.status;
27
- this.sticky = false;
28
- this.timestamp = requested.timestamp;
29
- this.title = requested.title;
30
- this.type = requested.type;
31
- }
32
-
33
- _defaultStatus() {
34
- throw new NotImplementedError();
35
- }
36
-
37
- _defaultType() {
38
- throw new NotImplementedError();
39
- }
40
- }
41
-
42
- export default BaseNewsData;
1
+ import Data from './index';
2
+
3
+ import NotImplementedError from '@thzero/library_common/errors/notImplemented';
4
+
5
+ class BaseNewsData extends Data {
6
+ constructor() {
7
+ super();
8
+
9
+ this.article = '';
10
+ this.gameSystemId = null;
11
+ this.requiresAuth = false;
12
+ this.status = this._defaultStatus();
13
+ this.sticky = false;
14
+ this.timestamp = null;
15
+ this.title = '';
16
+ this.type = this._defaultType();
17
+ }
18
+
19
+ map(requested) {
20
+ if (!requested)
21
+ return;
22
+
23
+ this.article = requested.article;
24
+ this.gameSystemId = requested.gameSystemId;
25
+ this.requiresAuth = requested.requiresAuth;
26
+ this.status = requested.status;
27
+ this.sticky = false;
28
+ this.timestamp = requested.timestamp;
29
+ this.title = requested.title;
30
+ this.type = requested.type;
31
+ }
32
+
33
+ _defaultStatus() {
34
+ throw new NotImplementedError();
35
+ }
36
+
37
+ _defaultType() {
38
+ throw new NotImplementedError();
39
+ }
40
+ }
41
+
42
+ export default BaseNewsData;
@@ -1,9 +1,9 @@
1
- class BaseSettings {
2
- constructor() {
3
- this.gamerTag = null;
4
- this.gamerTagSearch = null;
5
- this.home = {};
6
- }
7
- }
8
-
9
- export default BaseSettings;
1
+ class BaseSettings {
2
+ constructor() {
3
+ this.gamerTag = null;
4
+ this.gamerTagSearch = null;
5
+ this.home = {};
6
+ }
7
+ }
8
+
9
+ export default BaseSettings;
package/data/baseUser.js CHANGED
@@ -1,28 +1,28 @@
1
- import Data from './index';
2
-
3
- import NotImplementedError from '@thzero/library_common/errors/notImplemented';
4
-
5
- class BaseUserData extends Data {
6
- constructor() {
7
- super();
8
-
9
- this.planId = null;
10
- this.roles = [];
11
- this.settings = this._initUserSettings();
12
- this.user = null;
13
- }
14
-
15
- map(requested) {
16
- if (!requested)
17
- return;
18
-
19
- this.planId = requested.planId;
20
- this.roles = requested.roles;
21
- }
22
-
23
- _initUserSettings() {
24
- throw new NotImplementedError();
25
- }
26
- }
27
-
28
- export default BaseUserData;
1
+ import Data from './index';
2
+
3
+ import NotImplementedError from '@thzero/library_common/errors/notImplemented';
4
+
5
+ class BaseUserData extends Data {
6
+ constructor() {
7
+ super();
8
+
9
+ this.planId = null;
10
+ this.roles = [];
11
+ this.settings = this._initUserSettings();
12
+ this.user = null;
13
+ }
14
+
15
+ map(requested) {
16
+ if (!requested)
17
+ return;
18
+
19
+ this.planId = requested.planId;
20
+ this.roles = requested.roles;
21
+ }
22
+
23
+ _initUserSettings() {
24
+ throw new NotImplementedError();
25
+ }
26
+ }
27
+
28
+ export default BaseUserData;