@koralabs/kora-labs-common 1.0.7 → 1.1.0
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CardanoNetwork } from "../logger";
|
|
1
2
|
export declare enum ComputeEnvironment {
|
|
2
3
|
AWS_LAMBDA = "aws_lambda",
|
|
3
4
|
AWS_FARGATE = "aws_fargate",
|
|
@@ -7,6 +8,7 @@ export declare enum ComputeEnvironment {
|
|
|
7
8
|
}
|
|
8
9
|
export declare class Environment {
|
|
9
10
|
static getComputeEnvironment(): Promise<ComputeEnvironment>;
|
|
11
|
+
static getCardanoNetwork(): CardanoNetwork;
|
|
10
12
|
static getIpAddress(): Promise<{
|
|
11
13
|
private: string | null;
|
|
12
14
|
public: string | null;
|
package/lib/environment/index.js
CHANGED
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Environment = exports.ComputeEnvironment = void 0;
|
|
13
|
+
const logger_1 = require("../logger");
|
|
13
14
|
var ComputeEnvironment;
|
|
14
15
|
(function (ComputeEnvironment) {
|
|
15
16
|
ComputeEnvironment["AWS_LAMBDA"] = "aws_lambda";
|
|
@@ -36,6 +37,19 @@ class Environment {
|
|
|
36
37
|
return ComputeEnvironment.OTHER;
|
|
37
38
|
});
|
|
38
39
|
}
|
|
40
|
+
static getCardanoNetwork() {
|
|
41
|
+
try {
|
|
42
|
+
if (process.env.NETWORK) {
|
|
43
|
+
return logger_1.CardanoNetwork[process.env.NETWORK];
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return logger_1.CardanoNetwork.UNSET;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (_a) {
|
|
50
|
+
return logger_1.CardanoNetwork.UNSET;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
39
53
|
static getIpAddress() {
|
|
40
54
|
var _a, _b;
|
|
41
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -96,9 +110,6 @@ class Environment {
|
|
|
96
110
|
static getPotentialApplicationName() {
|
|
97
111
|
var _a, _b;
|
|
98
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
if (process.env.NODE_ENV == 'test') {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
113
|
if (process.env.APPLICATION_NAME) {
|
|
103
114
|
return process.env.APPLICATION_NAME;
|
|
104
115
|
}
|
package/lib/logger/index.d.ts
CHANGED
|
@@ -7,8 +7,15 @@ export declare enum LogCategory {
|
|
|
7
7
|
FATAL = "FATAL",
|
|
8
8
|
NOTIFY = "NOTIFY"
|
|
9
9
|
}
|
|
10
|
+
export declare enum CardanoNetwork {
|
|
11
|
+
MAINNET = "MAINNET",
|
|
12
|
+
PREPROD = "PREPROD",
|
|
13
|
+
PREVIEW = "PREVIEW",
|
|
14
|
+
UNSET = "UNSET"
|
|
15
|
+
}
|
|
10
16
|
export declare class Logger {
|
|
11
17
|
static application: string;
|
|
18
|
+
static network: CardanoNetwork;
|
|
12
19
|
private static isInitialized;
|
|
13
20
|
static initialize(): Promise<void>;
|
|
14
21
|
static log(args: {
|
package/lib/logger/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Logger = exports.LogCategory = void 0;
|
|
12
|
+
exports.Logger = exports.CardanoNetwork = exports.LogCategory = void 0;
|
|
13
13
|
const environment_1 = require("../environment");
|
|
14
14
|
// Fix from https://stackoverflow.com/questions/18391212/is-it-not-possible-to-stringify-an-error-using-json-stringify
|
|
15
15
|
if (!('toJSON' in Error.prototype))
|
|
@@ -34,16 +34,29 @@ var LogCategory;
|
|
|
34
34
|
LogCategory["FATAL"] = "FATAL";
|
|
35
35
|
LogCategory["NOTIFY"] = "NOTIFY";
|
|
36
36
|
})(LogCategory = exports.LogCategory || (exports.LogCategory = {}));
|
|
37
|
+
var CardanoNetwork;
|
|
38
|
+
(function (CardanoNetwork) {
|
|
39
|
+
CardanoNetwork["MAINNET"] = "MAINNET";
|
|
40
|
+
CardanoNetwork["PREPROD"] = "PREPROD";
|
|
41
|
+
CardanoNetwork["PREVIEW"] = "PREVIEW";
|
|
42
|
+
CardanoNetwork["UNSET"] = "UNSET";
|
|
43
|
+
})(CardanoNetwork = exports.CardanoNetwork || (exports.CardanoNetwork = {}));
|
|
37
44
|
class Logger {
|
|
38
45
|
static initialize() {
|
|
39
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
48
|
+
if (!Logger.application) {
|
|
49
|
+
const potentialName = yield environment_1.Environment.getPotentialApplicationName();
|
|
50
|
+
if (!potentialName) {
|
|
51
|
+
throw new Error('Logger.application must be set!');
|
|
52
|
+
}
|
|
53
|
+
Logger.application = potentialName;
|
|
44
54
|
}
|
|
45
|
-
Logger.application = potentialName;
|
|
46
55
|
}
|
|
56
|
+
else {
|
|
57
|
+
Logger.application = 'TEST';
|
|
58
|
+
}
|
|
59
|
+
this.network = environment_1.Environment.getCardanoNetwork();
|
|
47
60
|
Logger.isInitialized = true;
|
|
48
61
|
});
|
|
49
62
|
}
|
|
@@ -65,7 +78,7 @@ class Logger {
|
|
|
65
78
|
const log_count = count != undefined && count != null ? `, "count": ${count}` : '';
|
|
66
79
|
const log_dimensions = dimensions && Object.keys(dimensions).length ? `, "dimensions": ${JSON.stringify(dimensions)}` : '';
|
|
67
80
|
// PLEASE KEEP THIS ALL ON ONE LINE SO LOGS AREN'T BROKEN UP
|
|
68
|
-
console.log(`{"application": "${Logger.application}", "category": "${category !== null && category !== void 0 ? category : LogCategory.INFO}", "message": "${message}"${log_event}, "timestamp": "${now}"${log_milliseconds}${log_count}${log_dimensions} }`);
|
|
81
|
+
console.log(`{"network": "${Logger.network}", "application": "${Logger.application}", "category": "${category !== null && category !== void 0 ? category : LogCategory.INFO}", "message": "${message}"${log_event}, "timestamp": "${now}"${log_milliseconds}${log_count}${log_dimensions} }`);
|
|
69
82
|
// PLEASE KEEP THIS ALL ON ONE LINE SO LOGS AREN'T BROKEN UP
|
|
70
83
|
}
|
|
71
84
|
}
|
package/lib/logger/index.test.js
CHANGED