@thzero/library_server 0.16.6 → 0.16.8

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/openSource.js ADDED
@@ -0,0 +1,67 @@
1
+ export default () => {
2
+ return [
3
+ {
4
+ category: 'server',
5
+ name: '@godaddy/terminus',
6
+ url: 'https://github.com/godaddy/terminus',
7
+ licenseName: 'MIT',
8
+ licenseUrl: 'https://github.com/godaddy/terminus/blob/master/LICENSE'
9
+ },
10
+ {
11
+ category: 'server',
12
+ name: '@thzero/library_common',
13
+ url: 'https://github.com/thzero/library_common',
14
+ licenseName: 'MIT',
15
+ licenseUrl: 'https://github.com/thzero/library_common/blob/master/license.md'
16
+ },
17
+ {
18
+ category: 'server',
19
+ name: '@thzero/library_common_service',
20
+ url: 'https://github.com/thzero/library_common_service',
21
+ licenseName: 'MIT',
22
+ licenseUrl: 'https://github.com/thzero/library_common_service/blob/master/license.md'
23
+ },
24
+ {
25
+ category: 'server',
26
+ name: '@thzero/library_service',
27
+ url: 'https://github.com/thzero/library_service',
28
+ licenseName: 'MIT',
29
+ licenseUrl: 'https://github.com/thzero/library_service/blob/master/license.md'
30
+ },
31
+ {
32
+ category: 'server',
33
+ name: 'async-mutex',
34
+ url: 'https://github.com/DirtyHairy/async-mutex',
35
+ licenseName: 'MIT',
36
+ licenseUrl: 'https://github.com/DirtyHairy/async-mutex/blob/master/LICENSE'
37
+ },
38
+ {
39
+ category: 'server',
40
+ name: 'config',
41
+ url: 'https://github.com/lorenwest/node-config',
42
+ licenseName: 'MIT',
43
+ licenseUrl: 'https://github.com/lorenwest/node-config/blob/master/LICENSE'
44
+ },
45
+ {
46
+ category: 'server',
47
+ name: 'default-gateway',
48
+ url: 'https://github.com/silverwind/default-gateway',
49
+ licenseName: 'BSD 2',
50
+ licenseUrl: 'https://github.com/silverwind/default-gateway/blob/master/LICENSE'
51
+ },
52
+ {
53
+ category: 'server',
54
+ name: 'easy-rbac',
55
+ url: 'https://github.com/DeadAlready/easy-rbac',
56
+ licenseName: 'MIT',
57
+ licenseUrl: 'https://github.com/DeadAlready/easy-rbac/blob/master/LICENSE'
58
+ },
59
+ {
60
+ category: 'server',
61
+ name: 'ipaddr.js',
62
+ url: 'https://github.com/whitequark/ipaddr.js',
63
+ licenseName: 'MIT',
64
+ licenseUrl: 'https://github.com/whitequark/ipaddr.js/blob/master/LICENSE'
65
+ }
66
+ ];
67
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@thzero/library_server",
3
3
  "type": "module",
4
- "version": "0.16.6",
4
+ "version": "0.16.8",
5
5
  "version_major": 0,
6
6
  "version_minor": 16,
7
- "version_patch": 6,
8
- "version_date": "12/11/2022",
7
+ "version_patch": 8,
8
+ "version_date": "12/20/2022",
9
9
  "description": "An opinionated library of common functionality to bootstrap an API application using MongoDb and Firebase. Currently either Fastify or Koa can be used as the web server.",
10
10
  "author": "thZero",
11
11
  "license": "MIT",
@@ -1,6 +1,50 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ import LibraryConstants from '@thzero/library_server/constants.js';
5
+
1
6
  import Service from './index.js';
2
7
 
3
8
  class UtilityService extends Service {
9
+ constructor() {
10
+ super();
11
+
12
+ this._servicePlans = null;
13
+ this._serviceVersion = null;
14
+
15
+ this._openSourceResponse = null;
16
+ }
17
+
18
+ async init(injector) {
19
+ await super.init(injector);
20
+
21
+ this._servicePlans = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_PLANS);
22
+ this._serviceVersion = this._injector.getService(LibraryConstants.InjectorKeys.SERVICE_VERSION);
23
+
24
+ await this._initializeOopenSource();
25
+ }
26
+
27
+ async initialize(correlationId) {
28
+ const response = this._initResponse(correlationId);
29
+ response.results = {};
30
+
31
+ const responsePlans = await this._servicePlans.listing(correlationId);
32
+ if (this._hasFailed(responsePlans))
33
+ return responsePlans;
34
+
35
+ response.results.plans = responsePlans.results;
36
+
37
+ const responseVersion = await this._serviceVersion.version(correlationId);
38
+ if (this._hasFailed(responseVersion))
39
+ return responseVersion;
40
+
41
+ response.results.version = responseVersion.results;
42
+
43
+ this._intialize(correlationId, response);
44
+
45
+ return response;
46
+ }
47
+
4
48
  async logger(content, correlationId) {
5
49
  if (!content)
6
50
  return this._error('UtilityService', 'logger');
@@ -32,6 +76,166 @@ class UtilityService extends Service {
32
76
 
33
77
  return this._success(correlationId);
34
78
  }
79
+
80
+ async openSource(correlationId) {
81
+ return this._openSourceResponse ? this._openSourceResponse : this._error();
82
+ }
83
+
84
+ _intialize(correlationId, response) {
85
+ }
86
+
87
+ async _initializeOopenSource(correlationId) {
88
+ this._openSourceResponse = this._initResponse(correlationId);
89
+ this._openSourceResponse.results = [];
90
+
91
+ try {
92
+ const __dirname = path.resolve();
93
+ const dir = path.join(path.resolve(__dirname), 'node_modules', '@thzero');
94
+ const dirs = await fs.promises.readdir(dir);
95
+
96
+ console.log(`\tOpenSource...`);
97
+
98
+ let file;
99
+ let importPath;
100
+ let fileI;
101
+ let items;
102
+ for (const item of dirs) {
103
+ try {
104
+ file = path.join(dir, item, 'openSource.js');
105
+ console.log(`\t${file}...`);
106
+ if (!fs.existsSync(file)){
107
+ console.log(`\t...not found.`);
108
+ continue;
109
+ }
110
+
111
+ importPath = ['@thzero', item, 'openSource.js'].join('/');
112
+ console.log(`\t${importPath}...`);
113
+ fileI = await import(importPath);
114
+ if (!fileI.default) {
115
+ console.log(`\t...failed to load.`);
116
+ continue;
117
+ }
118
+
119
+ items = fileI.default();
120
+ items.forEach(element => {
121
+ if (element.category !== 'server')
122
+ return;
123
+ if (this._openSourceResponse.results.filter(l => l.name === element.name).length > 0)
124
+ return;
125
+ this._openSourceResponse.results.push(element);
126
+ });
127
+ console.log(`\t...processed.`);
128
+ }
129
+ catch(err) {
130
+ console.log(`\t...failed.`, err);
131
+ this._logger.warn('UtilityService', '_initializeOopenSource', null, err, correlationId);
132
+ }
133
+ }
134
+ }
135
+ catch(err) {
136
+ this._logger.warn('UtilityService', '_initializeOopenSource', null, err, correlationId);
137
+ }
138
+ finally {
139
+ console.log(`\t...OpenSource`);
140
+ }
141
+
142
+ // response.results = await this._openSourceServer(correlationId);
143
+ this._openSource(correlationId, this._openSourceResponse.results);
144
+
145
+ this._openSourceResponse.results = this._openSourceResponse.results.sort((a, b) => a.name.localeCompare(b.name));
146
+ }
147
+
148
+ _openSource(correlationId, openSource) {
149
+ }
150
+
151
+ // async _openSourceServer(correlationId) {
152
+ // return [
153
+ // {
154
+ // category: 'server',
155
+ // name: '@thzero/library_common',
156
+ // url: 'https://github.com/thzero/library_common',
157
+ // licenseName: 'MIT',
158
+ // licenseUrl: 'https://github.com/thzero/library_common/blob/master/license.md'
159
+ // },
160
+ // {
161
+ // category: 'server',
162
+ // name: '@thzero/library_common_service',
163
+ // url: 'https://github.com/thzero/library_common_service',
164
+ // licenseName: 'MIT',
165
+ // licenseUrl: 'https://github.com/thzero/library_common_service/blob/master/license.md'
166
+ // },
167
+ // {
168
+ // category: 'server',
169
+ // name: '@thzero/library_server',
170
+ // url: 'https://github.com/thzero/library_server',
171
+ // licenseName: 'MIT',
172
+ // licenseUrl: 'https://github.com/thzero/library_server/blob/master/license.md'
173
+ // },
174
+ // {
175
+ // category: 'server',
176
+ // name: 'async-mutex',
177
+ // url: 'https://github.com/DirtyHairy/async-mutex',
178
+ // licenseName: 'MIT',
179
+ // licenseUrl: 'https://github.com/DirtyHairy/async-mutex/blob/master/LICENSE'
180
+ // },
181
+ // {
182
+ // category: 'server',
183
+ // name: 'config',
184
+ // url: 'https://github.com/lorenwest/node-config',
185
+ // licenseName: 'MIT',
186
+ // licenseUrl: 'https://github.com/lorenwest/node-config/blob/master/LICENSE'
187
+ // },
188
+ // {
189
+ // category: 'server',
190
+ // name: 'dayjs',
191
+ // url: 'https://github.com/iamkun/dayjs',
192
+ // licenseName: 'MIT',
193
+ // licenseUrl: 'https://github.com/iamkun/dayjs/blob/dev/LICENSE'
194
+ // },
195
+ // {
196
+ // category: 'server',
197
+ // name: 'dayjs-plugin-utc',
198
+ // url: 'https://github.com/guisturdy/dayjs-plugin-utc',
199
+ // licenseName: '??',
200
+ // licenseUrl: ''
201
+ // },
202
+ // {
203
+ // category: 'server',
204
+ // name: 'easy-rbac',
205
+ // url: 'https://github.com/DeadAlready/easy-rbac',
206
+ // licenseName: 'MIT',
207
+ // licenseUrl: 'https://github.com/DeadAlready/easy-rbac/blob/master/LICENSE'
208
+ // },
209
+ // {
210
+ // category: 'server',
211
+ // name: 'ipaddr.js',
212
+ // url: 'https://github.com/whitequark/ipaddr.js',
213
+ // licenseName: 'MIT',
214
+ // licenseUrl: 'https://github.com/whitequark/ipaddr.js/blob/master/LICENSE'
215
+ // },
216
+ // {
217
+ // category: 'client',
218
+ // name: 'lodash',
219
+ // url: 'https://github.com/lodash/lodash',
220
+ // licenseName: 'MIT',
221
+ // licenseUrl: 'https://github.com/lodash/lodash/blob/master/LICENSE'
222
+ // },
223
+ // {
224
+ // category: 'server',
225
+ // name: 'terminus',
226
+ // url: 'https://github.com/godaddy/terminus',
227
+ // licenseName: 'MIT',
228
+ // licenseUrl: 'https://github.com/godaddy/terminus/blob/master/LICENSE'
229
+ // },
230
+ // {
231
+ // category: 'server',
232
+ // name: 'uuid',
233
+ // url: 'https://github.com/kelektiv/node-uuid',
234
+ // licenseName: 'MIT',
235
+ // licenseUrl: 'https://github.com/kelektiv/node-uuid/blob/master/LICENSE.md'
236
+ // }
237
+ // ];
238
+ // }
35
239
  }
36
240
 
37
241
  export default UtilityService;