@thzero/library_server_fastify 0.17.20 → 0.17.21

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