@thzero/library_server 0.15.22 → 0.15.25

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.
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@thzero/library_server",
3
3
  "type": "module",
4
- "version": "0.15.22",
4
+ "version": "0.15.25",
5
5
  "version_major": 0,
6
6
  "version_minor": 15,
7
- "version_patch": 22,
8
- "version_date": "04/15/2022",
7
+ "version_patch": 25,
8
+ "version_date": "04/16/2022",
9
9
  "description": "An opinionated library of common functionality to bootstrap a Koa based API application using MongoDb and Firebase.",
10
10
  "author": "thZero",
11
11
  "license": "MIT",
@@ -44,7 +44,7 @@ class AdminBaseRoute extends BaseRoute {
44
44
  async (ctx, next) => {
45
45
  const service = this._injector.getService(self._options.serviceKey);
46
46
  const response = (await service.create(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
47
- ctx.body = Utility.stringify(response);
47
+ this._jsonResponse(ctx, Utility.stringify(response));
48
48
  }
49
49
  );
50
50
  }
@@ -58,7 +58,7 @@ class AdminBaseRoute extends BaseRoute {
58
58
  async (ctx, next) => {
59
59
  const service = this._injector.getService(self._options.serviceKey);
60
60
  const response = (await service.delete(ctx.correlationId, ctx.state.user, ctx.params.id)).check(ctx);
61
- ctx.body = Utility.stringify(response);
61
+ this._jsonResponse(ctx, Utility.stringify(response));
62
62
  }
63
63
  );
64
64
  }
@@ -75,7 +75,7 @@ class AdminBaseRoute extends BaseRoute {
75
75
  async (ctx, next) => {
76
76
  const service = this._injector.getService(self._options.serviceKey);
77
77
  const response = (await service.update(ctx.correlationId, ctx.state.user, ctx.params.id, ctx.request.body)).check(ctx);
78
- ctx.body = Utility.stringify(response);
78
+ this._jsonResponse(ctx, Utility.stringify(response));
79
79
  }
80
80
  );
81
81
  }
@@ -94,7 +94,7 @@ class AdminBaseRoute extends BaseRoute {
94
94
  async (ctx, next) => {
95
95
  const service = this._injector.getService(this._options.serviceKey);
96
96
  const response = (await service.search(ctx.correlationId, ctx.state.user, ctx.request.body)).check(ctx);
97
- ctx.body = Utility.stringify(response);
97
+ this._jsonResponse(ctx, Utility.stringify(response));
98
98
  }
99
99
  );
100
100
 
@@ -22,7 +22,7 @@ class BaseNewsRoute extends BaseRoute {
22
22
  async (ctx, next) => {
23
23
  const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_NEWS);
24
24
  const response = (await service.latest(ctx.correlationId, ctx.state.user, parseInt(ctx.params.date))).check(ctx);
25
- ctx.body = Utility.stringify(response);
25
+ this._jsonResponse(ctx, Utility.stringify(response));
26
26
  }
27
27
  );
28
28
  }
@@ -37,7 +37,7 @@ class BaseUsersRoute extends BaseRoute {
37
37
  async (ctx, next) => {
38
38
  const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
39
39
  const response = (await service.fetchByGamerId(ctx.correlationId, ctx.params.gamerId)).check(ctx);
40
- ctx.body = Utility.stringify(response);
40
+ this._jsonResponse(ctx, Utility.stringify(response));
41
41
  }
42
42
  );
43
43
  }
@@ -53,7 +53,7 @@ class BaseUsersRoute extends BaseRoute {
53
53
  async (ctx, next) => {
54
54
  const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
55
55
  const response = (await service.fetchByGamerTag(ctx.correlationId, ctx.params.gamerTag)).check(ctx);
56
- ctx.body = Utility.stringify(response);
56
+ this._jsonResponse(ctx, Utility.stringify(response));
57
57
  }
58
58
  );
59
59
  }
@@ -69,7 +69,7 @@ class BaseUsersRoute extends BaseRoute {
69
69
  async (ctx, next) => {
70
70
  const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
71
71
  const response = (await service.refreshSettings(ctx.correlationId, ctx.request.body)).check(ctx);
72
- ctx.body = Utility.stringify(response);
72
+ this._jsonResponse(ctx, Utility.stringify(response));
73
73
  }
74
74
  );
75
75
  }
@@ -85,7 +85,7 @@ class BaseUsersRoute extends BaseRoute {
85
85
  async (ctx, next) => {
86
86
  const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
87
87
  const response = (await service.update(ctx.correlationId, ctx.request.body)).check(ctx);
88
- ctx.body = Utility.stringify(response);
88
+ this._jsonResponse(ctx, Utility.stringify(response));
89
89
  }
90
90
  );
91
91
  }
@@ -101,7 +101,7 @@ class BaseUsersRoute extends BaseRoute {
101
101
  async (ctx, next) => {
102
102
  const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_USERS);
103
103
  const response = (await service.updateSettings(ctx.correlationId, ctx.request.body)).check(ctx);
104
- ctx.body = Utility.stringify(response);
104
+ this._jsonResponse(ctx, Utility.stringify(response));
105
105
  }
106
106
  );
107
107
  }
package/routes/home.js CHANGED
@@ -16,8 +16,12 @@ class HomeRoute extends BaseRoute {
16
16
  });
17
17
  }
18
18
 
19
+ get _ignoreApi() {
20
+ return true;
21
+ }
22
+
19
23
  get _version() {
20
- return 'v1';
24
+ return '';
21
25
  }
22
26
  }
23
27
 
package/routes/index.js CHANGED
@@ -27,12 +27,15 @@ class BaseRoute {
27
27
  this._injector = injector;
28
28
 
29
29
  const api = config.get('api', { });
30
- let prefix = api.prefix !== null && api.prefix !== undefined ? api.prefix : 'api';
31
- if (!String.isNullOrEmpty(prefix) && (prefix !== '/'))
32
- prefix = '/' + prefix;
30
+ let prefix = '';
31
+ if (!this._ignoreApi) {
32
+ prefix = api.prefix !== null && api.prefix !== undefined ? api.prefix : 'api';
33
+ if (!String.isNullOrEmpty(prefix) && (prefix !== '/'))
34
+ prefix = '/' + prefix;
35
+ }
33
36
 
34
37
  let version = !String.isNullOrEmpty(api.version) ? api.version : null;
35
- if (!String.isNullOrEmpty(this._version))
38
+ if (this._version !== null && this._version !== undefined)
36
39
  version = this._version;
37
40
  if (!String.isNullOrEmpty(this.id) && api.apis && Array.isArray(api.apis))
38
41
  version = api.apis[this.id];
@@ -54,9 +57,21 @@ class BaseRoute {
54
57
  return this._router;
55
58
  }
56
59
 
60
+ _jsonResponse(ctx, json) {
61
+ if (!ctx)
62
+ throw Error('Invalid context for response.');
63
+
64
+ ctx.type = 'application/json; charset=utf-8';
65
+ ctx.body = json;
66
+ }
67
+
57
68
  _initializeRoutes(router) {
58
69
  }
59
70
 
71
+ get _ignoreApi() {
72
+ return false;
73
+ }
74
+
60
75
  get _version() {
61
76
  return null;
62
77
  }
package/routes/plans.js CHANGED
@@ -19,7 +19,7 @@ class PlansRoute extends BaseRoute {
19
19
  async (ctx, next) => {
20
20
  const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_PLANS);
21
21
  const response = (await service.listing(ctx.correlationId)).check(ctx);
22
- ctx.body = Utility.stringify(response);
22
+ this._jsonResponse(ctx, Utility.stringify(response));
23
23
  }
24
24
  );
25
25
  }
package/routes/utility.js CHANGED
@@ -29,7 +29,7 @@ class UtilityRoute extends BaseRoute {
29
29
  async (ctx, next) => {
30
30
  const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_UTILITY);
31
31
  const response = (await service.logger(ctx.correlationId, ctx.request.body)).check(ctx);
32
- ctx.body = Utility.stringify(response);
32
+ this._jsonResponse(ctx, Utility.stringify(response));
33
33
  }
34
34
  );
35
35
  }
package/routes/version.js CHANGED
@@ -19,7 +19,7 @@ class VersionRoute extends BaseRoute {
19
19
  async (ctx, next) => {
20
20
  const service = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_VERSION);
21
21
  const response = (await service.version(ctx.correlationId)).check(ctx);
22
- ctx.body = Utility.stringify(response);
22
+ this._jsonResponse(ctx, Utility.stringify(response));
23
23
  }
24
24
  );
25
25
  }