@thzero/library_server_fastify 0.18.13 → 0.18.14

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,180 +1,180 @@
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._initializeRoutesByExternalId(router);
27
- this._initializeRoutesRefreshSettings(router);
28
- this._initializeRoutesUpdate(router);
29
- this._initializeRoutesUpdateSettings(router);
30
- }
31
-
32
- _initializeRoutesByExternalId(router) {
33
- return router.get(this._join('/:externalId'),
34
- // authentication(false),
35
- // // authorization('user'),
36
- {
37
- preHandler: router.auth([
38
- router.authenticationDefault,
39
- // router.authorizationDefault
40
- ],
41
- {
42
- relation: LibraryCommonnConstants.Security.logicalAnd,
43
- required: false,
44
- roles: [ 'user' ]
45
- }),
46
- },
47
- // eslint-disable-next-line
48
- async (request, reply) => {
49
- // const service = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
50
- const response = (await router[LibraryServerConstants.InjectorKeys.SERVICE_USERS].fetchByExternalId(request.correlationId, request.params.externalId)).check(request);
51
- // https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
52
- return this._jsonResponse(reply, response);
53
- }
54
- );
55
- }
56
-
57
- _initializeRoutesGamerById(router) {
58
- return router.get(this._join('/gamerId/:gamerId'),
59
- // authentication(false),
60
- // // authorization('user'),
61
- {
62
- preHandler: router.auth([
63
- router.authenticationDefault,
64
- // router.authorizationDefault
65
- ],
66
- {
67
- relation: LibraryCommonnConstants.Security.logicalAnd,
68
- required: false,
69
- roles: [ 'user' ]
70
- }),
71
- },
72
- // eslint-disable-next-line
73
- async (request, reply) => {
74
- // const service = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
75
- const response = (await router[LibraryServerConstants.InjectorKeys.SERVICE_USERS].fetchByGamerId(request.correlationId, request.params.gamerId)).check(request);
76
- // https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
77
- return this._jsonResponse(reply, response);
78
- }
79
- );
80
- }
81
-
82
- _initializeRoutesGamerByTag(router) {
83
- return router.get(this._join('/gamerTag/:gamerTag'),
84
- // authentication(false),
85
- // // authorization('user'),
86
- {
87
- preHandler: router.auth([
88
- router.authenticationDefault,
89
- // router.authorizationDefault
90
- ],
91
- {
92
- relation: LibraryCommonnConstants.Security.logicalAnd,
93
- required: false,
94
- roles: [ 'user' ]
95
- }),
96
- },
97
- // eslint-disable-next-line
98
- async (request, reply) => {
99
- // const service = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
100
- const response = (await router[LibraryServerConstants.InjectorKeys.SERVICE_USERS].fetchByGamerTag(request.correlationId, request.params.gamerTag)).check(request);
101
- // https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
102
- return this._jsonResponse(reply, response);
103
- }
104
- );
105
- }
106
-
107
- _initializeRoutesRefreshSettings(router) {
108
- return router.post(this._join('/refresh/settings'),
109
- // authentication(true),
110
- // authorization('user'),
111
- {
112
- preHandler: router.auth([
113
- router.authenticationDefault,
114
- router.authorizationDefault
115
- ],
116
- {
117
- relation: LibraryCommonnConstants.Security.logicalAnd,
118
- roles: [ 'user' ]
119
- }),
120
- },
121
- // eslint-disable-next-line
122
- async (request, reply) => {
123
- // const service = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
124
- const response = (await router[LibraryServerConstants.InjectorKeys.SERVICE_USERS].refreshSettings(request.correlationId, request.body)).check(request);
125
- // https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
126
- return this._jsonResponse(reply, response);
127
- }
128
- );
129
- }
130
-
131
- _initializeRoutesUpdate(router) {
132
- return router.post(this._join('/update'),
133
- // authentication(true),
134
- // authorization('user'),
135
- {
136
- preHandler: router.auth([
137
- router.authenticationDefault,
138
- // router.authorizationDefault
139
- ],
140
- {
141
- relation: LibraryCommonnConstants.Security.logicalAnd,
142
- roles: [ 'user' ]
143
- }),
144
- },
145
- // eslint-disable-next-line
146
- async (request, reply) => {
147
- // const service = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
148
- const response = (await router[LibraryServerConstants.InjectorKeys.SERVICE_USERS].update(request.correlationId, request.body)).check(request);
149
- // https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
150
- return this._jsonResponse(reply, response);
151
- }
152
- );
153
- }
154
-
155
- _initializeRoutesUpdateSettings(router) {
156
- return router.post(this._join('/update/settings'),
157
- // authentication(true),
158
- // authorization('user'),
159
- {
160
- preHandler: router.auth([
161
- router.authenticationDefault,
162
- router.authorizationDefault
163
- ],
164
- {
165
- relation: LibraryCommonnConstants.Security.logicalAnd,
166
- roles: [ 'user' ]
167
- }),
168
- },
169
- // eslint-disable-next-line
170
- async (request, reply) => {
171
- // const service = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
172
- const response = (await router[LibraryServerConstants.InjectorKeys.SERVICE_USERS].updateSettings(request.correlationId, request.body)).check(request);
173
- // https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
174
- return this._jsonResponse(reply, response);
175
- }
176
- );
177
- }
178
- }
179
-
180
- 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._initializeRoutesByExternalId(router);
27
+ this._initializeRoutesRefreshSettings(router);
28
+ this._initializeRoutesUpdate(router);
29
+ this._initializeRoutesUpdateSettings(router);
30
+ }
31
+
32
+ _initializeRoutesByExternalId(router) {
33
+ return router.get(this._join('/:externalId'),
34
+ // authentication(false),
35
+ // // authorization('user'),
36
+ {
37
+ preHandler: router.auth([
38
+ router.authenticationDefault,
39
+ // router.authorizationDefault
40
+ ],
41
+ {
42
+ relation: LibraryCommonnConstants.Security.logicalAnd,
43
+ required: false,
44
+ roles: [ 'user' ]
45
+ }),
46
+ },
47
+ // eslint-disable-next-line
48
+ async (request, reply) => {
49
+ // const service = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
50
+ const response = (await router[LibraryServerConstants.InjectorKeys.SERVICE_USERS].fetchByExternalId(request.correlationId, request.params.externalId)).check(request);
51
+ // https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
52
+ return this._jsonResponse(reply, response);
53
+ }
54
+ );
55
+ }
56
+
57
+ _initializeRoutesGamerById(router) {
58
+ return router.get(this._join('/gamerId/:gamerId'),
59
+ // authentication(false),
60
+ // // authorization('user'),
61
+ {
62
+ preHandler: router.auth([
63
+ router.authenticationDefault,
64
+ // router.authorizationDefault
65
+ ],
66
+ {
67
+ relation: LibraryCommonnConstants.Security.logicalAnd,
68
+ required: false,
69
+ roles: [ 'user' ]
70
+ }),
71
+ },
72
+ // eslint-disable-next-line
73
+ async (request, reply) => {
74
+ // const service = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
75
+ const response = (await router[LibraryServerConstants.InjectorKeys.SERVICE_USERS].fetchByGamerId(request.correlationId, request.params.gamerId)).check(request);
76
+ // https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
77
+ return this._jsonResponse(reply, response);
78
+ }
79
+ );
80
+ }
81
+
82
+ _initializeRoutesGamerByTag(router) {
83
+ return router.get(this._join('/gamerTag/:gamerTag'),
84
+ // authentication(false),
85
+ // // authorization('user'),
86
+ {
87
+ preHandler: router.auth([
88
+ router.authenticationDefault,
89
+ // router.authorizationDefault
90
+ ],
91
+ {
92
+ relation: LibraryCommonnConstants.Security.logicalAnd,
93
+ required: false,
94
+ roles: [ 'user' ]
95
+ }),
96
+ },
97
+ // eslint-disable-next-line
98
+ async (request, reply) => {
99
+ // const service = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
100
+ const response = (await router[LibraryServerConstants.InjectorKeys.SERVICE_USERS].fetchByGamerTag(request.correlationId, request.params.gamerTag)).check(request);
101
+ // https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
102
+ return this._jsonResponse(reply, response);
103
+ }
104
+ );
105
+ }
106
+
107
+ _initializeRoutesRefreshSettings(router) {
108
+ return router.post(this._join('/refresh/settings'),
109
+ // authentication(true),
110
+ // authorization('user'),
111
+ {
112
+ preHandler: router.auth([
113
+ router.authenticationDefault,
114
+ router.authorizationDefault
115
+ ],
116
+ {
117
+ relation: LibraryCommonnConstants.Security.logicalAnd,
118
+ roles: [ 'user' ]
119
+ }),
120
+ },
121
+ // eslint-disable-next-line
122
+ async (request, reply) => {
123
+ // const service = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
124
+ const response = (await router[LibraryServerConstants.InjectorKeys.SERVICE_USERS].refreshSettings(request.correlationId, request.body)).check(request);
125
+ // https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
126
+ return this._jsonResponse(reply, response);
127
+ }
128
+ );
129
+ }
130
+
131
+ _initializeRoutesUpdate(router) {
132
+ return router.post(this._join('/update'),
133
+ // authentication(true),
134
+ // authorization('user'),
135
+ {
136
+ preHandler: router.auth([
137
+ router.authenticationDefault,
138
+ // router.authorizationDefault
139
+ ],
140
+ {
141
+ relation: LibraryCommonnConstants.Security.logicalAnd,
142
+ roles: [ 'user' ]
143
+ }),
144
+ },
145
+ // eslint-disable-next-line
146
+ async (request, reply) => {
147
+ // const service = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
148
+ const response = (await router[LibraryServerConstants.InjectorKeys.SERVICE_USERS].update(request.correlationId, request.body)).check(request);
149
+ // https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
150
+ return this._jsonResponse(reply, response);
151
+ }
152
+ );
153
+ }
154
+
155
+ _initializeRoutesUpdateSettings(router) {
156
+ return router.post(this._join('/update/settings'),
157
+ // authentication(true),
158
+ // authorization('user'),
159
+ {
160
+ preHandler: router.auth([
161
+ router.authenticationDefault,
162
+ router.authorizationDefault
163
+ ],
164
+ {
165
+ relation: LibraryCommonnConstants.Security.logicalAnd,
166
+ roles: [ 'user' ]
167
+ }),
168
+ },
169
+ // eslint-disable-next-line
170
+ async (request, reply) => {
171
+ // const service = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
172
+ const response = (await router[LibraryServerConstants.InjectorKeys.SERVICE_USERS].updateSettings(request.correlationId, request.body)).check(request);
173
+ // https://github.com/fastify/fastify-compress/issues/215#issuecomment-1210598312
174
+ return this._jsonResponse(reply, response);
175
+ }
176
+ );
177
+ }
178
+ }
179
+
180
+ 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 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;