@thzero/library_server_fastify 0.16.9 → 0.16.10

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.
@@ -1,148 +1,148 @@
1
- import LibraryConstants from '@thzero/library_server/constants.js';
2
-
3
- import BaseRoute from './index.js';
4
-
5
- class BaseUsersRoute extends BaseRoute {
6
- constructor(prefix, version) {
7
- super(prefix ? prefix : '/users');
8
-
9
- // this._serviceUsers = null;
10
- }
11
-
12
- async init(injector, app, config) {
13
- await super.init(injector, app, config);
14
- // this._serviceUsers = injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
15
- this._inject(app, injector, LibraryConstants.InjectorKeys.SERVICE_USERS, LibraryConstants.InjectorKeys.SERVICE_USERS);
16
- }
17
-
18
- get id() {
19
- return 'users';
20
- }
21
-
22
- _initializeRoutes(router) {
23
- this._initializeRoutesGamerById(router);
24
- this._initializeRoutesGamerByTag(router);
25
- this._initializeRoutesRefreshSettings(router);
26
- this._initializeRoutesUpdate(router);
27
- this._initializeRoutesUpdateSettings(router);
28
- }
29
-
30
- _initializeRoutesGamerById(router) {
31
- return router.get(this._join('/gamerId/:gamerId'),
32
- // authentication(false),
33
- // // authorization('user'),
34
- {
35
- preHandler: router.auth([
36
- router.authenticationDefault,
37
- // router.authorizationDefault
38
- ],
39
- {
40
- relation: 'and',
41
- required: false,
42
- roles: [ 'user' ]
43
- }),
44
- },
45
- // eslint-disable-next-line
46
- async (request, reply) => {
47
- // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
48
- const response = (await router[LibraryConstants.InjectorKeys.SERVICE_USERS].fetchByGamerId(request.correlationId, request.params.gamerId)).check(request);
49
- this._jsonResponse(reply, response);
50
- }
51
- );
52
- }
53
-
54
- _initializeRoutesGamerByTag(router) {
55
- return router.get(this._join('/gamerTag/:gamerTag'),
56
- // authentication(false),
57
- // // authorization('user'),
58
- {
59
- preHandler: router.auth([
60
- router.authenticationDefault,
61
- // router.authorizationDefault
62
- ],
63
- {
64
- relation: 'and',
65
- required: false,
66
- roles: [ 'user' ]
67
- }),
68
- },
69
- // eslint-disable-next-line
70
- async (request, reply) => {
71
- // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
72
- const response = (await router[LibraryConstants.InjectorKeys.SERVICE_USERS].fetchByGamerTag(request.correlationId, request.params.gamerTag)).check(request);
73
- this._jsonResponse(reply, response);
74
- }
75
- );
76
- }
77
-
78
- _initializeRoutesRefreshSettings(router) {
79
- return router.post(this._join('/refresh/settings'),
80
- // authentication(true),
81
- // authorization('user'),
82
- {
83
- preHandler: router.auth([
84
- router.authenticationDefault,
85
- router.authorizationDefault
86
- ],
87
- {
88
- relation: 'and',
89
- roles: [ 'user' ]
90
- }),
91
- },
92
- // eslint-disable-next-line
93
- async (request, reply) => {
94
- // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
95
- const response = (await router[LibraryConstants.InjectorKeys.SERVICE_USERS].refreshSettings(request.correlationId, request.body)).check(request);
96
- this._jsonResponse(reply, response);
97
- }
98
- );
99
- }
100
-
101
- _initializeRoutesUpdate(router) {
102
- return router.post(this._join('/update'),
103
- // authentication(true),
104
- // authorization('user'),
105
- {
106
- preHandler: router.auth([
107
- router.authenticationDefault,
108
- // router.authorizationDefault
109
- ],
110
- {
111
- relation: 'and',
112
- roles: [ 'user' ]
113
- }),
114
- },
115
- // eslint-disable-next-line
116
- async (request, reply) => {
117
- // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
118
- const response = (await router[LibraryConstants.InjectorKeys.SERVICE_USERS].update(request.correlationId, request.body)).check(request);
119
- this._jsonResponse(reply, response);
120
- }
121
- );
122
- }
123
-
124
- _initializeRoutesUpdateSettings(router) {
125
- return router.post(this._join('/update/settings'),
126
- // authentication(true),
127
- // authorization('user'),
128
- {
129
- preHandler: router.auth([
130
- router.authenticationDefault,
131
- router.authorizationDefault
132
- ],
133
- {
134
- relation: 'and',
135
- roles: [ 'user' ]
136
- }),
137
- },
138
- // eslint-disable-next-line
139
- async (request, reply) => {
140
- // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
141
- const response = (await router[LibraryConstants.InjectorKeys.SERVICE_USERS].updateSettings(request.correlationId, request.body)).check(request);
142
- this._jsonResponse(reply, response);
143
- }
144
- );
145
- }
146
- }
147
-
148
- export default BaseUsersRoute;
1
+ import LibraryConstants from '@thzero/library_server/constants.js';
2
+
3
+ import BaseRoute from './index.js';
4
+
5
+ class BaseUsersRoute extends BaseRoute {
6
+ constructor(prefix, version) {
7
+ super(prefix ? prefix : '/users');
8
+
9
+ // this._serviceUsers = null;
10
+ }
11
+
12
+ async init(injector, app, config) {
13
+ await super.init(injector, app, config);
14
+ // this._serviceUsers = injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
15
+ this._inject(app, injector, LibraryConstants.InjectorKeys.SERVICE_USERS, LibraryConstants.InjectorKeys.SERVICE_USERS);
16
+ }
17
+
18
+ get id() {
19
+ return 'users';
20
+ }
21
+
22
+ _initializeRoutes(router) {
23
+ this._initializeRoutesGamerById(router);
24
+ this._initializeRoutesGamerByTag(router);
25
+ this._initializeRoutesRefreshSettings(router);
26
+ this._initializeRoutesUpdate(router);
27
+ this._initializeRoutesUpdateSettings(router);
28
+ }
29
+
30
+ _initializeRoutesGamerById(router) {
31
+ return router.get(this._join('/gamerId/:gamerId'),
32
+ // authentication(false),
33
+ // // authorization('user'),
34
+ {
35
+ preHandler: router.auth([
36
+ router.authenticationDefault,
37
+ // router.authorizationDefault
38
+ ],
39
+ {
40
+ relation: 'and',
41
+ required: false,
42
+ roles: [ 'user' ]
43
+ }),
44
+ },
45
+ // eslint-disable-next-line
46
+ async (request, reply) => {
47
+ // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
48
+ const response = (await router[LibraryConstants.InjectorKeys.SERVICE_USERS].fetchByGamerId(request.correlationId, request.params.gamerId)).check(request);
49
+ this._jsonResponse(reply, response);
50
+ }
51
+ );
52
+ }
53
+
54
+ _initializeRoutesGamerByTag(router) {
55
+ return router.get(this._join('/gamerTag/:gamerTag'),
56
+ // authentication(false),
57
+ // // authorization('user'),
58
+ {
59
+ preHandler: router.auth([
60
+ router.authenticationDefault,
61
+ // router.authorizationDefault
62
+ ],
63
+ {
64
+ relation: 'and',
65
+ required: false,
66
+ roles: [ 'user' ]
67
+ }),
68
+ },
69
+ // eslint-disable-next-line
70
+ async (request, reply) => {
71
+ // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
72
+ const response = (await router[LibraryConstants.InjectorKeys.SERVICE_USERS].fetchByGamerTag(request.correlationId, request.params.gamerTag)).check(request);
73
+ this._jsonResponse(reply, response);
74
+ }
75
+ );
76
+ }
77
+
78
+ _initializeRoutesRefreshSettings(router) {
79
+ return router.post(this._join('/refresh/settings'),
80
+ // authentication(true),
81
+ // authorization('user'),
82
+ {
83
+ preHandler: router.auth([
84
+ router.authenticationDefault,
85
+ router.authorizationDefault
86
+ ],
87
+ {
88
+ relation: 'and',
89
+ roles: [ 'user' ]
90
+ }),
91
+ },
92
+ // eslint-disable-next-line
93
+ async (request, reply) => {
94
+ // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
95
+ const response = (await router[LibraryConstants.InjectorKeys.SERVICE_USERS].refreshSettings(request.correlationId, request.body)).check(request);
96
+ this._jsonResponse(reply, response);
97
+ }
98
+ );
99
+ }
100
+
101
+ _initializeRoutesUpdate(router) {
102
+ return router.post(this._join('/update'),
103
+ // authentication(true),
104
+ // authorization('user'),
105
+ {
106
+ preHandler: router.auth([
107
+ router.authenticationDefault,
108
+ // router.authorizationDefault
109
+ ],
110
+ {
111
+ relation: 'and',
112
+ roles: [ 'user' ]
113
+ }),
114
+ },
115
+ // eslint-disable-next-line
116
+ async (request, reply) => {
117
+ // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
118
+ const response = (await router[LibraryConstants.InjectorKeys.SERVICE_USERS].update(request.correlationId, request.body)).check(request);
119
+ this._jsonResponse(reply, response);
120
+ }
121
+ );
122
+ }
123
+
124
+ _initializeRoutesUpdateSettings(router) {
125
+ return router.post(this._join('/update/settings'),
126
+ // authentication(true),
127
+ // authorization('user'),
128
+ {
129
+ preHandler: router.auth([
130
+ router.authenticationDefault,
131
+ router.authorizationDefault
132
+ ],
133
+ {
134
+ relation: 'and',
135
+ roles: [ 'user' ]
136
+ }),
137
+ },
138
+ // eslint-disable-next-line
139
+ async (request, reply) => {
140
+ // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
141
+ const response = (await router[LibraryConstants.InjectorKeys.SERVICE_USERS].updateSettings(request.correlationId, request.body)).check(request);
142
+ this._jsonResponse(reply, response);
143
+ }
144
+ );
145
+ }
146
+ }
147
+
148
+ export default BaseUsersRoute;
package/routes/home.js CHANGED
@@ -1,28 +1,28 @@
1
- import BaseRoute from './index.js';
2
-
3
- class HomeRoute extends BaseRoute {
4
- constructor(prefix) {
5
- super(prefix ? prefix : '');
6
- }
7
-
8
- get id() {
9
- return 'home';
10
- }
11
-
12
- _initializeRoutes(router) {
13
- // eslint-disable-next-linethis._prefix
14
- router.get(this._join('/'), (request, reply) => {
15
- reply.status(494).send();
16
- });
17
- }
18
-
19
- get _ignoreApi() {
20
- return true;
21
- }
22
-
23
- get _version() {
24
- return '';
25
- }
26
- }
27
-
28
- export default HomeRoute;
1
+ import BaseRoute from './index.js';
2
+
3
+ class HomeRoute extends BaseRoute {
4
+ constructor(prefix) {
5
+ super(prefix ? prefix : '');
6
+ }
7
+
8
+ get id() {
9
+ return 'home';
10
+ }
11
+
12
+ _initializeRoutes(router) {
13
+ // eslint-disable-next-linethis._prefix
14
+ router.get(this._join('/'), (request, reply) => {
15
+ reply.status(494).send();
16
+ });
17
+ }
18
+
19
+ get _ignoreApi() {
20
+ return true;
21
+ }
22
+
23
+ get _version() {
24
+ return '';
25
+ }
26
+ }
27
+
28
+ export default HomeRoute;
package/routes/index.js CHANGED
@@ -1,41 +1,41 @@
1
- import fastifyPlugin from 'fastify-plugin';
2
-
3
- import Utility from '@thzero/library_common/utility/index.js';
4
-
5
- import BaseRoute from'@thzero/library_server/routes/index.js';
6
-
7
- class FastifyBaseRoute extends BaseRoute {
8
- _initializeRouter(app, config) {
9
- return app;
10
- }
11
-
12
- async _inject(app, injector, key, name) {
13
- const service = injector.getService(key);
14
- if (!service)
15
- throw Error(`Invalid service for '${key}'.`);
16
-
17
- app.register(fastifyPlugin((instance, opts, done) => {
18
- instance.decorate(opts.name, opts.service);
19
- done();
20
- }), {
21
- name: name,
22
- service: service
23
- });
24
- }
25
-
26
- _join(path) {
27
- return this._prefix + path;
28
- }
29
-
30
- _jsonResponse(reply, json) {
31
- if (!reply)
32
- throw Error('Invalid context for response.');
33
-
34
- reply
35
- .code(200)
36
- .header('Content-Type', 'application/json; charset=utf-8')
37
- .send((typeof user === 'string') ? json : Utility.stringify(json));
38
- }
39
- }
40
-
41
- export default FastifyBaseRoute;
1
+ import fastifyPlugin from 'fastify-plugin';
2
+
3
+ import Utility from '@thzero/library_common/utility/index.js';
4
+
5
+ import BaseRoute from'@thzero/library_server/routes/index.js';
6
+
7
+ class FastifyBaseRoute extends BaseRoute {
8
+ _initializeRouter(app, config) {
9
+ return app;
10
+ }
11
+
12
+ async _inject(app, injector, key, name) {
13
+ const service = injector.getService(key);
14
+ if (!service)
15
+ throw Error(`Invalid service for '${key}'.`);
16
+
17
+ app.register(fastifyPlugin((instance, opts, done) => {
18
+ instance.decorate(opts.name, opts.service);
19
+ done();
20
+ }), {
21
+ name: name,
22
+ service: service
23
+ });
24
+ }
25
+
26
+ _join(path) {
27
+ return this._prefix + path;
28
+ }
29
+
30
+ _jsonResponse(reply, json) {
31
+ if (!reply)
32
+ throw Error('Invalid context for response.');
33
+
34
+ reply
35
+ .code(200)
36
+ .header('Content-Type', 'application/json; charset=utf-8')
37
+ .send((typeof user === 'string') ? json : Utility.stringify(json));
38
+ }
39
+ }
40
+
41
+ export default FastifyBaseRoute;
package/routes/news.js CHANGED
@@ -1,6 +1,6 @@
1
- import BaseNewsRoute from './baseNews.js';
2
-
3
- class NewsRoute extends BaseNewsRoute {
4
- }
5
-
6
- export default NewsRoute;
1
+ import BaseNewsRoute from './baseNews.js';
2
+
3
+ class NewsRoute extends BaseNewsRoute {
4
+ }
5
+
6
+ export default NewsRoute;
package/routes/plans.js CHANGED
@@ -1,38 +1,38 @@
1
- import LibraryConstants from '@thzero/library_server/constants.js';
2
-
3
- import BaseRoute from './index.js';
4
-
5
- class PlansRoute extends BaseRoute {
6
- constructor(prefix) {
7
- super(prefix ? prefix : '/plans');
8
-
9
- // this._servicePlans = null;
10
- }
11
-
12
- async init(injector, app, config) {
13
- await super.init(injector, app, config);
14
- // this._servicePlans = injector.getService(LibraryConstants.InjectorKeys.SERVICE_PLANS);
15
- this._inject(app, injector, LibraryConstants.InjectorKeys.SERVICE_PLANS, LibraryConstants.InjectorKeys.SERVICE_PLANS);
16
- }
17
-
18
- get id() {
19
- return 'plans';
20
- }
21
-
22
- _initializeRoutes(router) {
23
- router.get(this._join(''),
24
- // eslint-disable-next-line
25
- async (request, reply) => {
26
- // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_PLANS);
27
- const response = (await router[LibraryConstants.InjectorKeys.SERVICE_PLANS].listing(request.correlationId, request.body)).check(request);
28
- this._jsonResponse(reply, response);
29
- }
30
- );
31
- }
32
-
33
- get _version() {
34
- return 'v1';
35
- }
36
- }
37
-
38
- export default PlansRoute;
1
+ import LibraryConstants from '@thzero/library_server/constants.js';
2
+
3
+ import BaseRoute from './index.js';
4
+
5
+ class PlansRoute extends BaseRoute {
6
+ constructor(prefix) {
7
+ super(prefix ? prefix : '/plans');
8
+
9
+ // this._servicePlans = null;
10
+ }
11
+
12
+ async init(injector, app, config) {
13
+ await super.init(injector, app, config);
14
+ // this._servicePlans = injector.getService(LibraryConstants.InjectorKeys.SERVICE_PLANS);
15
+ this._inject(app, injector, LibraryConstants.InjectorKeys.SERVICE_PLANS, LibraryConstants.InjectorKeys.SERVICE_PLANS);
16
+ }
17
+
18
+ get id() {
19
+ return 'plans';
20
+ }
21
+
22
+ _initializeRoutes(router) {
23
+ router.get(this._join(''),
24
+ // eslint-disable-next-line
25
+ async (request, reply) => {
26
+ // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_PLANS);
27
+ const response = (await router[LibraryConstants.InjectorKeys.SERVICE_PLANS].listing(request.correlationId, request.body)).check(request);
28
+ this._jsonResponse(reply, response);
29
+ }
30
+ );
31
+ }
32
+
33
+ get _version() {
34
+ return 'v1';
35
+ }
36
+ }
37
+
38
+ export default PlansRoute;
package/routes/users.js CHANGED
@@ -1,6 +1,6 @@
1
- import BaseUsersRoute from './baseUser.jss';
2
-
3
- class UsersRoute extends BaseUsersRoute {
4
- }
5
-
6
- export default UsersRoute;
1
+ import BaseUsersRoute from './baseUser.jss';
2
+
3
+ class UsersRoute extends BaseUsersRoute {
4
+ }
5
+
6
+ export default UsersRoute;
package/routes/utility.js CHANGED
@@ -1,51 +1,51 @@
1
- import LibraryConstants from '@thzero/library_server/constants.js';
2
-
3
- import BaseRoute from './index.js';
4
-
5
- class UtilityRoute extends BaseRoute {
6
- constructor(prefix) {
7
- super(prefix ? prefix : '/utility');
8
-
9
- // this._serviceUtility = null;
10
- }
11
-
12
- async init(injector, app, config) {
13
- await super.init(injector, app, config);
14
- // this._serviceUtility = injector.getService(LibraryConstants.InjectorKeys.SERVICE_UTILITY);
15
- this._inject(app, injector, LibraryConstants.InjectorKeys.SERVICE_UTILITY, LibraryConstants.InjectorKeys.SERVICE_UTILITY);
16
- }
17
-
18
- get id() {
19
- return 'utility';
20
- }
21
-
22
- _initializeRoutes(router) {
23
- router.post('/logger',
24
- // authentication(false),
25
- // // authorization('utility'),
26
- {
27
- preHandler: router.auth([
28
- router.authenticationDefault,
29
- // router.authorizationDefault
30
- ],
31
- {
32
- relation: 'and',
33
- required: false,
34
- roles: [ 'utility' ]
35
- }),
36
- },
37
- // eslint-disable-next-line
38
- async (request, reply) => {
39
- // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_UTILITY);
40
- const response = (await router[LibraryConstants.InjectorKeys.SERVICE_UTILITY].logger(request.correlationId, request.body)).check(request);
41
- this._jsonResponse(reply, response);
42
- }
43
- );
44
- }
45
-
46
- get _version() {
47
- return 'v1';
48
- }
49
- }
50
-
51
- export default UtilityRoute;
1
+ import LibraryConstants from '@thzero/library_server/constants.js';
2
+
3
+ import BaseRoute from './index.js';
4
+
5
+ class UtilityRoute extends BaseRoute {
6
+ constructor(prefix) {
7
+ super(prefix ? prefix : '/utility');
8
+
9
+ // this._serviceUtility = null;
10
+ }
11
+
12
+ async init(injector, app, config) {
13
+ await super.init(injector, app, config);
14
+ // this._serviceUtility = injector.getService(LibraryConstants.InjectorKeys.SERVICE_UTILITY);
15
+ this._inject(app, injector, LibraryConstants.InjectorKeys.SERVICE_UTILITY, LibraryConstants.InjectorKeys.SERVICE_UTILITY);
16
+ }
17
+
18
+ get id() {
19
+ return 'utility';
20
+ }
21
+
22
+ _initializeRoutes(router) {
23
+ router.post('/logger',
24
+ // authentication(false),
25
+ // // authorization('utility'),
26
+ {
27
+ preHandler: router.auth([
28
+ router.authenticationDefault,
29
+ // router.authorizationDefault
30
+ ],
31
+ {
32
+ relation: 'and',
33
+ required: false,
34
+ roles: [ 'utility' ]
35
+ }),
36
+ },
37
+ // eslint-disable-next-line
38
+ async (request, reply) => {
39
+ // const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_UTILITY);
40
+ const response = (await router[LibraryConstants.InjectorKeys.SERVICE_UTILITY].logger(request.correlationId, request.body)).check(request);
41
+ this._jsonResponse(reply, response);
42
+ }
43
+ );
44
+ }
45
+
46
+ get _version() {
47
+ return 'v1';
48
+ }
49
+ }
50
+
51
+ export default UtilityRoute;