@ikonintegration/ikapi 4.0.0-alpha9 → 5.0.0-alpha1
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/.eslintignore +3 -0
- package/.eslintrc.cjs +81 -0
- package/.github/workflows/npmpublish.yml +8 -19
- package/.github/workflows/prs.yml +12 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/package-lock.json +11886 -0
- package/dist/package.json +81 -0
- package/dist/src/API/Request.d.ts +125 -0
- package/dist/src/API/Request.js +185 -0
- package/dist/src/API/Request.js.map +1 -0
- package/dist/src/API/Response.d.ts +188 -0
- package/dist/src/API/Response.js +270 -0
- package/dist/src/API/Response.js.map +1 -0
- package/dist/src/BaseEvent/DynamoTransaction.d.ts +20 -0
- package/dist/src/BaseEvent/DynamoTransaction.js +81 -0
- package/dist/src/BaseEvent/DynamoTransaction.js.map +1 -0
- package/dist/src/BaseEvent/EventProcessor.d.ts +58 -0
- package/dist/src/BaseEvent/EventProcessor.js +101 -0
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
- package/dist/src/BaseEvent/Process.d.ts +50 -0
- package/dist/src/BaseEvent/Process.js +64 -0
- package/dist/src/BaseEvent/Process.js.map +1 -0
- package/dist/src/BaseEvent/StepTransaction.d.ts +23 -0
- package/dist/src/BaseEvent/StepTransaction.js +27 -0
- package/dist/src/BaseEvent/StepTransaction.js.map +1 -0
- package/dist/src/BaseEvent/Transaction.d.ts +149 -0
- package/dist/src/BaseEvent/Transaction.js +224 -0
- package/dist/src/BaseEvent/Transaction.js.map +1 -0
- package/dist/src/Cache/Redis.d.ts +29 -0
- package/dist/src/Cache/Redis.js +80 -0
- package/dist/src/Cache/Redis.js.map +1 -0
- package/dist/src/Cache/types.d.ts +31 -0
- package/dist/src/Cache/types.js +2 -0
- package/dist/src/Cache/types.js.map +1 -0
- package/dist/src/Config/Configuration.d.ts +123 -0
- package/dist/src/Config/Configuration.js +109 -0
- package/dist/src/Config/Configuration.js.map +1 -0
- package/dist/src/Config/EnvironmentVar.d.ts +74 -0
- package/dist/src/Config/EnvironmentVar.js +138 -0
- package/dist/src/Config/EnvironmentVar.js.map +1 -0
- package/dist/src/Crypto/Crypto.d.ts +45 -0
- package/dist/src/Crypto/Crypto.js +72 -0
- package/dist/src/Crypto/Crypto.js.map +1 -0
- package/dist/src/Database/Database.d.ts +21 -0
- package/dist/src/Database/Database.js +15 -0
- package/dist/src/Database/Database.js.map +1 -0
- package/dist/src/Database/DatabaseManager.d.ts +47 -0
- package/dist/src/Database/DatabaseManager.js +60 -0
- package/dist/src/Database/DatabaseManager.js.map +1 -0
- package/dist/src/Database/DatabaseTransaction.d.ts +101 -0
- package/dist/src/Database/DatabaseTransaction.js +126 -0
- package/dist/src/Database/DatabaseTransaction.js.map +1 -0
- package/dist/src/Database/index.d.ts +10 -0
- package/dist/src/Database/index.js +15 -0
- package/dist/src/Database/index.js.map +1 -0
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +35 -0
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +59 -0
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +1 -0
- package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +66 -0
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js +86 -0
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -0
- package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +70 -0
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js +118 -0
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +36 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +54 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +63 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +61 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
- package/dist/src/Database/types.d.ts +76 -0
- package/dist/src/Database/types.js +2 -0
- package/dist/src/Database/types.js.map +1 -0
- package/dist/src/Globals.d.ts +93 -0
- package/dist/src/Globals.js +99 -0
- package/dist/src/Globals.js.map +1 -0
- package/dist/src/Logger/Logger.d.ts +161 -0
- package/dist/src/Logger/Logger.js +297 -0
- package/dist/src/Logger/Logger.js.map +1 -0
- package/dist/src/Mailer/Mailer.d.ts +78 -0
- package/dist/src/Mailer/Mailer.js +182 -0
- package/dist/src/Mailer/Mailer.js.map +1 -0
- package/dist/src/Publisher/Publisher.d.ts +39 -0
- package/dist/src/Publisher/Publisher.js +77 -0
- package/dist/src/Publisher/Publisher.js.map +1 -0
- package/dist/src/Server/RouteResolver.d.ts +33 -0
- package/dist/src/Server/RouteResolver.js +100 -0
- package/dist/src/Server/RouteResolver.js.map +1 -0
- package/dist/src/Server/Router.d.ts +157 -0
- package/dist/src/Server/Router.js +32 -0
- package/dist/src/Server/Router.js.map +1 -0
- package/dist/src/Server/lib/ContainerServer.d.ts +42 -0
- package/dist/src/Server/lib/ContainerServer.js +66 -0
- package/dist/src/Server/lib/ContainerServer.js.map +1 -0
- package/dist/src/Server/lib/Server.d.ts +45 -0
- package/dist/src/Server/lib/Server.js +93 -0
- package/dist/src/Server/lib/Server.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandler.d.ts +9 -0
- package/dist/src/Server/lib/container/GenericHandler.js +82 -0
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +52 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +132 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
- package/dist/src/Server/lib/container/HealthHandler.d.ts +9 -0
- package/dist/src/Server/lib/container/HealthHandler.js +19 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
- package/dist/src/Server/lib/container/Proxy.d.ts +67 -0
- package/dist/src/Server/lib/container/Proxy.js +143 -0
- package/dist/src/Server/lib/container/Proxy.js.map +1 -0
- package/dist/src/Server/lib/container/Utils.d.ts +14 -0
- package/dist/src/Server/lib/container/Utils.js +37 -0
- package/dist/src/Server/lib/container/Utils.js.map +1 -0
- package/dist/src/Util/AsyncSingleton.d.ts +31 -0
- package/dist/src/Util/AsyncSingleton.js +83 -0
- package/dist/src/Util/AsyncSingleton.js.map +1 -0
- package/dist/src/Util/Utils.d.ts +61 -0
- package/dist/src/Util/Utils.js +147 -0
- package/dist/src/Util/Utils.js.map +1 -0
- package/dist/src/Validation/Validator.d.ts +17 -0
- package/dist/src/Validation/Validator.js +39 -0
- package/dist/src/Validation/Validator.js.map +1 -0
- package/index.ts +41 -0
- package/jest.config.ts +37 -0
- package/jest.smoke.config.ts +34 -0
- package/package.json +66 -22
- package/src/API/Request.ts +214 -0
- package/src/API/Response.ts +370 -0
- package/src/BaseEvent/DynamoTransaction.ts +125 -0
- package/src/BaseEvent/EventProcessor.ts +140 -0
- package/src/BaseEvent/Process.ts +78 -0
- package/src/BaseEvent/StepTransaction.ts +35 -0
- package/src/BaseEvent/Transaction.ts +323 -0
- package/src/Cache/Redis.ts +89 -0
- package/src/Cache/types.ts +33 -0
- package/src/Config/Configuration.ts +199 -0
- package/src/Config/EnvironmentVar.ts +147 -0
- package/src/Crypto/Crypto.ts +89 -0
- package/src/Database/Database.ts +22 -0
- package/src/Database/DatabaseManager.ts +67 -0
- package/src/Database/DatabaseTransaction.ts +170 -0
- package/src/Database/index.ts +27 -0
- package/src/Database/integrations/dynamo/DynamoDatabase.ts +58 -0
- package/src/Database/integrations/kysely/KyselyDatabase.ts +99 -0
- package/src/Database/integrations/kysely/KyselyTransaction.ts +172 -0
- package/src/Database/integrations/pgsql/PostgresDatabase.ts +56 -0
- package/src/Database/integrations/pgsql/PostgresTransaction.ts +87 -0
- package/src/Database/types.ts +85 -0
- package/src/Globals.ts +103 -0
- package/src/Logger/Logger.ts +360 -0
- package/src/Mailer/Mailer.ts +217 -0
- package/src/Publisher/Publisher.ts +96 -0
- package/src/Server/RouteResolver.ts +124 -0
- package/src/Server/Router.ts +200 -0
- package/src/Server/lib/ContainerServer.ts +65 -0
- package/src/Server/lib/Server.ts +109 -0
- package/src/Server/lib/container/GenericHandler.ts +76 -0
- package/src/Server/lib/container/GenericHandlerEvent.ts +154 -0
- package/src/Server/lib/container/HealthHandler.ts +11 -0
- package/src/Server/lib/container/Proxy.ts +172 -0
- package/src/Server/lib/container/Utils.ts +33 -0
- package/src/Util/AsyncSingleton.ts +86 -0
- package/src/Util/Utils.ts +131 -0
- package/src/Validation/Validator.ts +45 -0
- package/tests/API/Request.test.ts +273 -0
- package/tests/API/Response.test.ts +367 -0
- package/tests/BaseEvent/DynamoTransaction.test.ts +272 -0
- package/tests/BaseEvent/EventProcessor.test.ts +263 -0
- package/tests/BaseEvent/Process.test.ts +47 -0
- package/tests/BaseEvent/StepTransaction.test.ts +44 -0
- package/tests/BaseEvent/Transaction.test.ts +402 -0
- package/tests/Cache/Redis-client.test.ts +90 -0
- package/tests/Cache/Redis-cluster.test.ts +100 -0
- package/tests/Config/Config.test.ts +205 -0
- package/tests/Config/EnvironmentVar.test.ts +251 -0
- package/tests/Crypto/Crypto.test.ts +88 -0
- package/tests/Database/DatabaseManager.test.ts +79 -0
- package/tests/Database/integrations/dynamo/DynamoDatabase.test.ts +44 -0
- package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +113 -0
- package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +119 -0
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +76 -0
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +118 -0
- package/tests/Logger/Logger.test.ts +215 -0
- package/tests/Mailer/Mailer.test.ts +59 -0
- package/tests/Publisher/Publisher.test.ts +60 -0
- package/tests/Server/RouteResolver.test.ts +116 -0
- package/tests/Server/Router.test.ts +39 -0
- package/tests/Server/lib/ContainerServer.test.ts +531 -0
- package/tests/Server/lib/Server.test.ts +12 -0
- package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
- package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
- package/tests/Server/lib/container/Proxy.test.ts +268 -0
- package/tests/Server/lib/container/Utils.test.ts +47 -0
- package/tests/Test.utils.ts +78 -0
- package/tests/Utils/Utils.test.ts +230 -0
- package/tests/Validation/Validator.test.ts +82 -0
- package/tsconfig.json +26 -0
- package/tsconfig.smoke.json +26 -0
- package/index.js +0 -88
- package/src/API/IKRequest.js +0 -52
- package/src/API/IKResponse.js +0 -119
- package/src/API/IKUtils.js +0 -51
- package/src/BaseEvent/IKProcess.js +0 -77
- package/src/BaseEvent/IKTransaction.js +0 -139
- package/src/Cache/Prototype/IKCache.js +0 -17
- package/src/Cache/Redis/IKRedis.js +0 -148
- package/src/Database/DDB/IKDB.js +0 -56
- package/src/Database/DDB/IKDBBaseExpression.js +0 -130
- package/src/Database/DDB/IKDBBaseQuery.js +0 -151
- package/src/Database/DDB/IKDBQueryBatchGet.js +0 -37
- package/src/Database/DDB/IKDBQueryBatchWrite.js +0 -64
- package/src/Database/DDB/IKDBQueryDelete.js +0 -34
- package/src/Database/DDB/IKDBQueryGet.js +0 -48
- package/src/Database/DDB/IKDBQueryPut.js +0 -87
- package/src/Database/DDB/IKDBQueryScan.js +0 -45
- package/src/Database/DDB/IKDBQueryTransactionalWrite.js +0 -69
- package/src/Database/DDB/IKDBQueryUpdate.js +0 -219
- package/src/Database/DDB/_IKDBQueryTransactionalRead.js +0 -46
- package/src/Database/PSQL/IKDB.js +0 -41
- package/src/Database/PSQL/IKDBBaseQuery.js +0 -26
- package/src/Database/Prototype/IKDB.js +0 -21
- package/src/Database/Prototype/IKDBBaseQuery.js +0 -14
- package/src/IKDynamoStream.js +0 -42
- package/src/IKEventProcessor.js +0 -42
- package/src/IKGlobals.js +0 -24
- package/src/IKRouter.js +0 -47
- package/src/IKStepTransaction.js +0 -14
- package/src/Logger/IKLogger.js +0 -136
- package/src/Mailer/IKMailer.js +0 -68
- package/src/Publisher/IKPublisher.js +0 -44
- package/src/Tracker/IKExecutionTracker.js +0 -79
- package/src/Validation/IKValidation.js +0 -77
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
import Utils from './Util/Utils.js';
|
|
3
|
+
// important for dev env to load .env file
|
|
4
|
+
dotenv.config();
|
|
5
|
+
/**
|
|
6
|
+
* Class containing global constants and configurations for the application.
|
|
7
|
+
*/
|
|
8
|
+
class Globals {
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A constant string representing an error message for input validation failure.
|
|
12
|
+
*/
|
|
13
|
+
Globals.ErrorResponseValidationFail = 'Input validation failed: '; //400
|
|
14
|
+
/**
|
|
15
|
+
* A constant string representing an error response for an invalid server response.
|
|
16
|
+
*/
|
|
17
|
+
Globals.ErrorResponseInvalidServerResponse = 'No valid response, this is a system error.'; //400
|
|
18
|
+
/**
|
|
19
|
+
* The error message for an unhandled error when processing a request.
|
|
20
|
+
*/
|
|
21
|
+
Globals.ErrorResponseUnhandledError = 'Unhandled error when processing request.'; //400
|
|
22
|
+
/**
|
|
23
|
+
* A static string representing an error response when there are no records to be processed.
|
|
24
|
+
*/
|
|
25
|
+
Globals.ErrorResponseNoRecords = 'No events to be processed.'; //400
|
|
26
|
+
/**
|
|
27
|
+
* Represents an error code for a missing parameter.
|
|
28
|
+
* @type {string}
|
|
29
|
+
*/
|
|
30
|
+
Globals.ErrorCode_MissingParam = 'MISSING_PARAM';
|
|
31
|
+
/**
|
|
32
|
+
* Represents an error code for invalid input.
|
|
33
|
+
* @type {string}
|
|
34
|
+
*/
|
|
35
|
+
Globals.ErrorCode_InvalidInput = 'INVALID_INPUT';
|
|
36
|
+
/**
|
|
37
|
+
* Represents an error code for an API error.
|
|
38
|
+
* @type {string}
|
|
39
|
+
*/
|
|
40
|
+
Globals.ErrorCode_APIError = 'API_ERROR';
|
|
41
|
+
/**
|
|
42
|
+
* Represents the error code for when there are no records found.
|
|
43
|
+
* @type {string}
|
|
44
|
+
*/
|
|
45
|
+
Globals.ErrorCode_NoRecords = 'EMPTY_EVENT';
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the default port number for HTTP listeners.
|
|
48
|
+
* The port number is obtained from the environment variable "PORT" and parsed as an integer.
|
|
49
|
+
* If the environment variable is not set or cannot be parsed as an integer, the default port number 9000 is used.
|
|
50
|
+
* @returns {number} - The default port number for HTTP listeners.
|
|
51
|
+
*/
|
|
52
|
+
Globals.Listener_HTTP_DefaultPort = Utils.parseIntNullIfNaN(process.env.PORT) || 9000;
|
|
53
|
+
/**
|
|
54
|
+
* The default host for the HTTP listener.
|
|
55
|
+
*/
|
|
56
|
+
Globals.Listener_HTTP_DefaultHost = 'localhost';
|
|
57
|
+
/**
|
|
58
|
+
* The HTTP proxy route listener for all routes.
|
|
59
|
+
* @type {string}
|
|
60
|
+
*/
|
|
61
|
+
Globals.Listener_HTTP_ProxyRoute = '*';
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves the default timeout value for HTTP listeners.
|
|
64
|
+
* @returns {number} The default timeout value in milliseconds.
|
|
65
|
+
*/
|
|
66
|
+
Globals.Listener_HTTP_DefaultTimeout = Utils.parseIntNullIfNaN(process.env.TIMEOUT) || 30000;
|
|
67
|
+
/**
|
|
68
|
+
* The default health check route for the HTTP listener.
|
|
69
|
+
* @type {string}
|
|
70
|
+
*/
|
|
71
|
+
Globals.Listener_HTTP_DefaultHealthCheckRoute = process.env.HEALTH_ROUTE || '/health';
|
|
72
|
+
/**
|
|
73
|
+
* The response message for an exception that occurred during request execution in the Proxy.
|
|
74
|
+
*/
|
|
75
|
+
Globals.Resp_MSG_EXCEPTION = '[Proxy]: Exception during request execution!';
|
|
76
|
+
/**
|
|
77
|
+
* The response code for an exception that occurred during execution.
|
|
78
|
+
*/
|
|
79
|
+
Globals.Resp_CODE_EXCEPTION = 'EXEC_EXCEPTION';
|
|
80
|
+
/**
|
|
81
|
+
* The HTTP response status code for an exception scenario.
|
|
82
|
+
*/
|
|
83
|
+
Globals.Resp_STATUSCODE_EXCEPTION = 502;
|
|
84
|
+
/**
|
|
85
|
+
* The error message for an invalid response from the server.
|
|
86
|
+
*/
|
|
87
|
+
Globals.Resp_MSG_INVALIDRESP = '[Proxy]: Invalid response from server!';
|
|
88
|
+
/**
|
|
89
|
+
* Represents the response code for an invalid response.
|
|
90
|
+
*/
|
|
91
|
+
Globals.Resp_CODE_INVALIDRESP = 'EMPTY_RESPONSE';
|
|
92
|
+
/**
|
|
93
|
+
* The HTTP response status code for an invalid response.
|
|
94
|
+
* @type {number}
|
|
95
|
+
* @default 400
|
|
96
|
+
*/
|
|
97
|
+
Globals.Resp_STATUSCODE_INVALIDRESP = 400;
|
|
98
|
+
export default Globals;
|
|
99
|
+
//# sourceMappingURL=Globals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Globals.js","sourceRoot":"","sources":["../../src/Globals.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B,OAAO,KAAK,MAAM,iBAAiB,CAAA;AAEnC,0CAA0C;AAC1C,MAAM,CAAC,MAAM,EAAE,CAAA;AAEf;;GAEG;AACH,MAAqB,OAAO;;AAC1B;;GAEG;AACW,mCAA2B,GAAG,2BAA2B,CAAA,CAAC,KAAK;AAC7E;;GAEG;AACW,0CAAkC,GAAG,4CAA4C,CAAA,CAAC,KAAK;AACrG;;GAEG;AACW,mCAA2B,GAAG,0CAA0C,CAAA,CAAC,KAAK;AAC5F;;GAEG;AACW,8BAAsB,GAAG,4BAA4B,CAAA,CAAC,KAAK;AACzE;;;GAGG;AACW,8BAAsB,GAAG,eAAe,CAAA;AACtD;;;GAGG;AACW,8BAAsB,GAAG,eAAe,CAAA;AACtD;;;GAGG;AACW,0BAAkB,GAAG,WAAW,CAAA;AAC9C;;;GAGG;AACW,2BAAmB,GAAG,aAAa,CAAA;AAEjD;;;;;GAKG;AACW,iCAAyB,GAAG,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAA;AAC3F;;GAEG;AACW,iCAAyB,GAAG,WAAW,CAAA;AACrD;;;GAGG;AACW,gCAAwB,GAAG,GAAG,CAAA;AAC5C;;;GAGG;AACW,oCAA4B,GAAG,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,CAAA;AAClG;;;GAGG;AACW,6CAAqC,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,SAAS,CAAA;AAE3F;;GAEG;AACW,0BAAkB,GAAG,8CAA8C,CAAA;AACjF;;GAEG;AACW,2BAAmB,GAAG,gBAAgB,CAAA;AACpD;;GAEG;AACW,iCAAyB,GAAG,GAAG,CAAA;AAE7C;;GAEG;AACW,4BAAoB,GAAG,wCAAwC,CAAA;AAC7E;;GAEG;AACW,6BAAqB,GAAG,gBAAgB,CAAA;AACtD;;;;GAIG;AACW,mCAA2B,GAAG,GAAG,CAAA;eA3F5B,OAAO"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration of log levels.
|
|
3
|
+
* @enum {string}
|
|
4
|
+
* @property {string} DEBUG - Debug log level.
|
|
5
|
+
* @property {string} INFO - Info log level.
|
|
6
|
+
* @property {string} WARN - Warning log level.
|
|
7
|
+
* @property {string} ERROR - Error log level.
|
|
8
|
+
*/
|
|
9
|
+
export declare enum LOG_LEVELS {
|
|
10
|
+
DEBUG = "DEBUG",
|
|
11
|
+
INFO = "INFO",
|
|
12
|
+
WARN = "WARN",
|
|
13
|
+
ERROR = "ERROR"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Configuration options for the logger.
|
|
17
|
+
* @typedef {Object} LoggerConfig
|
|
18
|
+
* @property {boolean | Array<string>} [sensitiveFilteringKeywords] - Specifies whether to filter sensitive keywords in log messages. Can be a boolean value or an array of strings.
|
|
19
|
+
* @property {LOG_LEVELS | string} [logLevel] - The log level to use for logging. Can be one of the predefined log levels or a custom string value.
|
|
20
|
+
*/
|
|
21
|
+
export type LoggerConfig = {
|
|
22
|
+
sensitiveFilteringKeywords?: boolean | Array<string>;
|
|
23
|
+
logLevel?: LOG_LEVELS | string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Logger class for logging messages with different log levels.
|
|
27
|
+
*/
|
|
28
|
+
export default class Logger {
|
|
29
|
+
/**
|
|
30
|
+
* The optional configuration object for the logger.
|
|
31
|
+
*/
|
|
32
|
+
private config?;
|
|
33
|
+
/**
|
|
34
|
+
* Private property representing the transaction ID.
|
|
35
|
+
* @type {string}
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
private transactionID;
|
|
39
|
+
/**
|
|
40
|
+
* An array of strings representing a blacklist of filters
|
|
41
|
+
*/
|
|
42
|
+
private filterBlacklist;
|
|
43
|
+
/**
|
|
44
|
+
* The current log level for the application.
|
|
45
|
+
* @private
|
|
46
|
+
* @type {LOG_LEVELS}
|
|
47
|
+
*/
|
|
48
|
+
private _LOG_LEVEL;
|
|
49
|
+
/**
|
|
50
|
+
* The origin of the object.
|
|
51
|
+
* @private
|
|
52
|
+
* @type {any}
|
|
53
|
+
*/
|
|
54
|
+
private origin;
|
|
55
|
+
/**
|
|
56
|
+
* Constructs a Logger object with the given configuration and transaction ID.
|
|
57
|
+
* @param {config} config - The configuration object for the logger. Can be undefined.
|
|
58
|
+
* @param {string} transactionID - The ID of the transaction associated with the logger.
|
|
59
|
+
* @returns None
|
|
60
|
+
*/
|
|
61
|
+
constructor(config: LoggerConfig | undefined, transactionID: string);
|
|
62
|
+
/**
|
|
63
|
+
* Returns a boolean value indicating whether the notGlobalLogger function is executed successfully.
|
|
64
|
+
* @returns {boolean} - true if the function is executed successfully, false otherwise.
|
|
65
|
+
*/
|
|
66
|
+
notGlobalLogger(): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Logs the given arguments with the debug log level.
|
|
69
|
+
* @param {...any} args - The arguments to be logged.
|
|
70
|
+
* @returns None
|
|
71
|
+
*/
|
|
72
|
+
debug(...args: any[]): void;
|
|
73
|
+
/**
|
|
74
|
+
* Logs the given arguments with the INFO log level.
|
|
75
|
+
* @param {...any} args - The arguments to be logged.
|
|
76
|
+
* @returns None
|
|
77
|
+
*/
|
|
78
|
+
log(...args: any[]): void;
|
|
79
|
+
/**
|
|
80
|
+
* Logs an informational message.
|
|
81
|
+
* @param {...any} args - The message(s) to log.
|
|
82
|
+
* @returns None
|
|
83
|
+
*/
|
|
84
|
+
info(...args: any[]): void;
|
|
85
|
+
/**
|
|
86
|
+
* Logs a warning message with the provided arguments.
|
|
87
|
+
* @param {...any} args - The arguments to be logged as a warning message.
|
|
88
|
+
* @returns None
|
|
89
|
+
*/
|
|
90
|
+
warning(...args: any[]): void;
|
|
91
|
+
/**
|
|
92
|
+
* Logs a warning message to the console.
|
|
93
|
+
* @param {...any} args - The arguments to be logged.
|
|
94
|
+
* @returns None
|
|
95
|
+
*/
|
|
96
|
+
warn(...args: any[]): void;
|
|
97
|
+
/**
|
|
98
|
+
* Logs an error message with the given arguments.
|
|
99
|
+
* @param {...any} args - The arguments to log as an error message.
|
|
100
|
+
* @returns None
|
|
101
|
+
*/
|
|
102
|
+
error(...args: any[]): void;
|
|
103
|
+
/**
|
|
104
|
+
* Logs an exception with optional additional arguments.
|
|
105
|
+
* @param {any} exception - The exception to log.
|
|
106
|
+
* @param {...any} args - Additional arguments to include in the log.
|
|
107
|
+
* @returns None
|
|
108
|
+
*/
|
|
109
|
+
exception(exception: any, ...args: any[]): void;
|
|
110
|
+
/**
|
|
111
|
+
* Sets up the console bindings for logging purposes.
|
|
112
|
+
* @private
|
|
113
|
+
* @returns None
|
|
114
|
+
*/
|
|
115
|
+
private setupBindings;
|
|
116
|
+
/**
|
|
117
|
+
* Formats a log message with the specified log level, message, and caller.
|
|
118
|
+
* @param {LOG_LEVELS} level - The log level of the message.
|
|
119
|
+
* @param {Array<string>} msg - An array of strings representing the message.
|
|
120
|
+
* @param {string} caller - The name of the caller function.
|
|
121
|
+
* @returns {string} - The formatted log message.
|
|
122
|
+
*/
|
|
123
|
+
private formattedLog;
|
|
124
|
+
/**
|
|
125
|
+
* Retrieves the name of the caller function at the specified index in the stack trace.
|
|
126
|
+
* @param {number} index - The index of the caller function in the stack trace.
|
|
127
|
+
* @returns {string} The name of the caller function along with the file path and line number.
|
|
128
|
+
*/
|
|
129
|
+
private callerName;
|
|
130
|
+
/**
|
|
131
|
+
* Processes log messages based on the specified log level.
|
|
132
|
+
* @param {LOG_LEVELS} level - The level of the log message.
|
|
133
|
+
* @param {any} args - The arguments to be logged.
|
|
134
|
+
* @returns None
|
|
135
|
+
*/
|
|
136
|
+
private processLog;
|
|
137
|
+
private formatArgument;
|
|
138
|
+
/**
|
|
139
|
+
* Logs an exception along with additional arguments and the stack trace.
|
|
140
|
+
* @param {Error} exception - The exception object to log.
|
|
141
|
+
* @param {...any} args - Additional arguments to include in the log.
|
|
142
|
+
* @returns None
|
|
143
|
+
*/
|
|
144
|
+
private iexception;
|
|
145
|
+
/**
|
|
146
|
+
* Pushes a log message to the console with the specified log level.
|
|
147
|
+
* @param {LOG_LEVELS} level - The log level of the message.
|
|
148
|
+
* @param {string} fMsg - The formatted log message.
|
|
149
|
+
* @returns None
|
|
150
|
+
*/
|
|
151
|
+
private pushLog;
|
|
152
|
+
/**
|
|
153
|
+
* Suppresses sensitive information in the given value based on the filter blacklist.
|
|
154
|
+
* @param {any} value - The value to suppress sensitive information from.
|
|
155
|
+
* @returns {string} - The value with sensitive information suppressed.
|
|
156
|
+
*/
|
|
157
|
+
private suppressSensitiveInfo;
|
|
158
|
+
private suppressSensitiveInfoItem;
|
|
159
|
+
private suppressSensitiveString;
|
|
160
|
+
private suppressSensitiveObject;
|
|
161
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import abind from 'abind';
|
|
2
|
+
import stringify from 'json-stringify-safe';
|
|
3
|
+
import stackTrace from 'stack-trace';
|
|
4
|
+
import Utils from '../Util/Utils.js';
|
|
5
|
+
/**
|
|
6
|
+
* Enumeration of log levels.
|
|
7
|
+
* @enum {string}
|
|
8
|
+
* @property {string} DEBUG - Debug log level.
|
|
9
|
+
* @property {string} INFO - Info log level.
|
|
10
|
+
* @property {string} WARN - Warning log level.
|
|
11
|
+
* @property {string} ERROR - Error log level.
|
|
12
|
+
*/
|
|
13
|
+
export var LOG_LEVELS;
|
|
14
|
+
(function (LOG_LEVELS) {
|
|
15
|
+
LOG_LEVELS["DEBUG"] = "DEBUG";
|
|
16
|
+
LOG_LEVELS["INFO"] = "INFO";
|
|
17
|
+
LOG_LEVELS["WARN"] = "WARN";
|
|
18
|
+
LOG_LEVELS["ERROR"] = "ERROR";
|
|
19
|
+
})(LOG_LEVELS || (LOG_LEVELS = {}));
|
|
20
|
+
/**
|
|
21
|
+
* A constant that represents the console object to be used for logging.
|
|
22
|
+
* If the console object has a property named 'notGlobalLogger', it is assumed
|
|
23
|
+
* to be a custom logger and the 'origin' property is used as the console object.
|
|
24
|
+
* Otherwise, the global console object is used.
|
|
25
|
+
* @type {Console}
|
|
26
|
+
*/
|
|
27
|
+
const PURE_CONSOLE = console['notGlobalLogger'] ? console['origin'] : console;
|
|
28
|
+
/**
|
|
29
|
+
* The default log function that is used for logging messages.
|
|
30
|
+
* @type {Function}
|
|
31
|
+
*/
|
|
32
|
+
const DEFAULT_LOG_FUNCTION = PURE_CONSOLE.log.bind(PURE_CONSOLE);
|
|
33
|
+
/**
|
|
34
|
+
* Creates a blacklist array by mapping each string in the given array to its lowercase form.
|
|
35
|
+
* The resulting blacklist array is used to filter out sensitive information.
|
|
36
|
+
* @type {string[]} blacklist - An array of strings to be converted to lowercase and used as a blacklist.
|
|
37
|
+
* @returns {string[]} - An array of lowercase strings representing the blacklist.
|
|
38
|
+
*/
|
|
39
|
+
const blacklist = ['password', 'token', 'accounts'].map(s => s.toLowerCase());
|
|
40
|
+
/**
|
|
41
|
+
* Logger class for logging messages with different log levels.
|
|
42
|
+
*/
|
|
43
|
+
export default class Logger {
|
|
44
|
+
/**
|
|
45
|
+
* Constructs a Logger object with the given configuration and transaction ID.
|
|
46
|
+
* @param {config} config - The configuration object for the logger. Can be undefined.
|
|
47
|
+
* @param {string} transactionID - The ID of the transaction associated with the logger.
|
|
48
|
+
* @returns None
|
|
49
|
+
*/
|
|
50
|
+
constructor(config, transactionID) {
|
|
51
|
+
abind(this);
|
|
52
|
+
//
|
|
53
|
+
this.origin = PURE_CONSOLE;
|
|
54
|
+
this._LOG_LEVEL = (config === null || config === void 0 ? void 0 : config.logLevel)
|
|
55
|
+
? LOG_LEVELS[config === null || config === void 0 ? void 0 : config.logLevel] || LOG_LEVELS.DEBUG
|
|
56
|
+
: LOG_LEVELS.DEBUG;
|
|
57
|
+
this.config = config || {};
|
|
58
|
+
this.transactionID = transactionID;
|
|
59
|
+
this.filterBlacklist = this.config.sensitiveFilteringKeywords
|
|
60
|
+
? Array.isArray(this.config.sensitiveFilteringKeywords)
|
|
61
|
+
? this.config.sensitiveFilteringKeywords
|
|
62
|
+
: blacklist
|
|
63
|
+
: [];
|
|
64
|
+
//
|
|
65
|
+
this.setupBindings();
|
|
66
|
+
//
|
|
67
|
+
this.log('Using logger with level: ' + this._LOG_LEVEL.toString());
|
|
68
|
+
this.debug('logger config: ', this.config);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns a boolean value indicating whether the notGlobalLogger function is executed successfully.
|
|
72
|
+
* @returns {boolean} - true if the function is executed successfully, false otherwise.
|
|
73
|
+
*/
|
|
74
|
+
notGlobalLogger() {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Logs the given arguments with the debug log level.
|
|
79
|
+
* @param {...any} args - The arguments to be logged.
|
|
80
|
+
* @returns None
|
|
81
|
+
*/
|
|
82
|
+
debug(...args) {
|
|
83
|
+
this.processLog(LOG_LEVELS.DEBUG, args);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Logs the given arguments with the INFO log level.
|
|
87
|
+
* @param {...any} args - The arguments to be logged.
|
|
88
|
+
* @returns None
|
|
89
|
+
*/
|
|
90
|
+
log(...args) {
|
|
91
|
+
this.processLog(LOG_LEVELS.INFO, args);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Logs an informational message.
|
|
95
|
+
* @param {...any} args - The message(s) to log.
|
|
96
|
+
* @returns None
|
|
97
|
+
*/
|
|
98
|
+
info(...args) {
|
|
99
|
+
this.processLog(LOG_LEVELS.INFO, args);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Logs a warning message with the provided arguments.
|
|
103
|
+
* @param {...any} args - The arguments to be logged as a warning message.
|
|
104
|
+
* @returns None
|
|
105
|
+
*/
|
|
106
|
+
warning(...args) {
|
|
107
|
+
this.processLog(LOG_LEVELS.WARN, args);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Logs a warning message to the console.
|
|
111
|
+
* @param {...any} args - The arguments to be logged.
|
|
112
|
+
* @returns None
|
|
113
|
+
*/
|
|
114
|
+
warn(...args) {
|
|
115
|
+
this.processLog(LOG_LEVELS.WARN, args);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Logs an error message with the given arguments.
|
|
119
|
+
* @param {...any} args - The arguments to log as an error message.
|
|
120
|
+
* @returns None
|
|
121
|
+
*/
|
|
122
|
+
error(...args) {
|
|
123
|
+
this.processLog(LOG_LEVELS.ERROR, args);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Logs an exception with optional additional arguments.
|
|
127
|
+
* @param {any} exception - The exception to log.
|
|
128
|
+
* @param {...any} args - Additional arguments to include in the log.
|
|
129
|
+
* @returns None
|
|
130
|
+
*/
|
|
131
|
+
exception(exception, ...args) {
|
|
132
|
+
this.iexception(exception, args);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Sets up the console bindings for logging purposes.
|
|
136
|
+
* @private
|
|
137
|
+
* @returns None
|
|
138
|
+
*/
|
|
139
|
+
setupBindings() {
|
|
140
|
+
global.console = {
|
|
141
|
+
debug: (...args) => this.processLog(LOG_LEVELS.DEBUG, args),
|
|
142
|
+
log: (...args) => this.processLog(LOG_LEVELS.INFO, args),
|
|
143
|
+
info: (...args) => this.processLog(LOG_LEVELS.INFO, args),
|
|
144
|
+
warn: (...args) => this.processLog(LOG_LEVELS.WARN, args),
|
|
145
|
+
error: (...args) => this.processLog(LOG_LEVELS.ERROR, args),
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
147
|
+
// @ts-ignore
|
|
148
|
+
warning: (...args) => this.processLog(LOG_LEVELS.WARN, args),
|
|
149
|
+
exception: (exception, ...args) => this.iexception(exception, args),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Formats a log message with the specified log level, message, and caller.
|
|
154
|
+
* @param {LOG_LEVELS} level - The log level of the message.
|
|
155
|
+
* @param {Array<string>} msg - An array of strings representing the message.
|
|
156
|
+
* @param {string} caller - The name of the caller function.
|
|
157
|
+
* @returns {string} - The formatted log message.
|
|
158
|
+
*/
|
|
159
|
+
formattedLog(level, msg, caller) {
|
|
160
|
+
if (Utils.isHybridlessContainer() && this.transactionID) {
|
|
161
|
+
return `${this.transactionID}` + ` [${level.toString()}] [${caller}] ${msg.join(' ')}`;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
return `[${level.toString()}] [${caller}] ${msg.join(' ')}`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Retrieves the name of the caller function at the specified index in the stack trace.
|
|
169
|
+
* @param {number} index - The index of the caller function in the stack trace.
|
|
170
|
+
* @returns {string} The name of the caller function along with the file path and line number.
|
|
171
|
+
*/
|
|
172
|
+
callerName(index) {
|
|
173
|
+
var _a, _b, _c, _d, _e, _f;
|
|
174
|
+
const safeIndex = Math.min(index, stackTrace.get().length);
|
|
175
|
+
if (stackTrace.get()[safeIndex]) {
|
|
176
|
+
let callerName = (_c = (_b = (_a = stackTrace === null || stackTrace === void 0 ? void 0 : stackTrace.get()) === null || _a === void 0 ? void 0 : _a[safeIndex]) === null || _b === void 0 ? void 0 : _b.getFileName()) === null || _c === void 0 ? void 0 : _c.split('/');
|
|
177
|
+
callerName = (_d = callerName === null || callerName === void 0 ? void 0 : callerName.slice(callerName === null || callerName === void 0 ? void 0 : callerName.indexOf('src'))) === null || _d === void 0 ? void 0 : _d.join('/');
|
|
178
|
+
return callerName + ':' + ((_f = (_e = stackTrace === null || stackTrace === void 0 ? void 0 : stackTrace.get()) === null || _e === void 0 ? void 0 : _e[safeIndex]) === null || _f === void 0 ? void 0 : _f.getLineNumber());
|
|
179
|
+
}
|
|
180
|
+
return '';
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Processes log messages based on the specified log level.
|
|
184
|
+
* @param {LOG_LEVELS} level - The level of the log message.
|
|
185
|
+
* @param {any} args - The arguments to be logged.
|
|
186
|
+
* @returns None
|
|
187
|
+
*/
|
|
188
|
+
processLog(level, args) {
|
|
189
|
+
if (level < this._LOG_LEVEL)
|
|
190
|
+
return;
|
|
191
|
+
//get args
|
|
192
|
+
const msg = [];
|
|
193
|
+
for (const arg of args) {
|
|
194
|
+
// Deep clone object so we dont modify source
|
|
195
|
+
const fMsg = this.formatArgument(arg);
|
|
196
|
+
msg.push(fMsg);
|
|
197
|
+
}
|
|
198
|
+
//push into logs stack
|
|
199
|
+
// todo: improve error stack
|
|
200
|
+
this.pushLog(level, this.formattedLog(level, msg, this.callerName(3)));
|
|
201
|
+
}
|
|
202
|
+
formatArgument(arg) {
|
|
203
|
+
if (arg instanceof Error) {
|
|
204
|
+
return arg.message + '\n' + arg.stack;
|
|
205
|
+
}
|
|
206
|
+
if (arg && typeof arg === 'object') {
|
|
207
|
+
return stringify(this.suppressSensitiveInfo(JSON.parse(stringify(arg))), null, 2);
|
|
208
|
+
}
|
|
209
|
+
return `${this.suppressSensitiveInfo(arg)}`;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Logs an exception along with additional arguments and the stack trace.
|
|
213
|
+
* @param {Error} exception - The exception object to log.
|
|
214
|
+
* @param {...any} args - Additional arguments to include in the log.
|
|
215
|
+
* @returns None
|
|
216
|
+
*/
|
|
217
|
+
iexception(exception, ...args) {
|
|
218
|
+
//format message
|
|
219
|
+
const msg = [];
|
|
220
|
+
//push exeception
|
|
221
|
+
msg.push(exception.toString() + ' -');
|
|
222
|
+
//get args
|
|
223
|
+
for (const arg of args)
|
|
224
|
+
if (arg != exception)
|
|
225
|
+
msg.push(arg);
|
|
226
|
+
if (exception.stack)
|
|
227
|
+
msg.push(exception.stack); //push Exeception stack at the end
|
|
228
|
+
//push into logs stack
|
|
229
|
+
this.pushLog(LOG_LEVELS.ERROR, this.formattedLog(LOG_LEVELS.ERROR, msg, this.callerName(3)));
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Pushes a log message to the console with the specified log level.
|
|
233
|
+
* @param {LOG_LEVELS} level - The log level of the message.
|
|
234
|
+
* @param {string} fMsg - The formatted log message.
|
|
235
|
+
* @returns None
|
|
236
|
+
*/
|
|
237
|
+
pushLog(level, fMsg) {
|
|
238
|
+
DEFAULT_LOG_FUNCTION.apply(PURE_CONSOLE, [fMsg]);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Suppresses sensitive information in the given value based on the filter blacklist.
|
|
242
|
+
* @param {any} value - The value to suppress sensitive information from.
|
|
243
|
+
* @returns {string} - The value with sensitive information suppressed.
|
|
244
|
+
*/
|
|
245
|
+
suppressSensitiveInfo(value) {
|
|
246
|
+
if (!value || !this.filterBlacklist.length)
|
|
247
|
+
return value;
|
|
248
|
+
const parent = [value];
|
|
249
|
+
const stack = [{ value, parent, key: 0 }];
|
|
250
|
+
while (stack.length > 0) {
|
|
251
|
+
this.suppressSensitiveInfoItem(stack.pop(), stack.push.bind(stack));
|
|
252
|
+
}
|
|
253
|
+
return parent[0];
|
|
254
|
+
}
|
|
255
|
+
suppressSensitiveInfoItem({ value, parent, key }, push) {
|
|
256
|
+
if (!value)
|
|
257
|
+
return;
|
|
258
|
+
if (typeof value === 'string') {
|
|
259
|
+
this.suppressSensitiveString({ value, parent, key }, push);
|
|
260
|
+
}
|
|
261
|
+
else if (Array.isArray(value)) {
|
|
262
|
+
value.forEach((v, index) => push({ value: v, parent: value, key: index }));
|
|
263
|
+
}
|
|
264
|
+
else if (typeof value === 'object') {
|
|
265
|
+
this.suppressSensitiveObject(value, push);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
suppressSensitiveString({ value, parent, key }, push) {
|
|
269
|
+
var _a;
|
|
270
|
+
let modifiedValue = value;
|
|
271
|
+
try {
|
|
272
|
+
// Try to parse json string
|
|
273
|
+
modifiedValue = JSON.parse(value);
|
|
274
|
+
push({ value: modifiedValue, parent, key });
|
|
275
|
+
}
|
|
276
|
+
catch (_b) {
|
|
277
|
+
const lower = value.toLowerCase();
|
|
278
|
+
if (this.filterBlacklist.some(f => lower == f))
|
|
279
|
+
modifiedValue = `**SUPPRESSED_SENSITIVE_DATA** (${((_a = String(modifiedValue)) === null || _a === void 0 ? void 0 : _a.length) || 0} len)`;
|
|
280
|
+
}
|
|
281
|
+
parent[key] = modifiedValue;
|
|
282
|
+
}
|
|
283
|
+
suppressSensitiveObject(value, push) {
|
|
284
|
+
Object.entries(value).forEach(([k, v]) => {
|
|
285
|
+
var _a;
|
|
286
|
+
const lower = k.toLowerCase();
|
|
287
|
+
const match = v && this.filterBlacklist.some(f => lower == f);
|
|
288
|
+
if (match) {
|
|
289
|
+
value[k] = `**SUPPRESSED_SENSITIVE_DATA** (${((_a = String(v)) === null || _a === void 0 ? void 0 : _a.length) || 0} len)`;
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
push({ value: v, parent: value, key: k });
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=Logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../../src/Logger/Logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,SAAS,MAAM,qBAAqB,CAAA;AAC3C,OAAO,UAAU,MAAM,aAAa,CAAA;AAEpC,OAAO,KAAK,MAAM,kBAAkB,CAAA;AAEpC;;;;;;;GAOG;AACH,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,6BAAe,CAAA;IACf,2BAAa,CAAA;IACb,2BAAa,CAAA;IACb,6BAAe,CAAA;AACjB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AACD;;;;;;GAMG;AACH,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;AAC7E;;;GAGG;AACH,MAAM,oBAAoB,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;AAEhE;;;;;GAKG;AACH,MAAM,SAAS,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA;AAmB7E;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IA4BzB;;;;;OAKG;IACH,YAAY,MAAgC,EAAE,aAAqB;QACjE,KAAK,CAAC,IAAI,CAAC,CAAA;QACX,EAAE;QACF,IAAI,CAAC,MAAM,GAAG,YAAY,CAAA;QAC1B,IAAI,CAAC,UAAU,GAAG,CAAA,MAAM,aAAN,MAAM,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A;IAC7B,CAAC;IAEO,uBAAuB,CAAC,KAAa,EAAE,IAAkC;QAC/E,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;;YACvC,MAAM,KAAK,GAAG,CAAC,CAAC,WAAW,EAAE,CAAA;YAC7B,MAAM,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC,CAAA;YAC7D,IAAI,KAAK,EAAE,CAAC;gBACV,KAAK,CAAC,CAAC,CAAC,GAAG,kCAAkC,CAAA,MAAA,MAAM,CAAC,CAAC,CAAC,0CAAE,MAAM,KAAI,CAAC,OAAO,CAAA;YAC5E,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;YAC3C,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import Email from 'email-templates';
|
|
2
|
+
export default class Mailer {
|
|
3
|
+
/**
|
|
4
|
+
* The starting point of a range.
|
|
5
|
+
* @type {string}
|
|
6
|
+
*/
|
|
7
|
+
private readonly from;
|
|
8
|
+
/**
|
|
9
|
+
* The default file template for the application.
|
|
10
|
+
* @type {string}
|
|
11
|
+
*/
|
|
12
|
+
private readonly templateDefaultFile;
|
|
13
|
+
/**
|
|
14
|
+
* The transporter object used for sending emails using the AWS SES service.
|
|
15
|
+
* @type {ReturnType<typeof nodemailer.createTransport<SESTransport.SentMessageInfo>>}
|
|
16
|
+
*/
|
|
17
|
+
private readonly transporter;
|
|
18
|
+
/**
|
|
19
|
+
* Constructs a new instance of the EmailSender class.
|
|
20
|
+
* @param {string} defaultFrom - The default "from" email address.
|
|
21
|
+
* @param {string} region - The AWS region to use for sending emails.
|
|
22
|
+
* @returns None
|
|
23
|
+
*/
|
|
24
|
+
constructor(defaultFrom: string, region: string);
|
|
25
|
+
/**
|
|
26
|
+
* Sends a raw email with the specified parameters.
|
|
27
|
+
* @param {string | Array<string>} to - The recipient(s) of the email.
|
|
28
|
+
* @param {string} htmlMessage - The HTML content of the email.
|
|
29
|
+
* @param {string} subject - The subject of the email.
|
|
30
|
+
* @param {string | Array<string>} [optionalCC] - The optional CC recipient(s) of the email.
|
|
31
|
+
* @param {string} [optionalFrom] - The optional sender of the email. If not provided, the default sender will be used.
|
|
32
|
+
* @param {string} [optionalReplyTo] - The optional reply-to address for the email.
|
|
33
|
+
* @param {any[]} [optionalAttachments] - The optional attachments to include
|
|
34
|
+
*/
|
|
35
|
+
sendRawEmail(to: string | Array<string>, htmlMessage: string, subject: string, optionalCC?: string | Array<string>, optionalFrom?: string, optionalReplyTo?: string, optionalAttachments?: any[], optionalTransport?: Email.NodeMailerTransportOptions): Promise<null>;
|
|
36
|
+
/**
|
|
37
|
+
* Sends a templated email to the specified recipients.
|
|
38
|
+
* @param {string | Array<string>} to - The email address(es) of the recipient(s).
|
|
39
|
+
* @param {string | Array<string>} templates - The template(s) to use for the email.
|
|
40
|
+
* @param {object} data - The data to be used in the email template.
|
|
41
|
+
* @param {string | Array<string>} [optionalCC] - The email address(es) to CC.
|
|
42
|
+
* @param {string} [optionalFrom] - The email address to send the email from.
|
|
43
|
+
* @param {string} [optionalReplyTo] - The email address to set as the reply-to address.
|
|
44
|
+
* @param {any[]} [optionalAttachments] - An array
|
|
45
|
+
*/
|
|
46
|
+
sendTemplatedEmail(to: string | Array<string>, templates: string | Array<string>, data: object, optionalCC?: string | Array<string>, optionalFrom?: string, optionalReplyTo?: string, optionalAttachments?: any[], optionalTransport?: Email.NodeMailerTransportOptions): Promise<null>;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new SMTP transporter for sending emails using NodeMailer.
|
|
49
|
+
* @param {string} host - The SMTP server host.
|
|
50
|
+
* @param {number} portNumber - The port number to connect to the SMTP server.
|
|
51
|
+
* @param {string} user - The username for authentication with the SMTP server.
|
|
52
|
+
* @param {string} password - The password for authentication with the SMTP server.
|
|
53
|
+
* @returns {Email.NodeMailerTransportOptions} - The SMTP transporter object.
|
|
54
|
+
*/
|
|
55
|
+
newSMTPTransporter(host: string, portNumber: number, user: string, password: string): Email.NodeMailerTransportOptions;
|
|
56
|
+
/**
|
|
57
|
+
* Chooses a template from the given array of templates or a single template string based on whether it can be rendered with the provided data.
|
|
58
|
+
* @param {string | Array<string>} templates - The template(s) to choose from.
|
|
59
|
+
* @param {object} data - The data to be used for rendering the template.
|
|
60
|
+
* @returns {Promise<string>} - The chosen template.
|
|
61
|
+
* @throws {Error} - If no template can be rendered with the provided data.
|
|
62
|
+
*/
|
|
63
|
+
private chooseTemplate;
|
|
64
|
+
/**
|
|
65
|
+
* Checks if a given email template can be rendered with the provided data.
|
|
66
|
+
* @param {string} template - The name of the email template.
|
|
67
|
+
* @param {object} data - The data to be used for rendering the template.
|
|
68
|
+
* @returns {Promise<boolean>} - A promise that resolves to true if the template can be rendered, false otherwise.
|
|
69
|
+
*/
|
|
70
|
+
private canRenderTemplate;
|
|
71
|
+
/**
|
|
72
|
+
* Renders the given template with the provided data using the Email class.
|
|
73
|
+
* @param {string} template - The name or path of the template to render.
|
|
74
|
+
* @param {object} data - The data object to pass to the template.
|
|
75
|
+
* @returns {Promise<boolean>} - A promise that resolves to true if the template was rendered successfully, false otherwise.
|
|
76
|
+
*/
|
|
77
|
+
static renderTemplate(template: string, data: object): Promise<any>;
|
|
78
|
+
}
|