@thzero/library_server 0.18.22 → 0.18.24

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.
Files changed (53) hide show
  1. package/README.md +289 -112
  2. package/boot/index.js +529 -529
  3. package/boot/plugins/admin/index.js +6 -6
  4. package/boot/plugins/admin/news.js +33 -33
  5. package/boot/plugins/admin/users.js +33 -33
  6. package/boot/plugins/api.js +64 -64
  7. package/boot/plugins/apiFront.js +31 -31
  8. package/boot/plugins/index.js +70 -70
  9. package/boot/plugins/news.js +44 -44
  10. package/boot/plugins/users.js +46 -46
  11. package/boot/plugins/usersExtended.js +32 -32
  12. package/constants.js +45 -45
  13. package/data/baseNews.js +42 -42
  14. package/data/baseSettingsUser.js +9 -9
  15. package/data/baseUser.js +28 -28
  16. package/data/index.js +24 -24
  17. package/data/named.js +20 -20
  18. package/errors/tokenExpired.js +7 -7
  19. package/license.md +8 -8
  20. package/openSource.js +66 -66
  21. package/package.json +38 -38
  22. package/repository/index.js +182 -182
  23. package/repository/usageMetrics/devnull.js +16 -16
  24. package/routes/index.js +76 -76
  25. package/service/admin/baseNews.js +45 -45
  26. package/service/admin/index.js +130 -130
  27. package/service/admin/news.js +6 -6
  28. package/service/admin/users.js +107 -107
  29. package/service/baseSecurity.js +183 -183
  30. package/service/baseUser.js +122 -122
  31. package/service/communication.js +6 -6
  32. package/service/config.js +37 -37
  33. package/service/crypto.js +16 -16
  34. package/service/discovery/index.js +6 -6
  35. package/service/discovery/resources/index.js +101 -101
  36. package/service/external.js +19 -19
  37. package/service/externalRest.js +19 -19
  38. package/service/index.js +20 -20
  39. package/service/monitoring.js +12 -12
  40. package/service/news/base.js +59 -59
  41. package/service/news/index.js +6 -6
  42. package/service/news/validation/index.js +6 -6
  43. package/service/plans.js +31 -31
  44. package/service/restCommunication.js +21 -21
  45. package/service/usageMetrics.js +84 -84
  46. package/service/utility.js +190 -190
  47. package/service/version.js +37 -37
  48. package/utility/injector.js +59 -59
  49. package/utility/internalIp/index.js +48 -48
  50. package/utility/list/doubleLinked.js +88 -88
  51. package/utility/list/priorityQueue.js +109 -109
  52. package/utility/list/queue.js +72 -72
  53. package/utility/os.js +20 -20
package/README.md CHANGED
@@ -1,112 +1,289 @@
1
- ![GitHub package.json version](https://img.shields.io/github/package-json/v/thzero/library_server)
2
- ![David](https://img.shields.io/david/thzero/library_server)
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
-
5
- # library_server
6
-
7
- 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; Fastify will be the focus going forward due to lack of support and updates with the Koa stack.
8
-
9
- ### Requirements
10
-
11
- #### NodeJs
12
-
13
- Requires [NodeJs ](https://nodejs.org) version 18+.
14
-
15
- ### Installation
16
-
17
- [![NPM](https://nodei.co/npm/@thzero/library_server.png?compact=true)](https://npmjs.org/package/@thzero/library_server)
18
-
19
- #### Mongo
20
-
21
- Mongo is the only currently supposed option as the server side data source.
22
-
23
- * Install the MongoDb (either locally or in the cloud) server
24
- * Recommendation is MongoDb Atlas (https://www.mongodb.com/cloud/atlas) for development/sandbox
25
- * Create a new MongoDb database in the Mongo server
26
- * Restore the default SocietySidekick MongoDb
27
- * Use the following MongoDb CLI tool to restore the default database located at (https://github.com/thzero/societySidekick-database)
28
-
29
- ```
30
- .\bin\mongorestore --host <mongodb host name> --ssl --username <mongo user name> --password <mongo user password> --authenticationDatabase admin -d production <location of default database>
31
- ```
32
-
33
- Recommended tools for managing Mongo database
34
- * MongoDb Compass (https://www.mongodb.com/products/compass)
35
- * Robo3T (https://robomongo.org)
36
-
37
- #### Firebase
38
-
39
- Google Firebase (https://firebase.google.com) provides the social based authentication; currently only Google social accounts are supported.
40
-
41
- * Add a new project
42
- * Setup **Authentication**, enabled Google in the **Sign-in method**.
43
- * Get the Firebase SDK configuration
44
- * Go to Project Overview->Settings->Service accounts
45
- * Select **Node.js** option
46
- * Click **Generate new private key**
47
-
48
- #### Configuration
49
-
50
- The following setup for configuration is required for an application using this library_server dependency
51
-
52
- * Setup the configuration found in the config\development.json
53
- * Note that this is ignored in the .gitignore
54
- * Configuration looks like the following
55
-
56
- ```
57
- {
58
- "app": {
59
- "auth": {
60
- "apiKey": "<generate a GUID as key in standard nomeclature '#######-####-####-####-############'>",
61
- "claims": {
62
- "check": <true of false, false by default>,
63
- "useDefault": <true of false, false by default>
64
- }
65
- },
66
- "cors": {
67
- "origin": "*"
68
- },
69
- "db": {
70
- "default": "mongo"
71
- "mongo": {
72
- "connection": "<mongo connection string>",
73
- "name": "<environment name>"
74
- }
75
- },
76
- "logging": {
77
- "level": <see https://github.com/pinojs/pino/issues/123 for logging levels>,
78
- "prettify": <true of false if you want prettify, if true requres 'pino-prettify' as a dependency>
79
- },
80
- "port": <port to run the server on>
81
- }
82
- }
83
- ```
84
-
85
- ##### Environment Variable overrides
86
-
87
- The following environmnent variables override the above configuration settings found in the config file.
88
-
89
- * AUTH_API_KEY
90
- * AUTH_CLAIMS_CHECK
91
- * AUTH_CLAIMS_USE_DEFAULT
92
- * CORS_ORIGIN
93
- * DB_DEFAULT
94
- * DB_CONNECTION_ATLAS
95
- * DB_NAME_ATLAS
96
- * DB_CONNECTION_MONGO
97
- * DB_NAME_MONGO
98
- * IP_ADDRESS
99
- * LOGGING_LEVEL
100
- * LOGGING_PRETTIFY
101
- * PORT
102
-
103
- ##### Development Tool Configuration
104
-
105
- * Include the following in the package.json for the application.
106
-
107
- ```
108
- "version_major": #,
109
- "version_minor": #,
110
- "version_patch": #,
111
- "version_date": "MM/DD/YYYY",
112
- ```
1
+ ![GitHub package.json version](https://img.shields.io/github/package-json/v/thzero/library_server)
2
+ ![David](https://img.shields.io/david/thzero/library_server)
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+
5
+ # library_server
6
+
7
+ 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; Fastify will be the focus going forward due to lack of support and updates with the Koa stack.
8
+
9
+ ### Requirements
10
+
11
+ #### NodeJs
12
+
13
+ Requires [NodeJs ](https://nodejs.org) version 22+.
14
+
15
+ ### NodeMon
16
+
17
+ ```
18
+ npm -g i nodemon
19
+ ```
20
+
21
+ ### Installation
22
+
23
+ [![NPM](https://nodei.co/npm/@thzero/library_server.png?compact=true)](https://npmjs.org/package/@thzero/library_server)
24
+
25
+ #### NPM Dependencies
26
+
27
+ Install the NPM dependencies for the server.
28
+
29
+ ```
30
+ npm install
31
+ ```
32
+
33
+ #### Mongo
34
+
35
+ Mongo is the only currently supposed option as the server side data source.
36
+
37
+ * Install the MongoDb (either locally or in the cloud) server
38
+ * Recommendation is MongoDb Atlas (https://www.mongodb.com/cloud/atlas) for development/sandbox
39
+ * Create a new MongoDb database in the Mongo server
40
+ * Restore the default SocietySidekick MongoDb
41
+ * Use the following MongoDb CLI tool to restore the default database located at (https://github.com/thzero/societySidekick-database)
42
+
43
+ ```
44
+ .\bin\mongorestore --host <mongodb host name> --ssl --username <mongo user name> --password <mongo user password> --authenticationDatabase admin -d production <location of default database>
45
+ ```
46
+
47
+ Recommended tools for managing Mongo database
48
+ * MongoDb Compass (https://www.mongodb.com/products/compass)
49
+ * Robo3T (https://robomongo.org)
50
+
51
+ #### Firebase
52
+
53
+ Google Firebase (https://firebase.google.com) provides the social based authentication; currently only Google social accounts are supported.
54
+
55
+ * Add a new project
56
+ * Setup **Authentication**, enabled Google in the **Sign-in method**.
57
+ * Get the Firebase SDK configuration
58
+ * Go to Project Overview->Settings->Service accounts
59
+ * Select **Node.js** option
60
+ * Click **Generate new private key**
61
+
62
+ #### ServiceAccountKey.json
63
+
64
+ * Copy the contents of the file that was downloaded when generating a new private key into the 'config\ServiceAccountKey.json' file.
65
+
66
+ #### Configuration
67
+
68
+ The following setup for configuration is required for an application using this library_server dependency
69
+
70
+ * Setup the configuration found in the config\development.json
71
+ * Note that this is ignored in the .gitignore
72
+ * Configuration looks like the following
73
+
74
+ ```
75
+ {
76
+ "app": {
77
+ "auth": {
78
+ "apiKey": "<generate a GUID as key in standard nomeclature '#######-####-####-####-############'>",
79
+ "claims": {
80
+ "check": <true of false, false by default>,
81
+ "useDefault": <true of false, false by default>
82
+ }
83
+ },
84
+ "cors": {
85
+ "origin": "*"
86
+ },
87
+ "db": {
88
+ "default": "mongo"
89
+ "mongo": {
90
+ "connection": "<mongo connection string>",
91
+ "name": "<environment name>"
92
+ }
93
+ },
94
+ "logging": {
95
+ "level": <see https://github.com/pinojs/pino/issues/123 for logging levels>,
96
+ "prettify": <true of false if you want prettify, if true requres 'pino-prettify' as a dependency>
97
+ },
98
+ "port": <port to run the server on>
99
+ }
100
+ }
101
+ ```
102
+
103
+ ##### Environment Variable overrides
104
+
105
+ The following environmnent variables override the above configuration settings found in the config file.
106
+
107
+ * AUTH_API_KEY
108
+ * AUTH_CLAIMS_CHECK
109
+ * AUTH_CLAIMS_USE_DEFAULT
110
+ * CORS_ORIGIN
111
+ * DB_DEFAULT
112
+ * DB_CONNECTION_ATLAS
113
+ * DB_NAME_ATLAS
114
+ * DB_CONNECTION_MONGO
115
+ * DB_NAME_MONGO
116
+ * IP_ADDRESS
117
+ * LOGGING_LEVEL
118
+ * LOGGING_PRETTIFY
119
+ * PORT
120
+
121
+ ##### Development Tool Configuration
122
+
123
+ * Include the following in the package.json for the application.
124
+
125
+ ```
126
+ "version_major": #,
127
+ "version_minor": #,
128
+ "version_patch": #,
129
+ "version_date": "MM/DD/YYYY",
130
+ ```
131
+
132
+ ## Development
133
+
134
+ ### Compile and hot-reloads for development
135
+
136
+ #### NPM CLI
137
+
138
+ Run the application server locally in debug mode with hot reloading via Nodemon.
139
+
140
+ ```
141
+ npm run debug
142
+ ```
143
+
144
+ #### Visual Code
145
+
146
+ Install VisualCode, open the 'server' folder via 'Open Folder'.
147
+
148
+ Using the Menu->Run->Start Debugging will launch the application in debug mode with hot reloading via Nodemon
149
+
150
+ ## Hosting
151
+
152
+ See Google Cloud Hosting.
153
+
154
+ ## Google Cloud Hosting
155
+
156
+ Login to Google Cloud hosting, select the same account that was setup for Firebase.
157
+
158
+ Enable the following APIs in the Enable APIs & Services section for the project.
159
+
160
+ * Cloud Source Repositories API
161
+ * Cloud Build API
162
+
163
+ ### Project's cloudbuild.yaml
164
+
165
+ Update the cloudbuild.yaml file in the source project and change the following based on your account name
166
+
167
+ ```
168
+ https://source.developers.google.com/p/<account name>/r/github_thzero_rocket_sidekick-common
169
+ ```
170
+
171
+ ### Setup Google Cloud Source Repositories
172
+
173
+ This is a mirror of the GitHub repo for the following repos:
174
+ * https://img.shields.io/github/package-json/v/thzero/rocket_sidekick-common
175
+ * https://img.shields.io/github/package-json/v/thzero/rocket_sidekick-server
176
+
177
+ * Add Repository
178
+ * Connect external repository
179
+ * Select the project setup by Firebase, then GitHub
180
+ * Select the web-common repo
181
+ * Connect selected repositories
182
+
183
+ Select repository, then permissions. Verify that the Cloud Build Service Account is listed.
184
+
185
+ ### Deploy to CloudRun
186
+
187
+ https://cloud.google.com/run/docs/continuous-deployment-with-cloud-build
188
+ https://cloud.google.com/run/docs/deploying#service
189
+
190
+ #### Settings for Cloud Run configuration
191
+
192
+ ##### Cloud Run
193
+ * Continuously deploy new revisions from a source repository
194
+ * Use Set Up With Cloud Build
195
+ * Select the Repository Provide and Repository
196
+ * Click Next
197
+ * Branch: ^master$
198
+ * Build Type: Dockerfile
199
+ * Source location: /Dockerfile
200
+ * Click Save
201
+
202
+ ##### CPU Allocation
203
+ * CPU is only allocated during request processing
204
+
205
+ ##### Revision Autoscaling
206
+ * Minimum 0
207
+ * Maximum 1000
208
+
209
+ ##### Ingress Control
210
+ * All
211
+
212
+ ##### Authentication
213
+ * Allow unauthenticated invocations
214
+
215
+ ##### Capacity
216
+ * 512mb 1 cpu
217
+ * Requested Timeout 300
218
+ * Max Request per Container 80
219
+
220
+ ##### Variables & Secrets
221
+
222
+ Add these variables:
223
+
224
+ * SERVICE_ACCOUNT_KEY - <Firebase servicecAccountKey.json file in local config folder>
225
+ * AUTH_API_KEY - <guid>
226
+ * DB_DEFAULT - atla
227
+ * DB_CONNECTION_ALTAS - <connection string>
228
+ * DB_NAME_ALTAS - production
229
+ * DB_CONNECTION_MONGO - <connection string>
230
+ * optional
231
+ * DB_NAME_MONGO - production
232
+ * optional
233
+ * LOG_LEVEL - debug
234
+ * IP_ADDRESS - 0.0.0.0
235
+
236
+ #### Cloud Source Repository
237
+
238
+ In Cloud Build, go to the Repositories section.
239
+
240
+ * Select an appropriate region, should be for the same region as your Cloud Run is running on
241
+ * Select 2nd Gen
242
+ * Link Repository to create a link to your repository
243
+
244
+ ##### Link Repository
245
+
246
+ ###### Connection
247
+ * Create a new Host Connection
248
+
249
+ ###### Region
250
+ * Select the same region as your Cloud Run is running on
251
+
252
+ ###### Name
253
+ * Set name for the connection
254
+
255
+ * Click Connect to create the connection
256
+ * You may require the Security Manager API to be enabled
257
+ * Click Continue in the confirmation dialog
258
+
259
+ ###### Github Installation
260
+ * Select an installation user or Install a new account
261
+
262
+ #### Cloud Build Trigger
263
+
264
+ ##### Event
265
+ * Push to branch
266
+
267
+ ###### Region
268
+ * Select the same region as used with the Cloud Source Repository
269
+
270
+ ###### Repository Generation
271
+ * Select 2nd
272
+
273
+ ##### Source
274
+ * Select the repository
275
+ * Select "^master$" branch
276
+
277
+ ##### Configuration
278
+
279
+ ###### Type
280
+ * Cloud Build configuration file (yaml or json)
281
+
282
+ ###### Location
283
+ * Repository
284
+ * Cloud Build configuration file location
285
+ * / cloudbuild.yaml
286
+
287
+ ##### Deploy
288
+
289
+ Run the trigger to kick of a deploy.