@ti-engine/core 1.3.6 → 1.3.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/CHANGELOG.md +10 -0
- package/README.md +47 -29
- package/bin/localization/labels.json +3 -0
- package/package.json +3 -3
- package/utils/config.js +7 -9
- package/utils/exceptions.js +6 -9
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
This document will contain the list of changes made to the framework. The format is based on the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification.
|
|
4
4
|
|
|
5
|
+
## Version 1.3.8
|
|
6
|
+
* fix(tester): fix the relative paths of various files in the tester service. The configuration now assumes that the working directory is the root of the tester package instead of the repository itself
|
|
7
|
+
* build(npm): update npm dependencies to their latest versions
|
|
8
|
+
* docs: fix some outdated information in the `README.md` file and add some more details
|
|
9
|
+
|
|
10
|
+
## Version 1.3.7
|
|
11
|
+
* feat(exceptions): add new exception code `E_SEC_UNRECOGNIZED_AUTH_METHOD`
|
|
12
|
+
* fix(config): fix potential issue with `TI_GCLOUD_ENABLED` parsing as boolean
|
|
13
|
+
* docs: adjust some of the JSDoc descriptions and definitions
|
|
14
|
+
|
|
5
15
|
## Version 1.3.6
|
|
6
16
|
* feat(exceptions): add new exception code `E_GEN_INVALID_ARGUMENT_TYPE`
|
|
7
17
|
* feat(exceptions): add public enum with all HTTP codes exported as `httpCode` and typedef `TiHttpCode`. Use it as the type for the `httpCode` exception property
|
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|

|
|
7
7
|

|
|
8
8
|
|
|
9
|
+

|
|
10
|
+
|
|
9
11
|
Flexible framework for the creation of microservices with [node.js](https://nodejs.org/).
|
|
10
12
|
|
|
11
13
|
## Introduction
|
|
@@ -36,12 +38,7 @@ To run the basic **ti-engine** framework, you will need a couple of things:
|
|
|
36
38
|
* A local [node.js installation](https://nodejs.org/en/download/) with a minimum version of **18.0.0**
|
|
37
39
|
* A local or remote [Redis cache installation](https://redis.io/download) with a minimum version of **5.0.14**
|
|
38
40
|
|
|
39
|
-
If you are working under Windows 10+ OS and you need to install Redis, take a look at this [guide](https://redis.com/blog/redis-on-windows-10/). You could also use [Redis Cloud](https://app.redislabs.com/) for development as it offers a free basic account.
|
|
40
|
-
|
|
41
|
-
* `TI_MEMORY_CACHE_AUTH_KEY` can be used to provide the Redis password if there is any at all.
|
|
42
|
-
* `TI_MEMORY_CACHE_REDIS_DB` can be used to specify the Redis DB you want to use. Make sure to set the correct number as, for example, Redis Cloud only uses DB `0`.
|
|
43
|
-
* `TI_MEMORY_CACHE_REDIS_HOST` can be used to provide the remote host. This can be an IP or URL depending on your setup.
|
|
44
|
-
* `TI_MEMORY_CACHE_REDIS_PORT` can be used to provide the remote port. By default, Redis uses `6379` however many implementations might use a custom port that needs to be specified in the connection settings.
|
|
41
|
+
If you are working under Windows 10+ OS and you need to install Redis, take a look at this [guide](https://redis.com/blog/redis-on-windows-10/). You could also use [Redis Cloud](https://app.redislabs.com/) for development as it offers a free basic account.
|
|
45
42
|
|
|
46
43
|
To get the framework itself, use the command `npm install @ti-engine/core`. And to include it directly in your package.json dependencies execute `npm install @ti-engine/core --save-prod`.
|
|
47
44
|
|
|
@@ -50,13 +47,15 @@ To get the framework itself, use the command `npm install @ti-engine/core`. And
|
|
|
50
47
|
To start using the **ti-engine**, you will have to make sure that all prerequisites are available and operational. However, before we get to the fun part, you need to also consider a couple of crucial things while working with this framework:
|
|
51
48
|
|
|
52
49
|
1. The runtime configuration of the framework can be customized using ENV variables. These can be provided to node.js in all the standard ways, but there is also an option to include an `.env` file.
|
|
53
|
-
2. It loads your framework-related custom scripts and files dynamically, but it always assumes their provided paths are relative to the _current working directory_ (i.e., it uses `process.cwd()` to resolve the file paths). Be mindful of that whenever you declare file paths in the various settings.
|
|
50
|
+
2. It loads your framework-related custom scripts and files dynamically, but it always assumes their provided paths are relative to the _current working directory_ (i.e., it uses `process.cwd()` to resolve the file paths). Be mindful of that whenever you declare relative file paths in the various settings.
|
|
51
|
+
|
|
52
|
+
### Running the tester module
|
|
54
53
|
|
|
55
54
|
Once you have everything else ready, you should download the **ti-engine** tester module with the command `npm install @ti-engine/tester`. The tester module packages an example microservice that shows the basic approach for using the framework. To make sure everything is working properly, you should try and start the tester service:
|
|
56
55
|
|
|
57
56
|
1. Open a command prompt and navigate to the directory of the tester module; it should be something like that:
|
|
58
57
|
`[path to your project]/node_modules/@ti-engine/tester`
|
|
59
|
-
2. Execute the following command `node ../core/bin/start-instance.js`. Keep in mind that the working directory for the node process has to be the one specified in point 1. Otherwise, you'll get errors that certain files cannot be found and loaded.
|
|
58
|
+
2. Execute the following command `node ../core/bin/start-instance.js`. Keep in mind that the working directory for the node process has to be the one specified in point 1. Otherwise, you'll get errors that certain files cannot be found and loaded. Also, this configuration assumes that you have an unprotected local Redis server running on the default port. If you have a different setup, you can provide the host and port via ENV variables. We'll cover that in the section [Configuring for a remote Redis server](#configuring-for-a-remote-redis-server).
|
|
60
59
|
3. If everything was done properly, you should see the following output:
|
|
61
60
|
|
|
62
61
|
```text
|
|
@@ -86,20 +85,21 @@ At the start of the output log, you can see a `NOTICE` that tells you a couple o
|
|
|
86
85
|
* The instance name - in this case `ti-tester-service`. In the terminology of the framework, this is also known as a _service domain name_.
|
|
87
86
|
* The _instance identifier_. It is an uuid string with a `ti-` prefix, that is generated by the framework at process start. It can and will be used to trace the messages during their movement through the microservice ecosystem. But more on that later.
|
|
88
87
|
|
|
89
|
-
The following five `INFO` lines inform you about the successful connections to Redis.
|
|
88
|
+
The following five `INFO` lines inform you about the successful connections to Redis. Remember, the default configuration assumes that your Redis is running on localhost, requires no password, and uses the default port.
|
|
90
89
|
|
|
91
90
|
Following that come a couple of `INFO` lines that inform you about the microservice interface state. The framework starts with the process of _business services_ registration within the service domain of the microservice `ti-tester-service` and successfully adds two such services. The necessary information for this is read from a JSON config file included in the package. We'll get into more details on what this all means in the section [Creating a microservice](#creating-a-microservice).
|
|
92
91
|
|
|
93
92
|
Once the initialization sequence has completed, the framework informs you that the microservice instance has started successfully with a `NOTICE` entry.
|
|
94
93
|
|
|
95
|
-
If the framework encountered an error during initialization
|
|
94
|
+
NOTE: If the framework encountered an error during initialization, you would see something like this instead:
|
|
96
95
|
|
|
97
96
|
```text
|
|
98
97
|
[timestamp]: [instance-id] - notice - Starting new instance of type 'ti-tester-service' with instance ID '[instance-id]'.
|
|
99
98
|
[timestamp]: [instance-id] - alert - Error detected in the instance startup script!
|
|
99
|
+
» [information about the error]
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
Finally, you should see a sequence of test execution statements with their results in JSON format. These are the results of three business service calls that are part of the default tester microservice. The final `NOTICE` should indicate that all three tests have been completed successfully.
|
|
102
|
+
Finally, you should see a sequence of test execution statements with their results in JSON format. These are the results of three business service calls that are part of the default tester microservice. The final `NOTICE` should indicate that all three tests out of three have been completed successfully.
|
|
103
103
|
|
|
104
104
|
You can now kill the node process which should show you the following two lines:
|
|
105
105
|
|
|
@@ -114,6 +114,18 @@ The tester module gets its starting configuration from an `.env` file included i
|
|
|
114
114
|
|
|
115
115
|
Before moving on, also take a good look at the file `bin/start-instance.js`. It should give you an idea of how the process of starting and stopping a microservice operates. In most cases this file should be enough as a starting script for your **ti-engine** based microservice applications. You can, of course, create your own starting script, but then you'll have to consider all necessary steps to properly handle the microservice instance.
|
|
116
116
|
|
|
117
|
+
### Configuring for a remote Redis server
|
|
118
|
+
|
|
119
|
+
You can configure your connection to a remote Redis server using the following ENV variables:
|
|
120
|
+
|
|
121
|
+
* `TI_MEMORY_CACHE_AUTH_KEY` can be used to provide the Redis password if there is any at all.
|
|
122
|
+
* `TI_MEMORY_CACHE_REDIS_DB` can be used to specify the Redis DB you want to use. Make sure to set the correct number as, for example, Redis Cloud only uses DB `0`.
|
|
123
|
+
* `TI_MEMORY_CACHE_REDIS_HOST` can be used to provide the remote host. This can be an IP or URL depending on your setup.
|
|
124
|
+
* `TI_MEMORY_CACHE_REDIS_PORT` can be used to provide the remote port. By default, Redis uses `6379` however many implementations might use a custom port that needs to be specified in the connection settings.
|
|
125
|
+
* `TI_MEMORY_CACHE_USER` can be used to specify the Redis username if this is supported by your Redis implementation.
|
|
126
|
+
|
|
127
|
+
The easiest way to configure these variables is to edit the `.env` file included in the package. You might have to do that if you want to run the tester module successfully with a remote Redis server.
|
|
128
|
+
|
|
117
129
|
## Architecture
|
|
118
130
|
|
|
119
131
|
The architectural approach for the **ti-engine** is done in _tiers_ with lower tiers being unaware of the tiers above them. The framework prefers a high level of abstraction in all its tiers and provides many options for customization and extension. While the language is JavaScript, the structuring of the framework follows the OOP principles, and you will find a lot of abstract classes and methods that require you to implement them. These are always marked with the `@abstract` annotation but if you happen to miss one, the framework will raise an `E_GEN_ABSTRACT_METHOD_CALL` exception when you try to use it in your solution.
|
|
@@ -138,7 +150,7 @@ For now, take a look at the following diagram:
|
|
|
138
150
|
|
|
139
151
|
It shows the standard flow of a message exchange between one sender and _n_ identical message receivers. The sender splits each message into an _envelope_ and a _payload_, then stores the payload in the shared cache and enqueues the envelope in the requests (destination) queue. Receivers can subscribe to that queue to fetch enqueued messages and process their contents. During the fetch sequence a receiver assembles the full message by getting the payload from the storage. This process is depicted by the blue flow lines.
|
|
140
152
|
|
|
141
|
-
After the processing is done, the message payload is modified, and the receiver sends the message back to the original sender using the same mechanism. It again splits the message into an envelope and a payload, stores the payload in the storage and enqueues the envelope in the sender response (source) queue. The sender will then assemble the message back and process the contained results. This process is depicted by the red flow lines.
|
|
153
|
+
After the processing is done, the message payload is modified, and the receiver sends the message back to the original sender using the same mechanism. It again splits the message into an envelope and a payload, stores the payload in the storage, and enqueues the envelope in the sender response (source) queue. The sender will then assemble the message back and process the contained results. This process is depicted by the red flow lines.
|
|
142
154
|
|
|
143
155
|
In this scenario the framework uses _Redis lists_ as queues for the message envelopes and _Redis hash_ as message payload storage. The splitting between envelope and payload is done to avoid unnecessary transportation of potentially large volumes of operational data between the microservices. Other message brokers might use a slightly different approach, but they should still adhere to the same logical flow.
|
|
144
156
|
|
|
@@ -169,15 +181,15 @@ This tier comprises the actual implementation of your application. Its structure
|
|
|
169
181
|
* It needs to take care of any type of stateful behavior like user sessions or transactions.
|
|
170
182
|
* It needs to act as the primary interface between users and your application, thus handling access management and user interactions.
|
|
171
183
|
|
|
172
|
-
Depending on the type of software you are building, tier 3 can be an API Gateway, a Web application, backend for a Mobile application or anything like that.
|
|
184
|
+
Depending on the type of software you are building, tier 3 can be an API Gateway, a Web application, backend for a Mobile application, or anything like that.
|
|
173
185
|
|
|
174
186
|
## Creating a microservice
|
|
175
187
|
|
|
176
188
|
Now let's walk through the process of creating a microservice with **ti-engine**. We'll start with analyzing the contents of the tester module. Then we'll proceed with creating a new microservice that can call one of the business services in the default `ti-tester-service`.
|
|
177
189
|
|
|
178
|
-
###
|
|
190
|
+
### Deconstructing the ti-tester microservice
|
|
179
191
|
|
|
180
|
-
If you managed to execute the initial framework test as explained in the [
|
|
192
|
+
If you managed to execute the initial framework test as explained in the [Running the tester module](#running-the-tester-module) section, you should already be familiar with the default ti-tester microservice. Here we'll dissect its contents even further.
|
|
181
193
|
|
|
182
194
|
Let's take a look at the files and file structure first (only relevant items are shown):
|
|
183
195
|
|
|
@@ -187,6 +199,7 @@ bin
|
|
|
187
199
|
↳ v1
|
|
188
200
|
↳ service1.js
|
|
189
201
|
↳ service2.js
|
|
202
|
+
↳ more-labels.json
|
|
190
203
|
↳ tester-service.js
|
|
191
204
|
↳ tester-service.json
|
|
192
205
|
.env
|
|
@@ -195,43 +208,45 @@ package.json
|
|
|
195
208
|
|
|
196
209
|
You don't have to follow the exact same folder structure as most of the paths can be defined via ENV parameters and in the configuration file. However, having a good clean structure helps when organizing your work in more complex projects.
|
|
197
210
|
|
|
198
|
-
In the
|
|
211
|
+
In the tester module all application files are located inside the `bin` folder. Outside you have only the `package.json` and the `.env` files which can be considered more of a configuration for the node process rather than part of the application itself. Nevertheless, let's start with them:
|
|
199
212
|
|
|
200
213
|
#### package.json contents
|
|
201
214
|
|
|
202
215
|
```json
|
|
203
216
|
{
|
|
204
217
|
"name": "@ti-engine/tester",
|
|
205
|
-
"version": "
|
|
206
|
-
"description": "
|
|
207
|
-
"author": "
|
|
208
|
-
"license": "
|
|
218
|
+
"version": "[tester module version]",
|
|
219
|
+
"description": "[tester module description]",
|
|
220
|
+
"author": "[tester module author]",
|
|
221
|
+
"license": "GPL-3.0-or-later",
|
|
209
222
|
"dependencies": {
|
|
210
223
|
"@ti-engine/core": "latest"
|
|
211
224
|
},
|
|
212
225
|
"engines": {
|
|
213
|
-
"node": "
|
|
226
|
+
"node": "[min required node version]"
|
|
214
227
|
}
|
|
215
228
|
}
|
|
216
229
|
```
|
|
217
230
|
|
|
218
|
-
Apart from the standard information properties there are only two important entries here: `"@ti-engine/core": "
|
|
231
|
+
Apart from the standard information properties there are only two important entries here: `"@ti-engine/core": "[min required core version]"` and `"node": "[min required node version]"`. The dependency on the core of the framework is set to `latest`, but as with any other npm library you should set this to a specific version when releasing on production. The minimum node version should also reflect the minimum requirements of your application and can be adjusted accordingly, but it should not go below the minimum version required by the **ti-engine** itself.
|
|
219
232
|
|
|
220
233
|
#### .env contents
|
|
221
234
|
|
|
222
235
|
```text
|
|
236
|
+
TI_INSTANCE_NAME=ti-tester-service
|
|
223
237
|
TI_INSTANCE_CLASS=bin/tester-service.js
|
|
224
238
|
TI_INSTANCE_CONFIG=bin/tester-service.json
|
|
225
|
-
TI_INSTANCE_NAME=tester-service
|
|
226
239
|
TI_AUDITING_LOG_MIN_LEVEL=200
|
|
240
|
+
TI_LOCALIZATION_LABELS_PATH=bin/more-labels.json
|
|
227
241
|
```
|
|
228
242
|
|
|
229
|
-
The ENV initialization file provides the minimal settings for the proper tester microservice operation. The first three are usually _mandatory_ for every microservice you create, while the last
|
|
243
|
+
The ENV initialization file provides the minimal settings for the proper tester microservice operation. The first three are usually _mandatory_ for every microservice you create, while the last two are provided for the needs of the tester demonstration. Let's review them and see what they do:
|
|
230
244
|
|
|
231
|
-
* `TI_INSTANCE_CLASS` specifies the relative path to the implementation of the `ServiceInstance` framework class—in this case a `ServiceProvider`. As stated above, the path is relative to the working directory of the `node` process. This variable is mandatory for every microservice you create with the **ti-engine**. If it is not provided, the microservice won't be able to start at all, and you will get an exception.
|
|
232
|
-
* `TI_INSTANCE_CONFIG` specifies the relative path to the configuration data for the microservice. We'll delve into the specific settings below. Technically, you can omit this variable, and the microservice will still start successfully with an empty configuration. There are very few cases, however, where this would be applicable.
|
|
233
245
|
* `TI_INSTANCE_NAME` is the _service domain_ name provided for the microservice. It has to be _unique_ in the context of the microservice ecosystem. If not provided, the framework will attempt to extract this information from the name of the implementation file. That is not a recommended approach, though, as it might cause hard to identify errors later.
|
|
234
|
-
* `
|
|
246
|
+
* `TI_INSTANCE_CLASS` specifies the relative path to the implementation of the `ServiceInstance` framework class—in this case a `ServiceProvider`. As stated above, the path is relative to the working directory of the `node.js` process. This variable is mandatory for every microservice you create with the **ti-engine**. If it is not provided, the microservice won't be able to start at all, and you will get an exception.
|
|
247
|
+
* `TI_INSTANCE_CONFIG` specifies the relative path to the configuration data for the microservice. We'll delve into the specific settings below. Technically, you can omit this variable, and the microservice will still start successfully with an empty configuration. There are very few cases, however, where this would be applicable.
|
|
248
|
+
* `TI_AUDITING_LOG_MIN_LEVEL` specifies the minimum log level that should be sent to the log output stream. With a setting of `200` (corresponding to `INFO`) we filter out all `DEFAULT (0)` and `DEBUG (100)` entries as we don't need them for the tester microservice.
|
|
249
|
+
* `TI_LOCALIZATION_LABELS_PATH` specifies the relative path to the additional localization labels file. This is optional and can be omitted if you don't need custom labels for your microservice.
|
|
235
250
|
|
|
236
251
|
You can find the full list of available ENV variables and what they do below in [Using the framework](#using-the-framework) section.
|
|
237
252
|
|
|
@@ -242,10 +257,13 @@ Now let's look inside the `bin` folder. The two files there are the ones specifi
|
|
|
242
257
|
* Method `onStart` overrides the base one from the parent class and is invoked automatically by the framework once initialization of the microservice is complete. In this case the method invokes the execution of the test sequence just once, and then the microservice remains dormant but active.
|
|
243
258
|
* Method `reportHealthy` overrides but essentially just calls the same base method. Its only purpose here is to draw your attention to its existence and the possibility to implement your own health status reporting functionality if you want.
|
|
244
259
|
* Method `verifyAccess` also overrides the base method and shows a very basic example of how to implement user access verification on business service level. Each time a service in the `ti-tester-service` is called, the framework will trigger this method and will only allow processing if there is a non-undefined value inside the `authToken` variable.
|
|
245
|
-
* Method `#executeTests` is a custom private method that contains the test sequence itself. It is called by the `onStart` method just once per microservice start.
|
|
260
|
+
* Method `#executeTests` is a custom private method that contains the test execution sequence itself. It is called by the `onStart` method just once per microservice start.
|
|
261
|
+
* Method `#assertService` is an assertion wrapper around a standard service call request. Inside it, you can see how a business service is invoked and how the results should be handled.
|
|
246
262
|
|
|
247
263
|
The file `tester-service.json` contains framework configuration for the tester microservice. It will be automatically loaded inside the `ServiceInstance` class during initialization and will already be available inside the `onStart` method for usage. In this case the configuration is related to the two business services that will be provided by the microservice. More on this topic will be covered in the section [Using the framework](#using-the-framework). For now pay attention to the `serviceFile` parameter and that it once again provides a relative path to the actual file containing the business logic.
|
|
248
264
|
|
|
265
|
+
The file `more-labels.json` contains one additional localization label for the tester microservice and is only used to demonstrate how to add custom labels to the microservice. For more information on localization, see the section [Localization](#localization).
|
|
266
|
+
|
|
249
267
|
The final two files are located in `bin/services/v1/` folder. They contain the definitions and business logic of the two business services that will be loaded at initialization time and provided by the tester microservice. In this case `service1.js` contains a basic service that returns the current timestamp. The `service2.js` file contains a slightly more complex example of a service calling another service (in this case `service1`) before also returning two timestamps taken at the beginning and end of execution. Pay attention to the way the methods inside are declared and exported as this is the proper way to do this while using the **ti-engine** framework. Once again, we'll delve into the details and specifics of creating business services in the section [Using the framework](#using-the-framework).
|
|
250
268
|
|
|
251
269
|
### Creating your own microservice
|
|
@@ -253,9 +271,9 @@ The final two files are located in `bin/services/v1/` folder. They contain the d
|
|
|
253
271
|
Now that we've seen the structure of the tester microservice, let's create a new one and make it call `service2`. Let's use the same file structure as for the tester. Create a folder `my-service` and in it create a `package.json` file. Make sure to include a dependency to `"@ti-engine/core": "latest"` in it. After that create a `.env` file and add the following entries in it:
|
|
254
272
|
|
|
255
273
|
```text
|
|
274
|
+
TI_INSTANCE_NAME=my-service
|
|
256
275
|
TI_INSTANCE_CLASS=bin/my-service.js
|
|
257
276
|
TI_INSTANCE_CONFIG=bin/my-service.json
|
|
258
|
-
TI_INSTANCE_NAME=my-service
|
|
259
277
|
TI_AUDITING_LOG_MIN_LEVEL=200
|
|
260
278
|
```
|
|
261
279
|
|
|
@@ -40,6 +40,9 @@
|
|
|
40
40
|
"2003": {
|
|
41
41
|
"en": "The system detected tampering with the message received via message exchange."
|
|
42
42
|
},
|
|
43
|
+
"2004": {
|
|
44
|
+
"en": "The requested authentication method is not recognized or supported."
|
|
45
|
+
},
|
|
43
46
|
"3000": {
|
|
44
47
|
"en": "General error during cross-application communication."
|
|
45
48
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ti-engine/core",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8",
|
|
4
4
|
"description": "The ti-engine is an open source, free to use—both for personal and commercial projects—framework for the creation of microservice-based solutions using node.js.",
|
|
5
5
|
"author": "Boris Kostadinov <kostadinov.boris@gmail.com>",
|
|
6
6
|
"license": "GPL-3.0-or-later",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"blake2": "^5.0.0",
|
|
50
|
-
"@dotenvx/dotenvx": "^1.
|
|
50
|
+
"@dotenvx/dotenvx": "^1.51.0",
|
|
51
51
|
"lodash": "^4.17.21",
|
|
52
52
|
"node-schedule": "^2.1.1",
|
|
53
|
-
"ioredis": "^5.
|
|
53
|
+
"ioredis": "^5.8.0"
|
|
54
54
|
},
|
|
55
55
|
"optionalDependencies": {
|
|
56
56
|
"@google-cloud/error-reporting": "^3.0.5",
|
package/utils/config.js
CHANGED
|
@@ -112,6 +112,7 @@ const tools = require( "#tools" );
|
|
|
112
112
|
*
|
|
113
113
|
* @readonly
|
|
114
114
|
* @enum {string} Keys of this ENUM are strings.
|
|
115
|
+
* @typedef {string} TiSetting
|
|
115
116
|
*/
|
|
116
117
|
const settingsEnum = tools.enum( {
|
|
117
118
|
AUDITING_LOG_CONSOLE_ENABLED: [ "auditing.logConsoleEnabled", "logConsoleEnabled", "" ],
|
|
@@ -144,9 +145,6 @@ const settingsEnum = tools.enum( {
|
|
|
144
145
|
OPERATION_MODE: [ "operationMode", "operationMode", "" ]
|
|
145
146
|
} );
|
|
146
147
|
|
|
147
|
-
/**
|
|
148
|
-
* @typedef {string} TiSetting
|
|
149
|
-
*/
|
|
150
148
|
module.exports.setting = settingsEnum;
|
|
151
149
|
|
|
152
150
|
/** @type {SettingsMain} */
|
|
@@ -165,11 +163,11 @@ if ( settings.localization ) {
|
|
|
165
163
|
}
|
|
166
164
|
if ( settings.memoryCache ) {
|
|
167
165
|
settings.memoryCache.authKey = ( process.env.TI_MEMORY_CACHE_AUTH_KEY !== undefined ) ? process.env.TI_MEMORY_CACHE_AUTH_KEY : settings.memoryCache.authKey;
|
|
168
|
-
settings.memoryCache.redisDB = ( process.env.TI_MEMORY_CACHE_REDIS_DB !== undefined ) ? process.env.TI_MEMORY_CACHE_REDIS_DB : settings.memoryCache.redisDB;
|
|
166
|
+
settings.memoryCache.redisDB = ( process.env.TI_MEMORY_CACHE_REDIS_DB !== undefined ) ? Number( process.env.TI_MEMORY_CACHE_REDIS_DB ) : settings.memoryCache.redisDB;
|
|
169
167
|
settings.memoryCache.redisHost = ( process.env.TI_MEMORY_CACHE_REDIS_HOST !== undefined ) ? process.env.TI_MEMORY_CACHE_REDIS_HOST : settings.memoryCache.redisHost;
|
|
170
|
-
settings.memoryCache.redisPort = ( process.env.TI_MEMORY_CACHE_REDIS_PORT !== undefined ) ? process.env.TI_MEMORY_CACHE_REDIS_PORT : settings.memoryCache.redisPort;
|
|
171
|
-
settings.memoryCache.retryMaxAttempts = ( process.env.TI_MEMORY_CACHE_RETRY_MAX_ATTEMPTS !== undefined ) ? process.env.TI_MEMORY_CACHE_RETRY_MAX_ATTEMPTS : settings.memoryCache.retryMaxAttempts;
|
|
172
|
-
settings.memoryCache.retryMaxInterval = ( process.env.TI_MEMORY_CACHE_RETRY_MAX_INTERVAL !== undefined ) ? process.env.TI_MEMORY_CACHE_RETRY_MAX_INTERVAL : settings.memoryCache.retryMaxInterval;
|
|
168
|
+
settings.memoryCache.redisPort = ( process.env.TI_MEMORY_CACHE_REDIS_PORT !== undefined ) ? Number( process.env.TI_MEMORY_CACHE_REDIS_PORT ) : settings.memoryCache.redisPort;
|
|
169
|
+
settings.memoryCache.retryMaxAttempts = ( process.env.TI_MEMORY_CACHE_RETRY_MAX_ATTEMPTS !== undefined ) ? Number( process.env.TI_MEMORY_CACHE_RETRY_MAX_ATTEMPTS ) : settings.memoryCache.retryMaxAttempts;
|
|
170
|
+
settings.memoryCache.retryMaxInterval = ( process.env.TI_MEMORY_CACHE_RETRY_MAX_INTERVAL !== undefined ) ? Number( process.env.TI_MEMORY_CACHE_RETRY_MAX_INTERVAL ) : settings.memoryCache.retryMaxInterval;
|
|
173
171
|
settings.memoryCache.user = ( process.env.TI_MEMORY_CACHE_USER !== undefined ) ? process.env.TI_MEMORY_CACHE_USER : settings.memoryCache.user;
|
|
174
172
|
}
|
|
175
173
|
if ( settings.messageExchange ) {
|
|
@@ -178,8 +176,8 @@ if ( settings.messageExchange ) {
|
|
|
178
176
|
settings.messageExchange.traceLogEnabled = ( process.env.TI_MESSAGE_EXCHANGE_TRACE_LOG_ENABLED !== undefined ) ? tools.toBool( process.env.TI_MESSAGE_EXCHANGE_TRACE_LOG_ENABLED ) : settings.messageExchange.traceLogEnabled;
|
|
179
177
|
}
|
|
180
178
|
|
|
181
|
-
//
|
|
182
|
-
if ( process.env.TI_GCLOUD_ENABLED === true && settings.gcloudIntegration ) {
|
|
179
|
+
// Make sure GCloud is enabled before trying to set it up:
|
|
180
|
+
if ( tools.toBool( process.env.TI_GCLOUD_ENABLED ) === true && settings.gcloudIntegration ) {
|
|
183
181
|
settings.gcloudIntegration.apiKey = ( process.env.TI_GCLOUD_API_KEY !== undefined ) ? process.env.TI_GCLOUD_API_KEY : settings.gcloudIntegration.apiKey;
|
|
184
182
|
settings.gcloudIntegration.projectID = ( process.env.TI_GCLOUD_PROJECT_ID !== undefined ) ? process.env.TI_GCLOUD_PROJECT_ID : settings.gcloudIntegration.projectID;
|
|
185
183
|
}
|
package/utils/exceptions.js
CHANGED
|
@@ -14,6 +14,7 @@ const tools = require( "#tools" );
|
|
|
14
14
|
*
|
|
15
15
|
* @readonly
|
|
16
16
|
* @enum {number}
|
|
17
|
+
* @typedef {number} TiExceptionCode
|
|
17
18
|
*/
|
|
18
19
|
const exceptionCodeEnum = tools.enum( {
|
|
19
20
|
E_UNKNOWN_ERROR: [ 0, "unknown error", "Unidentified error encountered or unrecognized exception code provided." ],
|
|
@@ -31,6 +32,7 @@ const exceptionCodeEnum = tools.enum( {
|
|
|
31
32
|
E_SEC_INVALID_EXPIRED_SESSION: [ 2001, "invalid or expired session", "Invalid or expired session encountered." ],
|
|
32
33
|
E_SEC_UNAUTHORIZED_ACCESS: [ 2002, "unauthorized access", "Attempt for unauthorized access detected." ],
|
|
33
34
|
E_SEC_MESSAGE_TAMPERING_DETECTED: [ 2003, "message tampering detected", "The system detected tampering with the message received via message exchange." ],
|
|
35
|
+
E_SEC_UNRECOGNIZED_AUTH_METHOD: [ 2004, "unrecognized auth method", "The requested authentication method is not recognized or supported." ],
|
|
34
36
|
/** Cross-Application Communication exceptions - codes under 3xxx */
|
|
35
37
|
E_COM_GENERAL_ERROR: [ 3000, "general communication error", "General error during cross-application communication." ],
|
|
36
38
|
E_COM_MESSAGE_SENDER_UNAVAILABLE: [ 3001, "message sender unavailable", "The message sender instance is currently unavailable." ],
|
|
@@ -54,11 +56,14 @@ const exceptionCodeEnum = tools.enum( {
|
|
|
54
56
|
E_WEB_INVALID_REQUEST_CONTENT_ENCODING: [ 4009, "invalid request content encoding", "The request content encoding is not recognized or not supported." ]
|
|
55
57
|
} );
|
|
56
58
|
|
|
59
|
+
module.exports.exceptionCode = exceptionCodeEnum;
|
|
60
|
+
|
|
57
61
|
/**
|
|
58
62
|
* Enum for listing all HTTP codes.
|
|
59
63
|
*
|
|
60
64
|
* @readonly
|
|
61
65
|
* @enum {number}
|
|
66
|
+
* @typedef {number} TiHttpCode
|
|
62
67
|
*/
|
|
63
68
|
const httpCodeEnum = tools.enum( {
|
|
64
69
|
/** 1xx informational response */
|
|
@@ -127,14 +132,6 @@ const httpCodeEnum = tools.enum( {
|
|
|
127
132
|
C_511: [ 511, "Network Authentication Required", "The client needs to authenticate to gain network access. Intended for use by intercepting proxies used to control access to the network." ]
|
|
128
133
|
} );
|
|
129
134
|
|
|
130
|
-
/**
|
|
131
|
-
* @typedef {number} TiExceptionCode
|
|
132
|
-
*/
|
|
133
|
-
module.exports.exceptionCode = exceptionCodeEnum;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @typedef {number} TiHttpCode
|
|
137
|
-
*/
|
|
138
135
|
module.exports.httpCode = httpCodeEnum;
|
|
139
136
|
|
|
140
137
|
const labelPath = "system.exceptions.";
|
|
@@ -166,7 +163,7 @@ class Exception {
|
|
|
166
163
|
|
|
167
164
|
this.#id = id;
|
|
168
165
|
this.#code = exceptionCode;
|
|
169
|
-
this.#label = labelPath + exceptionCode;
|
|
166
|
+
this.#label = labelPath + String( exceptionCode );
|
|
170
167
|
this.#description = description || exceptionCodeEnum.description( exceptionCode );
|
|
171
168
|
this.#data = data || {};
|
|
172
169
|
}
|