@seidor-cloud-produtos/orbit-backend-lib 2.0.91 → 2.0.93
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/logger/base-audit-logger.d.ts +10 -0
- package/dist/clean-arch/application/logger/base-audit-logger.js +28 -0
- package/dist/clean-arch/application/logger/index.d.ts +13 -4
- package/dist/clean-arch/application/logger/index.js +4 -4
- package/dist/clean-arch/domain/entities/entity.d.ts +2 -0
- package/dist/clean-arch/domain/entities/entity.js +28 -0
- package/dist/clean-arch/domain/entities/watched-list.d.ts +1 -0
- package/dist/clean-arch/domain/entities/watched-list.js +9 -0
- package/dist/clean-arch/infra/logger/logger-in-memory.d.ts +8 -2
- package/dist/clean-arch/infra/logger/logger-in-memory.js +2 -2
- package/dist/clean-arch/infra/logger/logger-orbit.d.ts +12 -1
- package/dist/clean-arch/infra/logger/logger-orbit.js +21 -3
- package/dist/clean-arch/infra/validations/zod/schemas/common-validation.d.ts +23 -8
- package/dist/clean-arch/infra/validations/zod/schemas/common-validation.js +6 -3
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthorizerHeaders } from '../../infra/http/handle-authorizer-headers';
|
|
2
|
+
import LoggerGateway, { Trace } from '.';
|
|
3
|
+
import { LogOrbitParams } from '../../infra/logger/logger-orbit';
|
|
4
|
+
export declare abstract class BaseAuditLogger {
|
|
5
|
+
protected readonly gateway: LoggerGateway;
|
|
6
|
+
protected defaultExpirationHours: number;
|
|
7
|
+
constructor(gateway: LoggerGateway);
|
|
8
|
+
protected buildParams(type: string, authorizerHeaders: AuthorizerHeaders, trace: Trace): LogOrbitParams;
|
|
9
|
+
protected info(payload: any, params: LogOrbitParams): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseAuditLogger = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const FIVE_YEARS_IN_HOURS = 24 * 365 * 5;
|
|
6
|
+
class BaseAuditLogger {
|
|
7
|
+
gateway;
|
|
8
|
+
defaultExpirationHours = FIVE_YEARS_IN_HOURS;
|
|
9
|
+
constructor(gateway) {
|
|
10
|
+
this.gateway = gateway;
|
|
11
|
+
}
|
|
12
|
+
buildParams(type, authorizerHeaders, trace) {
|
|
13
|
+
trace?.ids.push(authorizerHeaders.traceId);
|
|
14
|
+
return {
|
|
15
|
+
type,
|
|
16
|
+
trace,
|
|
17
|
+
actor: authorizerHeaders.entityId,
|
|
18
|
+
tenantId: authorizerHeaders.tenantId,
|
|
19
|
+
actorType: _1.ActorEnum.USER,
|
|
20
|
+
category: _1.CategoryEnum.BUSINESS,
|
|
21
|
+
expirationHours: this.defaultExpirationHours,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async info(payload, params) {
|
|
25
|
+
return await this.gateway.info({ payload }, params);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.BaseAuditLogger = BaseAuditLogger;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { LOG_LEVEL } from '../../infra/environment/types';
|
|
2
2
|
import { Cache } from '../cache/cache';
|
|
3
|
+
export interface Trace {
|
|
4
|
+
mainId?: string;
|
|
5
|
+
ids: string[];
|
|
6
|
+
}
|
|
3
7
|
/**
|
|
4
8
|
* Identifica o tipo de ator que originou o log.
|
|
5
9
|
*/
|
|
@@ -55,6 +59,11 @@ export interface Logger {
|
|
|
55
59
|
error: (...input: any[]) => Promise<void> | void;
|
|
56
60
|
debug: (...input: any[]) => Promise<void> | void;
|
|
57
61
|
}
|
|
62
|
+
export type LoggerGatewayProps = {
|
|
63
|
+
cache?: Cache;
|
|
64
|
+
options?: LogOptions;
|
|
65
|
+
params?: LogParamsInput;
|
|
66
|
+
};
|
|
58
67
|
/**
|
|
59
68
|
* Classe base para loggers.
|
|
60
69
|
*
|
|
@@ -64,10 +73,10 @@ export interface Logger {
|
|
|
64
73
|
* - Delegar o envio para a implementação concreta (`register`).
|
|
65
74
|
*/
|
|
66
75
|
export default abstract class LoggerGateway implements Logger {
|
|
67
|
-
protected cache?: Cache
|
|
68
|
-
protected options?: LogOptions
|
|
69
|
-
protected params?:
|
|
70
|
-
constructor(
|
|
76
|
+
protected cache?: Cache;
|
|
77
|
+
protected options?: LogOptions;
|
|
78
|
+
protected params?: LogParamsInput;
|
|
79
|
+
constructor(props: LoggerGatewayProps);
|
|
71
80
|
private static cacheKey;
|
|
72
81
|
/**
|
|
73
82
|
* Loga com nível `info`.
|
|
@@ -30,10 +30,10 @@ class LoggerGateway {
|
|
|
30
30
|
cache;
|
|
31
31
|
options;
|
|
32
32
|
params;
|
|
33
|
-
constructor(
|
|
34
|
-
this.cache = cache;
|
|
35
|
-
this.options = options;
|
|
36
|
-
this.params = params;
|
|
33
|
+
constructor(props) {
|
|
34
|
+
this.cache = props.cache;
|
|
35
|
+
this.options = props.options;
|
|
36
|
+
this.params = props.params;
|
|
37
37
|
}
|
|
38
38
|
static cacheKey = 'LOG_LEVEL';
|
|
39
39
|
/**
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Entity = void 0;
|
|
4
4
|
const unique_entity_id_1 = require("./unique-entity-id");
|
|
5
|
+
const watched_list_1 = require("./watched-list");
|
|
5
6
|
class Entity {
|
|
6
7
|
_id;
|
|
7
8
|
props;
|
|
@@ -24,5 +25,32 @@ class Entity {
|
|
|
24
25
|
}
|
|
25
26
|
return false;
|
|
26
27
|
}
|
|
28
|
+
serializeValue(value) {
|
|
29
|
+
if (value instanceof Entity) {
|
|
30
|
+
return value.toObject();
|
|
31
|
+
}
|
|
32
|
+
if (value instanceof Date) {
|
|
33
|
+
return value.toISOString();
|
|
34
|
+
}
|
|
35
|
+
if (value instanceof unique_entity_id_1.UniqueEntityId) {
|
|
36
|
+
return value.toString();
|
|
37
|
+
}
|
|
38
|
+
if (value instanceof watched_list_1.WatchedList) {
|
|
39
|
+
return value.toObject();
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
return value.map(item => this.serializeValue(item));
|
|
43
|
+
}
|
|
44
|
+
if (value && typeof value === 'object') {
|
|
45
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
46
|
+
key,
|
|
47
|
+
this.serializeValue(item),
|
|
48
|
+
]));
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
toObject() {
|
|
53
|
+
return this.serializeValue(this.props);
|
|
54
|
+
}
|
|
27
55
|
}
|
|
28
56
|
exports.Entity = Entity;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WatchedList = void 0;
|
|
4
|
+
const entity_1 = require("./entity");
|
|
4
5
|
class WatchedList {
|
|
5
6
|
currentItems;
|
|
6
7
|
initial;
|
|
@@ -89,5 +90,13 @@ class WatchedList {
|
|
|
89
90
|
this.removed = removedItems;
|
|
90
91
|
this.updated = updatedItems;
|
|
91
92
|
}
|
|
93
|
+
toObject() {
|
|
94
|
+
return this.currentItems.map(item => {
|
|
95
|
+
if (item instanceof entity_1.Entity) {
|
|
96
|
+
return item.toObject();
|
|
97
|
+
}
|
|
98
|
+
return item;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
92
101
|
}
|
|
93
102
|
exports.WatchedList = WatchedList;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Cache } from '../../../clean-arch/application/cache/cache';
|
|
2
|
-
import LoggerGateway, { LogOptions,
|
|
2
|
+
import LoggerGateway, { LogOptions, LogPropertiesInput } from '../../application/logger';
|
|
3
|
+
import { LogOrbitParamsInput } from './logger-orbit';
|
|
3
4
|
export interface LoggerInMemoryOptions extends LogOptions {
|
|
4
5
|
/**
|
|
5
6
|
* Quando `true`, inclui as propriedades do log na saída do console.
|
|
@@ -7,6 +8,11 @@ export interface LoggerInMemoryOptions extends LogOptions {
|
|
|
7
8
|
*/
|
|
8
9
|
showProps?: boolean;
|
|
9
10
|
}
|
|
11
|
+
export type LoggerInMemoryProps = {
|
|
12
|
+
cache?: Cache;
|
|
13
|
+
options?: LoggerInMemoryOptions;
|
|
14
|
+
params?: LogOrbitParamsInput;
|
|
15
|
+
};
|
|
10
16
|
/**
|
|
11
17
|
* Logger simples que escreve no console.
|
|
12
18
|
*
|
|
@@ -20,7 +26,7 @@ export declare class LoggerInMemory extends LoggerGateway {
|
|
|
20
26
|
* @param options Opções de comportamento do logger.
|
|
21
27
|
* @param params Parâmetros padrão de log (actor/type).
|
|
22
28
|
*/
|
|
23
|
-
constructor(
|
|
29
|
+
constructor(props: LoggerInMemoryProps);
|
|
24
30
|
/**
|
|
25
31
|
* Delegado para o fluxo comum de LoggerGateway.
|
|
26
32
|
* Mantido como atalho para compatibilidade com outros loggers.
|
|
@@ -16,8 +16,8 @@ class LoggerInMemory extends logger_1.default {
|
|
|
16
16
|
* @param options Opções de comportamento do logger.
|
|
17
17
|
* @param params Parâmetros padrão de log (actor/type).
|
|
18
18
|
*/
|
|
19
|
-
constructor(
|
|
20
|
-
super(
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Delegado para o fluxo comum de LoggerGateway.
|
|
@@ -60,6 +60,11 @@ export type LogPayload = Omit<LogProperties, 'expirationHours'> & {
|
|
|
60
60
|
expirationDate: Date;
|
|
61
61
|
details: any;
|
|
62
62
|
};
|
|
63
|
+
export type LoggerOrbitProps = {
|
|
64
|
+
cache?: Cache;
|
|
65
|
+
options?: LoggerOrbitOptions;
|
|
66
|
+
params?: LogOrbitParamsInput;
|
|
67
|
+
};
|
|
63
68
|
/**
|
|
64
69
|
* Evento de domínio enviado para o serviço de logs.
|
|
65
70
|
*/
|
|
@@ -80,7 +85,7 @@ export declare class LoggerOrbit extends LoggerGateway {
|
|
|
80
85
|
private queue;
|
|
81
86
|
protected options: LoggerOrbitOptions;
|
|
82
87
|
protected params?: LogOrbitParamsInput;
|
|
83
|
-
constructor(queue: Queue,
|
|
88
|
+
constructor(queue: Queue, props: LoggerOrbitProps);
|
|
84
89
|
/**
|
|
85
90
|
* Loga um evento (atalho para `super.log`).
|
|
86
91
|
*/
|
|
@@ -116,3 +121,9 @@ export declare class LoggerOrbit extends LoggerGateway {
|
|
|
116
121
|
*/
|
|
117
122
|
protected buildDefaultProps(params?: LogOrbitParamsInput): LogOrbitProperties;
|
|
118
123
|
}
|
|
124
|
+
export declare class BaseAuditOrbitLogger {
|
|
125
|
+
private static instance;
|
|
126
|
+
protected constructor();
|
|
127
|
+
static getInstance(queue: Queue, props?: LoggerOrbitProps): LoggerOrbit;
|
|
128
|
+
private static buildProps;
|
|
129
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LoggerOrbit = void 0;
|
|
3
|
+
exports.BaseAuditOrbitLogger = exports.LoggerOrbit = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const logger_1 = tslib_1.__importStar(require("../../application/logger"));
|
|
6
6
|
const log_error_1 = tslib_1.__importDefault(require("../../domain/errors/log-error"));
|
|
@@ -25,8 +25,8 @@ exports.default = LogEvent;
|
|
|
25
25
|
*/
|
|
26
26
|
class LoggerOrbit extends logger_1.default {
|
|
27
27
|
queue;
|
|
28
|
-
constructor(queue,
|
|
29
|
-
super(
|
|
28
|
+
constructor(queue, props) {
|
|
29
|
+
super(props);
|
|
30
30
|
this.queue = queue;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -100,3 +100,21 @@ class LoggerOrbit extends logger_1.default {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
exports.LoggerOrbit = LoggerOrbit;
|
|
103
|
+
class BaseAuditOrbitLogger {
|
|
104
|
+
static instance;
|
|
105
|
+
constructor() { }
|
|
106
|
+
static getInstance(queue, props) {
|
|
107
|
+
if (!this.instance) {
|
|
108
|
+
this.instance = new LoggerOrbit(queue, this.buildProps(props));
|
|
109
|
+
}
|
|
110
|
+
return this.instance;
|
|
111
|
+
}
|
|
112
|
+
static buildProps(props = {}) {
|
|
113
|
+
props.options = props.options || {
|
|
114
|
+
throwOnError: false,
|
|
115
|
+
lastArgIsParams: true,
|
|
116
|
+
};
|
|
117
|
+
return props;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.BaseAuditOrbitLogger = BaseAuditOrbitLogger;
|
|
@@ -73,6 +73,13 @@ export declare const traceSchema: z.ZodObject<{
|
|
|
73
73
|
}, {
|
|
74
74
|
"x-trace-id"?: string | undefined;
|
|
75
75
|
}>;
|
|
76
|
+
export declare const tenantSchema: z.ZodObject<{
|
|
77
|
+
tenantname: z.ZodString;
|
|
78
|
+
}, "strip", z.ZodTypeAny, {
|
|
79
|
+
tenantname: string;
|
|
80
|
+
}, {
|
|
81
|
+
tenantname: string;
|
|
82
|
+
}>;
|
|
76
83
|
export declare const integrationHeaders: z.ZodObject<z.objectUtil.extendShape<{
|
|
77
84
|
tenantid: z.ZodString;
|
|
78
85
|
}, {
|
|
@@ -84,7 +91,7 @@ export declare const integrationHeaders: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
84
91
|
tenantid: string;
|
|
85
92
|
"x-trace-id"?: string | undefined;
|
|
86
93
|
}>;
|
|
87
|
-
export declare const authorizerHeaders: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
|
|
94
|
+
export declare const authorizerHeaders: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{
|
|
88
95
|
username: z.ZodString;
|
|
89
96
|
useremail: z.ZodString;
|
|
90
97
|
userid: z.ZodOptional<z.ZodString>;
|
|
@@ -92,34 +99,42 @@ export declare const authorizerHeaders: z.ZodUnion<[z.ZodObject<z.objectUtil.ext
|
|
|
92
99
|
tenantid: z.ZodString;
|
|
93
100
|
}, {
|
|
94
101
|
"x-trace-id": z.ZodDefault<z.ZodString>;
|
|
95
|
-
}>>,
|
|
96
|
-
|
|
102
|
+
}>>, {
|
|
103
|
+
tenantname: z.ZodString;
|
|
104
|
+
}>, "strip", z.ZodTypeAny, {
|
|
97
105
|
"x-trace-id": string;
|
|
106
|
+
username: string;
|
|
98
107
|
tenantid: string;
|
|
99
108
|
useremail: string;
|
|
109
|
+
tenantname: string;
|
|
100
110
|
userid?: string | undefined;
|
|
101
111
|
}, {
|
|
102
112
|
username: string;
|
|
103
113
|
tenantid: string;
|
|
104
114
|
useremail: string;
|
|
115
|
+
tenantname: string;
|
|
105
116
|
"x-trace-id"?: string | undefined;
|
|
106
117
|
userid?: string | undefined;
|
|
107
|
-
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
118
|
+
}>, z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{
|
|
108
119
|
"app-name": z.ZodString;
|
|
109
120
|
"app-id": z.ZodString;
|
|
110
121
|
}, z.objectUtil.extendShape<{
|
|
111
122
|
tenantid: z.ZodString;
|
|
112
123
|
}, {
|
|
113
124
|
"x-trace-id": z.ZodDefault<z.ZodString>;
|
|
114
|
-
}>>,
|
|
125
|
+
}>>, {
|
|
126
|
+
tenantname: z.ZodString;
|
|
127
|
+
}>, "strip", z.ZodTypeAny, {
|
|
115
128
|
"app-id": string;
|
|
116
129
|
"app-name": string;
|
|
117
130
|
"x-trace-id": string;
|
|
118
131
|
tenantid: string;
|
|
132
|
+
tenantname: string;
|
|
119
133
|
}, {
|
|
120
134
|
"app-id": string;
|
|
121
135
|
"app-name": string;
|
|
122
136
|
tenantid: string;
|
|
137
|
+
tenantname: string;
|
|
123
138
|
"x-trace-id"?: string | undefined;
|
|
124
139
|
}>]>;
|
|
125
140
|
export declare const authorizerHeadersWithFiscalIds: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{
|
|
@@ -133,9 +148,9 @@ export declare const authorizerHeadersWithFiscalIds: z.ZodUnion<[z.ZodObject<z.o
|
|
|
133
148
|
}, {
|
|
134
149
|
"x-trace-id": z.ZodDefault<z.ZodString>;
|
|
135
150
|
}>>, "strip", z.ZodTypeAny, {
|
|
151
|
+
"x-trace-id": string;
|
|
136
152
|
fiscalidsfromtenant: string;
|
|
137
153
|
username: string;
|
|
138
|
-
"x-trace-id": string;
|
|
139
154
|
tenantid: string;
|
|
140
155
|
useremail: string;
|
|
141
156
|
userid?: string | undefined;
|
|
@@ -156,15 +171,15 @@ export declare const authorizerHeadersWithFiscalIds: z.ZodUnion<[z.ZodObject<z.o
|
|
|
156
171
|
}, {
|
|
157
172
|
"x-trace-id": z.ZodDefault<z.ZodString>;
|
|
158
173
|
}>>, "strip", z.ZodTypeAny, {
|
|
159
|
-
fiscalidsfromtenant: string;
|
|
160
174
|
"app-id": string;
|
|
161
175
|
"app-name": string;
|
|
162
176
|
"x-trace-id": string;
|
|
177
|
+
fiscalidsfromtenant: string;
|
|
163
178
|
tenantid: string;
|
|
164
179
|
}, {
|
|
165
|
-
fiscalidsfromtenant: string;
|
|
166
180
|
"app-id": string;
|
|
167
181
|
"app-name": string;
|
|
182
|
+
fiscalidsfromtenant: string;
|
|
168
183
|
tenantid: string;
|
|
169
184
|
"x-trace-id"?: string | undefined;
|
|
170
185
|
}>]>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.headersDefaultWithFiscalIds = exports.authorizerHeadersWithFiscalIds = exports.authorizerHeaders = exports.integrationHeaders = exports.traceSchema = exports.appSchema = exports.userSchema = exports.tenantIdSchema = exports.headersDefaultWithUserId = exports.headersDefault = void 0;
|
|
3
|
+
exports.headersDefaultWithFiscalIds = exports.authorizerHeadersWithFiscalIds = exports.authorizerHeaders = exports.integrationHeaders = exports.tenantSchema = exports.traceSchema = exports.appSchema = exports.userSchema = exports.tenantIdSchema = exports.headersDefaultWithUserId = exports.headersDefault = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
@@ -48,10 +48,13 @@ const fiscalIdsSchema = zod_1.z.object({
|
|
|
48
48
|
countryCode: zod_1.z.string(),
|
|
49
49
|
}))),
|
|
50
50
|
});
|
|
51
|
+
exports.tenantSchema = zod_1.z.object({
|
|
52
|
+
tenantname: zod_1.z.string(),
|
|
53
|
+
});
|
|
51
54
|
exports.integrationHeaders = exports.tenantIdSchema.merge(exports.traceSchema);
|
|
52
55
|
exports.authorizerHeaders = zod_1.z.union([
|
|
53
|
-
exports.userSchema.merge(exports.integrationHeaders),
|
|
54
|
-
exports.appSchema.merge(exports.integrationHeaders),
|
|
56
|
+
exports.userSchema.merge(exports.integrationHeaders).merge(exports.tenantSchema),
|
|
57
|
+
exports.appSchema.merge(exports.integrationHeaders).merge(exports.tenantSchema),
|
|
55
58
|
]);
|
|
56
59
|
exports.authorizerHeadersWithFiscalIds = zod_1.z.union([
|
|
57
60
|
exports.userSchema.merge(fiscalIdsSchema).merge(exports.integrationHeaders),
|