@seidor-cloud-produtos/orbit-backend-lib 2.0.96 → 2.0.98
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/consistency-event-dispatcher/consistency-event-dispatcher.d.ts +8 -0
- package/dist/clean-arch/application/consistency-event-dispatcher/consistency-event-dispatcher.js +16 -0
- package/dist/clean-arch/application/logger/base-audit-logger.js +1 -1
- package/dist/clean-arch/domain/entities/entity.d.ts +1 -0
- package/dist/clean-arch/domain/entities/entity.js +3 -0
- package/dist/clean-arch/domain/entities/watched-list.d.ts +1 -1
- package/dist/clean-arch/domain/events/consistency-event.d.ts +9 -0
- package/dist/clean-arch/domain/events/consistency-event.js +15 -0
- package/dist/clean-arch/infra/consistency-event-dispatcher/amqp-consistency-event-dispatcher.d.ts +7 -0
- package/dist/clean-arch/infra/consistency-event-dispatcher/amqp-consistency-event-dispatcher.js +15 -0
- package/dist/clean-arch/infra/consistency-event-dispatcher/in-memory-consistency-event-dispatcher.d.ts +8 -0
- package/dist/clean-arch/infra/consistency-event-dispatcher/in-memory-consistency-event-dispatcher.js +15 -0
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.d.ts +2 -10
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.js +13 -5
- package/dist/clean-arch/infra/validations/zod/schemas/common-validation.d.ts +9 -9
- package/dist/clean-arch/infra/validations/zod/schemas/common-validation.js +1 -1
- package/package.json +1 -1
package/dist/clean-arch/application/consistency-event-dispatcher/consistency-event-dispatcher.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AuthorizerHeaders } from '../../infra/http/handle-authorizer-headers';
|
|
2
|
+
import { Entity } from '../../domain/entities/entity';
|
|
3
|
+
import ConsistencyEvent from '../../domain/events/consistency-event';
|
|
4
|
+
export declare abstract class ConsistencyEventDispatcher {
|
|
5
|
+
dispatch(entity: Entity<any>, authorizerHeaders: AuthorizerHeaders, eventName: string): Promise<void>;
|
|
6
|
+
dispatchBatch(entities: Entity<any>[], authorizerHeaders: AuthorizerHeaders, eventName: string): Promise<void>;
|
|
7
|
+
abstract publish(event: ConsistencyEvent): Promise<void>;
|
|
8
|
+
}
|
package/dist/clean-arch/application/consistency-event-dispatcher/consistency-event-dispatcher.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConsistencyEventDispatcher = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const consistency_event_1 = tslib_1.__importDefault(require("../../domain/events/consistency-event"));
|
|
6
|
+
class ConsistencyEventDispatcher {
|
|
7
|
+
async dispatch(entity, authorizerHeaders, eventName) {
|
|
8
|
+
const event = new consistency_event_1.default(entity, authorizerHeaders, eventName);
|
|
9
|
+
await this.publish(event);
|
|
10
|
+
}
|
|
11
|
+
async dispatchBatch(entities, authorizerHeaders, eventName) {
|
|
12
|
+
const events = entities.map(entity => new consistency_event_1.default(entity, authorizerHeaders, eventName));
|
|
13
|
+
await Promise.all(events.map(event => this.publish(event)));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ConsistencyEventDispatcher = ConsistencyEventDispatcher;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AuthorizerHeaders } from '../../infra/http/handle-authorizer-headers';
|
|
2
|
+
import { Entity } from '../entities/entity';
|
|
3
|
+
import DomainEvent from './domain-event';
|
|
4
|
+
export default class ConsistencyEvent implements DomainEvent {
|
|
5
|
+
readonly eventDate: Date;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly input: Record<string, unknown>;
|
|
8
|
+
constructor(entity: Entity<any>, authorizerHeaders: AuthorizerHeaders, eventName: string);
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ConsistencyEvent {
|
|
4
|
+
eventDate = new Date();
|
|
5
|
+
name;
|
|
6
|
+
input;
|
|
7
|
+
constructor(entity, authorizerHeaders, eventName) {
|
|
8
|
+
this.name = eventName;
|
|
9
|
+
this.input = {
|
|
10
|
+
origin: authorizerHeaders,
|
|
11
|
+
payload: entity.toEventDispatchObject(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = ConsistencyEvent;
|
package/dist/clean-arch/infra/consistency-event-dispatcher/amqp-consistency-event-dispatcher.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConsistencyEventDispatcher } from '../../application/consistency-event-dispatcher/consistency-event-dispatcher';
|
|
2
|
+
import ConsistencyEvent from '../../domain/events/consistency-event';
|
|
3
|
+
export declare class InMemoryConsistencyEventDispatcher extends ConsistencyEventDispatcher {
|
|
4
|
+
protected events: ConsistencyEvent[];
|
|
5
|
+
constructor(events?: ConsistencyEvent[]);
|
|
6
|
+
publish(event: ConsistencyEvent): Promise<void>;
|
|
7
|
+
}
|
package/dist/clean-arch/infra/consistency-event-dispatcher/amqp-consistency-event-dispatcher.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryConsistencyEventDispatcher = void 0;
|
|
4
|
+
const consistency_event_dispatcher_1 = require("../../application/consistency-event-dispatcher/consistency-event-dispatcher");
|
|
5
|
+
class InMemoryConsistencyEventDispatcher extends consistency_event_dispatcher_1.ConsistencyEventDispatcher {
|
|
6
|
+
events;
|
|
7
|
+
constructor(events = []) {
|
|
8
|
+
super();
|
|
9
|
+
this.events = events;
|
|
10
|
+
}
|
|
11
|
+
async publish(event) {
|
|
12
|
+
this.events.push(event);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.InMemoryConsistencyEventDispatcher = InMemoryConsistencyEventDispatcher;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ConsistencyEventDispatcher } from '../../application/consistency-event-dispatcher/consistency-event-dispatcher';
|
|
2
|
+
import AmqpQueue from '../queue/rabbitmq/amqp-lib';
|
|
3
|
+
import ConsistencyEvent from '../../domain/events/consistency-event';
|
|
4
|
+
export declare class AmqpConsistencyEventDispatcher extends ConsistencyEventDispatcher {
|
|
5
|
+
protected amqp: AmqpQueue;
|
|
6
|
+
constructor(amqp: AmqpQueue);
|
|
7
|
+
publish(event: ConsistencyEvent): Promise<void>;
|
|
8
|
+
}
|
package/dist/clean-arch/infra/consistency-event-dispatcher/in-memory-consistency-event-dispatcher.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmqpConsistencyEventDispatcher = void 0;
|
|
4
|
+
const consistency_event_dispatcher_1 = require("../../application/consistency-event-dispatcher/consistency-event-dispatcher");
|
|
5
|
+
class AmqpConsistencyEventDispatcher extends consistency_event_dispatcher_1.ConsistencyEventDispatcher {
|
|
6
|
+
amqp;
|
|
7
|
+
constructor(amqp) {
|
|
8
|
+
super();
|
|
9
|
+
this.amqp = amqp;
|
|
10
|
+
}
|
|
11
|
+
async publish(event) {
|
|
12
|
+
await this.amqp.publish(event.name, event, { storeMessageOnError: false });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.AmqpConsistencyEventDispatcher = AmqpConsistencyEventDispatcher;
|
|
@@ -4,24 +4,16 @@ import QueueConnection from '../../../application/queue/queue-connection';
|
|
|
4
4
|
import DomainEvent from '../../../domain/events/domain-event';
|
|
5
5
|
import { AmqpQueueGetResult } from './types';
|
|
6
6
|
import { Logger } from '../../../application/logger';
|
|
7
|
-
interface SocketOptions {
|
|
8
|
-
retry?: {
|
|
9
|
-
maxCount: number;
|
|
10
|
-
intervalMs: number;
|
|
11
|
-
};
|
|
12
|
-
timeoutSeconds?: number;
|
|
13
|
-
}
|
|
14
7
|
/**
|
|
15
8
|
* Opções de socket/conexão para o AMQP.
|
|
16
9
|
*/
|
|
17
10
|
interface SocketOptions {
|
|
18
|
-
/**
|
|
19
|
-
* Política simples de retry para a conexão inicial.
|
|
20
|
-
*/
|
|
21
11
|
retry?: {
|
|
22
12
|
maxCount: number;
|
|
23
13
|
intervalMs: number;
|
|
24
14
|
};
|
|
15
|
+
timeoutSeconds?: number;
|
|
16
|
+
maxStoredMessagesOnError?: number;
|
|
25
17
|
}
|
|
26
18
|
/**
|
|
27
19
|
* Implementação de fila baseada em AMQP (RabbitMQ) usando `amqplib`.
|
|
@@ -32,7 +32,10 @@ class AmqpQueue {
|
|
|
32
32
|
* Define (ou atualiza) as opções de conexão.
|
|
33
33
|
*/
|
|
34
34
|
setSocketOptions(socketOptions) {
|
|
35
|
-
this.socketOptions =
|
|
35
|
+
this.socketOptions = {
|
|
36
|
+
...(socketOptions || {}),
|
|
37
|
+
maxStoredMessagesOnError: 500,
|
|
38
|
+
};
|
|
36
39
|
return this;
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
@@ -194,15 +197,20 @@ class AmqpQueue {
|
|
|
194
197
|
return result;
|
|
195
198
|
}
|
|
196
199
|
catch (err) {
|
|
200
|
+
this.logger.info({
|
|
201
|
+
message: `⛔ Error to publish messages to: ${domainEvent.name}.`,
|
|
202
|
+
error: err,
|
|
203
|
+
});
|
|
204
|
+
if (buildedConfigs.storeMessageOnError === false ||
|
|
205
|
+
(this.socketOptions?.maxStoredMessagesOnError || 0) <
|
|
206
|
+
this.messagesInMemory.length) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
197
209
|
this.messagesInMemory.push({
|
|
198
210
|
exchangeName,
|
|
199
211
|
domainEvent,
|
|
200
212
|
configs: buildedConfigs,
|
|
201
213
|
});
|
|
202
|
-
this.logger.info({
|
|
203
|
-
message: `⛔ Error to publish messages to: ${domainEvent.name}. Publish in memory!`,
|
|
204
|
-
error: err,
|
|
205
|
-
});
|
|
206
214
|
}
|
|
207
215
|
}
|
|
208
216
|
async publishToServer(exchangeName, domainEvent, buildedConfigs) {
|
|
@@ -74,11 +74,11 @@ export declare const traceSchema: z.ZodObject<{
|
|
|
74
74
|
"x-trace-id"?: string | undefined;
|
|
75
75
|
}>;
|
|
76
76
|
export declare const tenantSchema: z.ZodObject<{
|
|
77
|
-
tenantname: z.ZodString
|
|
77
|
+
tenantname: z.ZodOptional<z.ZodString>;
|
|
78
78
|
}, "strip", z.ZodTypeAny, {
|
|
79
|
-
tenantname
|
|
79
|
+
tenantname?: string | undefined;
|
|
80
80
|
}, {
|
|
81
|
-
tenantname
|
|
81
|
+
tenantname?: string | undefined;
|
|
82
82
|
}>;
|
|
83
83
|
export declare const integrationHeaders: z.ZodObject<z.objectUtil.extendShape<{
|
|
84
84
|
tenantid: z.ZodString;
|
|
@@ -100,21 +100,21 @@ export declare const authorizerHeaders: z.ZodUnion<[z.ZodObject<z.objectUtil.ext
|
|
|
100
100
|
}, {
|
|
101
101
|
"x-trace-id": z.ZodDefault<z.ZodString>;
|
|
102
102
|
}>>, {
|
|
103
|
-
tenantname: z.ZodString
|
|
103
|
+
tenantname: z.ZodOptional<z.ZodString>;
|
|
104
104
|
}>, "strip", z.ZodTypeAny, {
|
|
105
105
|
"x-trace-id": string;
|
|
106
106
|
username: string;
|
|
107
107
|
tenantid: string;
|
|
108
108
|
useremail: string;
|
|
109
|
-
tenantname: string;
|
|
110
109
|
userid?: string | undefined;
|
|
110
|
+
tenantname?: string | undefined;
|
|
111
111
|
}, {
|
|
112
112
|
username: string;
|
|
113
113
|
tenantid: string;
|
|
114
114
|
useremail: string;
|
|
115
|
-
tenantname: string;
|
|
116
115
|
"x-trace-id"?: string | undefined;
|
|
117
116
|
userid?: string | undefined;
|
|
117
|
+
tenantname?: string | undefined;
|
|
118
118
|
}>, z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{
|
|
119
119
|
"app-name": z.ZodString;
|
|
120
120
|
"app-id": z.ZodString;
|
|
@@ -123,19 +123,19 @@ export declare const authorizerHeaders: z.ZodUnion<[z.ZodObject<z.objectUtil.ext
|
|
|
123
123
|
}, {
|
|
124
124
|
"x-trace-id": z.ZodDefault<z.ZodString>;
|
|
125
125
|
}>>, {
|
|
126
|
-
tenantname: z.ZodString
|
|
126
|
+
tenantname: z.ZodOptional<z.ZodString>;
|
|
127
127
|
}>, "strip", z.ZodTypeAny, {
|
|
128
128
|
"app-id": string;
|
|
129
129
|
"app-name": string;
|
|
130
130
|
"x-trace-id": string;
|
|
131
131
|
tenantid: string;
|
|
132
|
-
tenantname
|
|
132
|
+
tenantname?: string | undefined;
|
|
133
133
|
}, {
|
|
134
134
|
"app-id": string;
|
|
135
135
|
"app-name": string;
|
|
136
136
|
tenantid: string;
|
|
137
|
-
tenantname: string;
|
|
138
137
|
"x-trace-id"?: string | undefined;
|
|
138
|
+
tenantname?: string | undefined;
|
|
139
139
|
}>]>;
|
|
140
140
|
export declare const authorizerHeadersWithFiscalIds: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{
|
|
141
141
|
username: z.ZodString;
|
|
@@ -49,7 +49,7 @@ const fiscalIdsSchema = zod_1.z.object({
|
|
|
49
49
|
}))),
|
|
50
50
|
});
|
|
51
51
|
exports.tenantSchema = zod_1.z.object({
|
|
52
|
-
tenantname: zod_1.z.string(),
|
|
52
|
+
tenantname: zod_1.z.string().optional(),
|
|
53
53
|
});
|
|
54
54
|
exports.integrationHeaders = exports.tenantIdSchema.merge(exports.traceSchema);
|
|
55
55
|
exports.authorizerHeaders = zod_1.z.union([
|