ismx-nexo-node-app 0.4.163 → 0.4.170

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,9 +1,72 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ const fs = __importStar(require("fs"));
27
+ const path = __importStar(require("path"));
3
28
  class BusinessLogger {
29
+ constructor() {
30
+ this.logStream = null;
31
+ this.currentLogFile = null;
32
+ }
33
+ file() {
34
+ return null;
35
+ }
36
+ writeToFile(message) {
37
+ const file = this.file();
38
+ if (!file)
39
+ return;
40
+ if (this.currentLogFile !== file) {
41
+ if (this.logStream) {
42
+ this.logStream.end();
43
+ this.logStream = null;
44
+ }
45
+ const dir = path.dirname(file);
46
+ if (!fs.existsSync(dir))
47
+ fs.mkdirSync(dir, { recursive: true });
48
+ this.logStream = fs.createWriteStream(file, { flags: 'a', encoding: 'utf8' });
49
+ this.currentLogFile = file;
50
+ }
51
+ if (this.logStream)
52
+ this.logStream.write(message + '\n');
53
+ }
54
+ log(level, message, writeToFile = false) {
55
+ const logMessage = `[${level}] ${new Date().toISOString()} -- ${message}`;
56
+ console.log(logMessage);
57
+ this.writeToFile(logMessage);
58
+ }
4
59
  i(message) {
5
- console.log(`${"I"}: ${new Date().toISOString()}\t${message}`);
60
+ this.log("INFO", message);
61
+ }
62
+ w(message) {
63
+ this.log("WARN", message);
64
+ }
65
+ e(message) {
66
+ this.log("ERROR", message);
67
+ }
68
+ d(message) {
69
+ this.log("DEBUG", message);
6
70
  }
7
- ;
8
71
  }
9
72
  exports.default = BusinessLogger;
@@ -46,14 +46,19 @@ class BusinessServer extends Business_1.default {
46
46
  }
47
47
  init() {
48
48
  return __awaiter(this, void 0, void 0, function* () {
49
- yield Promise.resolve().then(() => __importStar(require("express"))).then((_a) => __awaiter(this, [_a], void 0, function* ({ default: express }) {
50
- yield Promise.resolve().then(() => __importStar(require("cors"))).then((_a) => __awaiter(this, [_a], void 0, function* ({ default: cors }) {
51
- this.express = express;
52
- this.app = express();
53
- this.app.use(express.urlencoded({ extended: false }));
54
- this.app.use(cors());
55
- }));
49
+ const { default: express } = yield Promise.resolve().then(() => __importStar(require("express")));
50
+ const { default: cors } = yield Promise.resolve().then(() => __importStar(require("cors")));
51
+ this.express = express;
52
+ this.app = express();
53
+ this.app.use(express.urlencoded({ extended: false }));
54
+ this.app.use(cors({
55
+ origin: true,
56
+ methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
57
+ allowedHeaders: ["Authorization", "Content-Type"],
58
+ exposedHeaders: ["Authorization"],
59
+ credentials: false
56
60
  }));
61
+ this.app.options("*", cors());
57
62
  });
58
63
  }
59
64
  start(port) {
@@ -1,3 +1,12 @@
1
1
  export default class BusinessLogger {
2
+ private logStream;
3
+ private currentLogFile;
4
+ constructor();
5
+ protected file(): string | null;
6
+ private writeToFile;
7
+ private log;
2
8
  i(message: string): void;
9
+ w(message: string): void;
10
+ e(message: string): void;
11
+ d(message: string): void;
3
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.163",
3
+ "version": "0.4.170",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -1,6 +1,56 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+
1
4
  export default class BusinessLogger
2
5
  {
6
+ private logStream: fs.WriteStream | null = null;
7
+ private currentLogFile: string | null = null;
8
+
9
+ constructor() {
10
+
11
+ }
12
+
13
+ protected file(): string | null {
14
+ return null;
15
+ }
16
+
17
+ private writeToFile(message: string) {
18
+ const file = this.file();
19
+ if (!file) return;
20
+
21
+ if (this.currentLogFile !== file) {
22
+ if (this.logStream) {
23
+ this.logStream.end();
24
+ this.logStream = null;
25
+ }
26
+
27
+ const dir = path.dirname(file);
28
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
29
+ this.logStream = fs.createWriteStream(file, { flags: 'a', encoding: 'utf8' });
30
+ this.currentLogFile = file;
31
+ }
32
+
33
+ if (this.logStream) this.logStream.write(message + '\n');
34
+ }
35
+
36
+ private log(level: string, message: string, writeToFile: boolean = false) {
37
+ const logMessage = `[${level}] ${new Date().toISOString()} -- ${message}`;
38
+ console.log(logMessage);this.writeToFile(logMessage);
39
+ }
40
+
3
41
  i(message: string) {
4
- console.log(`${"I"}: ${new Date().toISOString()}\t${message}`)
5
- };
42
+ this.log("INFO", message);
43
+ }
44
+
45
+ w(message: string) {
46
+ this.log("WARN", message);
47
+ }
48
+
49
+ e(message: string) {
50
+ this.log("ERROR", message);
51
+ }
52
+
53
+ d(message: string) {
54
+ this.log("DEBUG", message);
55
+ }
6
56
  }
@@ -15,15 +15,24 @@ export default class BusinessServer extends Business
15
15
  this.publish = this.publish.bind(this);
16
16
  }
17
17
 
18
- async init() {
19
- await import("express").then(async ({ default: express }) => {
20
- await import("cors").then(async ({ default: cors }) => {
21
- this.express = express;
22
- this.app = express();
23
- this.app.use(express.urlencoded({ extended: false }));
24
- this.app.use(cors());
25
- })
26
- });
18
+ async init()
19
+ {
20
+ const { default: express } = await import("express");
21
+ const { default: cors } = await import("cors");
22
+
23
+ this.express = express;
24
+ this.app = express();
25
+
26
+ this.app.use(express.urlencoded({ extended: false }));
27
+ this.app.use(cors({
28
+ origin: true,
29
+ methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
30
+ allowedHeaders: ["Authorization", "Content-Type"],
31
+ exposedHeaders: ["Authorization"],
32
+ credentials: false
33
+ }));
34
+
35
+ this.app.options("*", cors());
27
36
  }
28
37
 
29
38
  start(port: number) {