@koralabs/kora-labs-common 1.0.8 → 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;
@@ -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* () {
@@ -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: {
@@ -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,6 +34,13 @@ 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* () {
@@ -49,6 +56,7 @@ class Logger {
49
56
  else {
50
57
  Logger.application = 'TEST';
51
58
  }
59
+ this.network = environment_1.Environment.getCardanoNetwork();
52
60
  Logger.isInitialized = true;
53
61
  });
54
62
  }
@@ -70,7 +78,7 @@ class Logger {
70
78
  const log_count = count != undefined && count != null ? `, "count": ${count}` : '';
71
79
  const log_dimensions = dimensions && Object.keys(dimensions).length ? `, "dimensions": ${JSON.stringify(dimensions)}` : '';
72
80
  // PLEASE KEEP THIS ALL ON ONE LINE SO LOGS AREN'T BROKEN UP
73
- 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} }`);
74
82
  // PLEASE KEEP THIS ALL ON ONE LINE SO LOGS AREN'T BROKEN UP
75
83
  }
76
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koralabs/kora-labs-common",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "Kora Labs Common Utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",