@seidor-cloud-produtos/orbit-backend-lib 2.0.27 → 2.0.28
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/dist/clean-arch/application/cache/cache.d.ts +1 -1
- package/dist/clean-arch/application/cache/cache.js +0 -1
- package/dist/clean-arch/application/logger/index.d.ts +9 -1
- package/dist/clean-arch/application/logger/index.js +40 -0
- package/dist/clean-arch/infra/logger/logger-in-memory.d.ts +4 -2
- package/dist/clean-arch/infra/logger/logger-in-memory.js +10 -2
- package/dist/clean-arch/infra/logger/logger-orbit.d.ts +6 -2
- package/dist/clean-arch/infra/logger/logger-orbit.js +5 -2
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ export type CacheOptions = {
|
|
|
7
7
|
contingencyClients?: CacheClient[];
|
|
8
8
|
};
|
|
9
9
|
export declare abstract class Cache {
|
|
10
|
-
protected client: CacheClient;
|
|
10
|
+
protected abstract client: CacheClient;
|
|
11
11
|
protected elegibleClients: CacheClient[];
|
|
12
12
|
protected DEFAULT_EXPIRATION_SECONDS: number;
|
|
13
13
|
private options?;
|
|
@@ -6,7 +6,6 @@ const logger_in_memory_1 = tslib_1.__importDefault(require("../../infra/logger/l
|
|
|
6
6
|
const env_1 = require("../../infra/environment/env");
|
|
7
7
|
const types_1 = require("../../infra/environment/types");
|
|
8
8
|
class Cache {
|
|
9
|
-
client;
|
|
10
9
|
elegibleClients;
|
|
11
10
|
DEFAULT_EXPIRATION_SECONDS = env_1.env?.DEFAULT_CACHE_EXPIRATION || 360;
|
|
12
11
|
options;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LOG_LEVEL } from '../../infra/environment/types';
|
|
2
|
+
import { Cache } from '../cache/cache';
|
|
2
3
|
export declare enum ActorEnum {
|
|
3
4
|
SYSTEM = "system",
|
|
4
5
|
USER = "user"
|
|
@@ -27,5 +28,12 @@ export interface LogOptions {
|
|
|
27
28
|
retryStrategy?: (data: any, props?: LogProperties, options?: LogOptions) => Promise<void>;
|
|
28
29
|
}
|
|
29
30
|
export default abstract class LoggerGateway {
|
|
30
|
-
|
|
31
|
+
protected cache: Cache;
|
|
32
|
+
constructor(cache: Cache);
|
|
33
|
+
private static cacheKey;
|
|
34
|
+
abstract register(data: any, props?: Partial<LogProperties>, options?: LogOptions): Promise<void>;
|
|
35
|
+
private static buildAcceptLogLevelValues;
|
|
36
|
+
log(data: any, props?: Partial<LogProperties>, options?: LogOptions): Promise<void>;
|
|
37
|
+
protected buildProps(props?: Partial<LogProperties>): Partial<LogProperties>;
|
|
38
|
+
setLevel(level: LOG_LEVEL): Promise<void>;
|
|
31
39
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CategoryEnum = exports.ActorEnum = void 0;
|
|
4
|
+
const types_1 = require("../../infra/environment/types");
|
|
4
5
|
var ActorEnum;
|
|
5
6
|
(function (ActorEnum) {
|
|
6
7
|
ActorEnum["SYSTEM"] = "system";
|
|
@@ -12,5 +13,44 @@ var CategoryEnum;
|
|
|
12
13
|
CategoryEnum["TECHNICAL"] = "technical";
|
|
13
14
|
})(CategoryEnum || (exports.CategoryEnum = CategoryEnum = {}));
|
|
14
15
|
class LoggerGateway {
|
|
16
|
+
cache;
|
|
17
|
+
constructor(cache) {
|
|
18
|
+
this.cache = cache;
|
|
19
|
+
}
|
|
20
|
+
static cacheKey = 'LOG_LEVEL';
|
|
21
|
+
static buildAcceptLogLevelValues(level) {
|
|
22
|
+
const acceptValues = [types_1.LOG_LEVEL.error];
|
|
23
|
+
if (level === types_1.LOG_LEVEL.warn) {
|
|
24
|
+
acceptValues.push(types_1.LOG_LEVEL.warn);
|
|
25
|
+
}
|
|
26
|
+
if (level === types_1.LOG_LEVEL.info) {
|
|
27
|
+
acceptValues.push(types_1.LOG_LEVEL.info, types_1.LOG_LEVEL.warn);
|
|
28
|
+
}
|
|
29
|
+
if (level === types_1.LOG_LEVEL.debug) {
|
|
30
|
+
acceptValues.push(types_1.LOG_LEVEL.debug, types_1.LOG_LEVEL.info, types_1.LOG_LEVEL.warn);
|
|
31
|
+
}
|
|
32
|
+
return acceptValues;
|
|
33
|
+
}
|
|
34
|
+
async log(data, props, options) {
|
|
35
|
+
const buildedProps = this.buildProps();
|
|
36
|
+
const cachedValue = await this.cache.get(LoggerGateway.cacheKey);
|
|
37
|
+
const acceptValues = LoggerGateway.buildAcceptLogLevelValues(cachedValue);
|
|
38
|
+
if (acceptValues.includes(buildedProps.level || types_1.LOG_LEVEL.info)) {
|
|
39
|
+
return await this.register(data, buildedProps, options);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
buildProps(props) {
|
|
43
|
+
if (props) {
|
|
44
|
+
return props;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
level: types_1.LOG_LEVEL.info,
|
|
48
|
+
dateTime: new Date(),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async setLevel(level) {
|
|
52
|
+
const oneWeekInSeconds = 604800;
|
|
53
|
+
return await this.cache.set(LoggerGateway.cacheKey, level, oneWeekInSeconds);
|
|
54
|
+
}
|
|
15
55
|
}
|
|
16
56
|
exports.default = LoggerGateway;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import LoggerGateway, {
|
|
1
|
+
import LoggerGateway, { LogProperties } from '../../application/logger';
|
|
2
|
+
import { Cache } from '../../../clean-arch/application/cache/cache';
|
|
2
3
|
export declare class LoggerInMemory extends LoggerGateway {
|
|
3
|
-
|
|
4
|
+
constructor(cache: Cache);
|
|
5
|
+
register(payload: any, props?: Partial<LogProperties>): Promise<void>;
|
|
4
6
|
private info;
|
|
5
7
|
private error;
|
|
6
8
|
private warning;
|
|
@@ -5,8 +5,16 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const env_1 = require("../../infra/environment/env");
|
|
6
6
|
const logger_1 = tslib_1.__importDefault(require("../../application/logger"));
|
|
7
7
|
const types_1 = require("../environment/types");
|
|
8
|
+
const cache_1 = require("../../../clean-arch/application/cache/cache");
|
|
9
|
+
const node_cache_1 = require("../cache/clients/node-cache");
|
|
10
|
+
class CacheInMemory extends cache_1.Cache {
|
|
11
|
+
client = new node_cache_1.NodeCache();
|
|
12
|
+
}
|
|
8
13
|
class LoggerInMemory extends logger_1.default {
|
|
9
|
-
|
|
14
|
+
constructor(cache) {
|
|
15
|
+
super(cache);
|
|
16
|
+
}
|
|
17
|
+
async register(payload, props) {
|
|
10
18
|
switch (props?.level) {
|
|
11
19
|
case types_1.LOG_LEVEL.error:
|
|
12
20
|
return this.error(payload, props);
|
|
@@ -32,5 +40,5 @@ class LoggerInMemory extends logger_1.default {
|
|
|
32
40
|
}
|
|
33
41
|
}
|
|
34
42
|
exports.LoggerInMemory = LoggerInMemory;
|
|
35
|
-
const loggerInMemory = new LoggerInMemory();
|
|
43
|
+
const loggerInMemory = new LoggerInMemory(new CacheInMemory());
|
|
36
44
|
exports.default = loggerInMemory;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Queue from '../../application/queue/queue';
|
|
2
2
|
import LoggerGateway, { LogOptions, LogProperties } from '../../application/logger';
|
|
3
3
|
import DomainEvent from '../../domain/events/domain-event';
|
|
4
|
+
import { Cache } from '../../../clean-arch/application/cache/cache';
|
|
4
5
|
export type LogPayload = Omit<LogProperties, 'expirationHours'> & {
|
|
5
6
|
expirationDate: Date;
|
|
6
7
|
details: any;
|
|
@@ -13,9 +14,12 @@ export default class LogEvent implements DomainEvent {
|
|
|
13
14
|
}
|
|
14
15
|
export declare class LoggerOrbit extends LoggerGateway {
|
|
15
16
|
private queue;
|
|
16
|
-
constructor(queue: Queue);
|
|
17
|
+
constructor(queue: Queue, cache: Cache);
|
|
17
18
|
log(data: any, props?: LogProperties, options?: LogOptions): Promise<void>;
|
|
19
|
+
register(data: any, props?: LogProperties, options?: LogOptions): Promise<void>;
|
|
18
20
|
private buildPayload;
|
|
19
|
-
|
|
21
|
+
protected buildProps(props?: Partial<LogProperties>): LogProperties & {
|
|
22
|
+
expirationHours: number;
|
|
23
|
+
};
|
|
20
24
|
protected buildDefaultProps(): LogProperties;
|
|
21
25
|
}
|
|
@@ -18,11 +18,14 @@ class LogEvent {
|
|
|
18
18
|
exports.default = LogEvent;
|
|
19
19
|
class LoggerOrbit extends logger_1.default {
|
|
20
20
|
queue;
|
|
21
|
-
constructor(queue) {
|
|
22
|
-
super();
|
|
21
|
+
constructor(queue, cache) {
|
|
22
|
+
super(cache);
|
|
23
23
|
this.queue = queue;
|
|
24
24
|
}
|
|
25
25
|
async log(data, props, options) {
|
|
26
|
+
return await super.log(data, props, options);
|
|
27
|
+
}
|
|
28
|
+
async register(data, props, options) {
|
|
26
29
|
const payload = this.buildPayload(data, props);
|
|
27
30
|
try {
|
|
28
31
|
await this.queue.publish('logservice.common.direct', new LogEvent(payload));
|