@seidor-cloud-produtos/orbit-backend-lib 2.0.73 → 2.0.75
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/index.d.ts +6 -4
- package/dist/clean-arch/application/logger/index.js +4 -1
- package/dist/clean-arch/infra/http/handle-authorizer-headers.d.ts +15 -0
- package/dist/clean-arch/infra/http/handle-authorizer-headers.js +12 -0
- package/dist/clean-arch/infra/http/handle-user-headers.d.ts +3 -0
- package/dist/clean-arch/infra/http/handle-user-headers.js +1 -0
- package/dist/clean-arch/infra/logger/logger-in-memory.d.ts +2 -2
- package/dist/clean-arch/infra/logger/logger-orbit.d.ts +5 -3
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.d.ts +6 -0
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.js +15 -1
- package/dist/clean-arch/infra/validations/zod/schemas/common-validation.d.ts +22 -0
- package/dist/clean-arch/infra/validations/zod/schemas/common-validation.js +11 -1
- package/package.json +1 -1
|
@@ -21,6 +21,8 @@ export interface LogParams {
|
|
|
21
21
|
actor: string;
|
|
22
22
|
type: string;
|
|
23
23
|
}
|
|
24
|
+
export interface LogParamsInput extends Partial<LogParams> {
|
|
25
|
+
}
|
|
24
26
|
export interface LogOptions {
|
|
25
27
|
lastArgIsParams?: boolean;
|
|
26
28
|
}
|
|
@@ -33,8 +35,8 @@ export interface Logger {
|
|
|
33
35
|
export default abstract class LoggerGateway implements Logger {
|
|
34
36
|
protected cache?: Cache | undefined;
|
|
35
37
|
protected options?: LogOptions | undefined;
|
|
36
|
-
protected params?:
|
|
37
|
-
constructor(cache?: Cache | undefined, options?: LogOptions | undefined, params?:
|
|
38
|
+
protected params?: LogParamsInput | undefined;
|
|
39
|
+
constructor(cache?: Cache | undefined, options?: LogOptions | undefined, params?: LogParamsInput | undefined);
|
|
38
40
|
private static cacheKey;
|
|
39
41
|
info(...input: any[]): Promise<void>;
|
|
40
42
|
warn(...input: any[]): Promise<void>;
|
|
@@ -44,8 +46,8 @@ export default abstract class LoggerGateway implements Logger {
|
|
|
44
46
|
protected abstract register(props: LogProperties, dataToLog: any, params?: LogParams): Promise<void> | void;
|
|
45
47
|
private static buildAcceptLogLevelValues;
|
|
46
48
|
protected isToLog(props: LogProperties, dataToLog: any): Promise<boolean>;
|
|
47
|
-
protected buildProps(props?: LogPropertiesInput, params?:
|
|
48
|
-
protected buildDefaultProps(params?:
|
|
49
|
+
protected buildProps(props?: LogPropertiesInput, params?: LogParamsInput): LogProperties;
|
|
50
|
+
protected buildDefaultProps(params?: LogParamsInput): LogProperties;
|
|
49
51
|
setLevel(level: LOG_LEVEL, filter: {
|
|
50
52
|
logType: string;
|
|
51
53
|
logActor: string;
|
|
@@ -38,7 +38,10 @@ class LoggerGateway {
|
|
|
38
38
|
try {
|
|
39
39
|
let params = this.params;
|
|
40
40
|
if (this.options?.lastArgIsParams && dataToLog instanceof Array) {
|
|
41
|
-
params =
|
|
41
|
+
params = {
|
|
42
|
+
...(params || {}),
|
|
43
|
+
...dataToLog[dataToLog.length - 1],
|
|
44
|
+
};
|
|
42
45
|
dataToLog = dataToLog.slice(0, dataToLog.length - 1);
|
|
43
46
|
}
|
|
44
47
|
const buildedProperties = this.buildProps(props, params);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type HeadersProps = {
|
|
2
|
+
username?: string;
|
|
3
|
+
useremail?: string;
|
|
4
|
+
userid?: string;
|
|
5
|
+
['app-id']?: string;
|
|
6
|
+
['app-name']?: string;
|
|
7
|
+
};
|
|
8
|
+
export type AuthorizerHeaders = {
|
|
9
|
+
userName?: string;
|
|
10
|
+
userEmail?: string;
|
|
11
|
+
appName?: string;
|
|
12
|
+
entityId: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function handleAuthorizerHeaders(headers: HeadersProps): AuthorizerHeaders;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleAuthorizerHeaders = void 0;
|
|
4
|
+
function handleAuthorizerHeaders(headers) {
|
|
5
|
+
return {
|
|
6
|
+
userName: headers.username,
|
|
7
|
+
userEmail: headers.useremail,
|
|
8
|
+
appName: headers['app-name'],
|
|
9
|
+
entityId: (headers.userid || headers['app-id']),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
exports.handleAuthorizerHeaders = handleAuthorizerHeaders;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
type HeadersProps = {
|
|
2
2
|
username: string;
|
|
3
3
|
useremail: string;
|
|
4
|
+
userid: string;
|
|
5
|
+
['app-id']: string;
|
|
4
6
|
};
|
|
5
7
|
export declare function handleUserHeaders(headers: HeadersProps): {
|
|
6
8
|
createdByName: string;
|
|
7
9
|
createdByEmail: string;
|
|
8
10
|
updatedByEmail: string;
|
|
9
11
|
updatedByName: string;
|
|
12
|
+
entityId: string;
|
|
10
13
|
};
|
|
11
14
|
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import LoggerGateway, { LogOptions,
|
|
1
|
+
import LoggerGateway, { LogOptions, LogParamsInput, LogPropertiesInput } from '../../application/logger';
|
|
2
2
|
import { Cache } from '../../../clean-arch/application/cache/cache';
|
|
3
3
|
export interface LoggerInMemoryOptions extends LogOptions {
|
|
4
4
|
showProps?: boolean;
|
|
5
5
|
}
|
|
6
6
|
export declare class LoggerInMemory extends LoggerGateway {
|
|
7
7
|
protected options: LoggerInMemoryOptions;
|
|
8
|
-
constructor(cache?: Cache, options?: LoggerInMemoryOptions, params?:
|
|
8
|
+
constructor(cache?: Cache, options?: LoggerInMemoryOptions, params?: LogParamsInput);
|
|
9
9
|
log(props: LogPropertiesInput, dataToLog: any): Promise<void>;
|
|
10
10
|
protected register(props: LogPropertiesInput, dataToLog: any): void;
|
|
11
11
|
}
|
|
@@ -32,6 +32,8 @@ export interface LogOrbitParams extends LogParams {
|
|
|
32
32
|
category: CategoryEnum;
|
|
33
33
|
expirationHours: number;
|
|
34
34
|
}
|
|
35
|
+
export interface LogOrbitParamsInput extends Partial<LogOrbitParams> {
|
|
36
|
+
}
|
|
35
37
|
export type LogPayload = Omit<LogProperties, 'expirationHours'> & {
|
|
36
38
|
expirationDate: Date;
|
|
37
39
|
details: any;
|
|
@@ -45,11 +47,11 @@ export default class LogEvent implements DomainEvent {
|
|
|
45
47
|
export declare class LoggerOrbit extends LoggerGateway {
|
|
46
48
|
private queue;
|
|
47
49
|
protected options: LoggerOrbitOptions;
|
|
48
|
-
protected params?:
|
|
49
|
-
constructor(queue: Queue, cache?: Cache, options?: LoggerOrbitOptions, params?:
|
|
50
|
+
protected params?: LogOrbitParamsInput;
|
|
51
|
+
constructor(queue: Queue, cache?: Cache, options?: LoggerOrbitOptions, params?: LogOrbitParamsInput);
|
|
50
52
|
log(props: LogOrbitPropertiesInput, dataToLog: any): Promise<void>;
|
|
51
53
|
protected isToLog(props: LogOrbitProperties, dataToLog: any): Promise<boolean>;
|
|
52
54
|
register(props: LogOrbitProperties, data: any): Promise<void>;
|
|
53
55
|
private buildPayload;
|
|
54
|
-
protected buildDefaultProps(params?:
|
|
56
|
+
protected buildDefaultProps(params?: LogOrbitParamsInput): LogOrbitProperties;
|
|
55
57
|
}
|
|
@@ -31,7 +31,12 @@ export default class AmqpQueue implements QueueConnection {
|
|
|
31
31
|
publish(exchangeName: string, domainEvent: DomainEvent, configs?: Record<string, any>): Promise<void>;
|
|
32
32
|
private publishToServer;
|
|
33
33
|
private static delayOperation;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @deprecated Use createQueues() instead.
|
|
37
|
+
*/
|
|
34
38
|
createConsumers(queueName: string, configs: CreateConsumers): Promise<void>;
|
|
39
|
+
createQueues(queueName: string, configs: CreateConsumers): Promise<void>;
|
|
35
40
|
static getInstance(vHost?: string, socketOptions?: SocketOptions, uri?: string): Promise<AmqpQueue>;
|
|
36
41
|
private treatReconnection;
|
|
37
42
|
private reconnectionChannels;
|
|
@@ -41,5 +46,6 @@ type CreateConsumers = {
|
|
|
41
46
|
exchangeName: string;
|
|
42
47
|
exchangeType: 'direct' | 'fanout';
|
|
43
48
|
queueType?: 'classic' | 'quorum' | 'stream';
|
|
49
|
+
dlqTTLms?: number | null;
|
|
44
50
|
};
|
|
45
51
|
export {};
|
|
@@ -164,6 +164,10 @@ class AmqpQueue {
|
|
|
164
164
|
await new Promise(resolve => setTimeout(resolve, timeoutMs));
|
|
165
165
|
return new infra_error_1.default('Timeout with rabbitMQ server!');
|
|
166
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
*
|
|
169
|
+
* @deprecated Use createQueues() instead.
|
|
170
|
+
*/
|
|
167
171
|
async createConsumers(queueName, configs) {
|
|
168
172
|
try {
|
|
169
173
|
const channel = await this.connection.createChannel();
|
|
@@ -188,7 +192,7 @@ class AmqpQueue {
|
|
|
188
192
|
await channel.assertQueue(`${queueName}.DLQ`, {
|
|
189
193
|
durable: true,
|
|
190
194
|
arguments: {
|
|
191
|
-
'x-message-ttl':
|
|
195
|
+
...(configs.dlqTTLms ? { 'x-message-ttl': configs.dlqTTLms } : {}),
|
|
192
196
|
'x-queue-type': configs.queueType || 'classic',
|
|
193
197
|
},
|
|
194
198
|
});
|
|
@@ -202,6 +206,16 @@ class AmqpQueue {
|
|
|
202
206
|
});
|
|
203
207
|
}
|
|
204
208
|
}
|
|
209
|
+
async createQueues(queueName, configs) {
|
|
210
|
+
const buildedConfigs = {
|
|
211
|
+
...configs,
|
|
212
|
+
};
|
|
213
|
+
if (buildedConfigs.dlqTTLms === undefined) {
|
|
214
|
+
const sevenDaysInMs = 604800000;
|
|
215
|
+
buildedConfigs.dlqTTLms = sevenDaysInMs;
|
|
216
|
+
}
|
|
217
|
+
return await this.createConsumers(queueName, configs);
|
|
218
|
+
}
|
|
205
219
|
static async getInstance(vHost = '', socketOptions, uri) {
|
|
206
220
|
if (AmqpQueue.instance && AmqpQueue.instance.vHost === vHost) {
|
|
207
221
|
return AmqpQueue.instance;
|
|
@@ -28,6 +28,28 @@ export declare const headersDefaultWithUserId: z.ZodObject<{
|
|
|
28
28
|
useremail: string;
|
|
29
29
|
userid: string;
|
|
30
30
|
}>;
|
|
31
|
+
export declare const authorizerHeaders: z.ZodUnion<[z.ZodObject<{
|
|
32
|
+
username: z.ZodString;
|
|
33
|
+
useremail: z.ZodString;
|
|
34
|
+
userid: z.ZodString;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
username: string;
|
|
37
|
+
useremail: string;
|
|
38
|
+
userid: string;
|
|
39
|
+
}, {
|
|
40
|
+
username: string;
|
|
41
|
+
useremail: string;
|
|
42
|
+
userid: string;
|
|
43
|
+
}>, z.ZodObject<{
|
|
44
|
+
"app-name": z.ZodString;
|
|
45
|
+
"app-id": z.ZodString;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
"app-id": string;
|
|
48
|
+
"app-name": string;
|
|
49
|
+
}, {
|
|
50
|
+
"app-id": string;
|
|
51
|
+
"app-name": string;
|
|
52
|
+
}>]>;
|
|
31
53
|
export declare const headersDefaultWithFiscalIds: z.ZodObject<{
|
|
32
54
|
tenantid: z.ZodString;
|
|
33
55
|
username: z.ZodString;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.headersDefaultWithFiscalIds = exports.headersDefaultWithUserId = exports.headersDefault = void 0;
|
|
3
|
+
exports.headersDefaultWithFiscalIds = exports.authorizerHeaders = exports.headersDefaultWithUserId = exports.headersDefault = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
exports.headersDefault = zod_1.z.object({
|
|
6
6
|
tenantid: zod_1.z.string().uuid(),
|
|
@@ -13,6 +13,16 @@ exports.headersDefaultWithUserId = zod_1.z.object({
|
|
|
13
13
|
useremail: zod_1.z.string(),
|
|
14
14
|
userid: zod_1.z.string().uuid(),
|
|
15
15
|
});
|
|
16
|
+
const userSchema = zod_1.z.object({
|
|
17
|
+
username: zod_1.z.string(),
|
|
18
|
+
useremail: zod_1.z.string().email(),
|
|
19
|
+
userid: zod_1.z.string().uuid(),
|
|
20
|
+
});
|
|
21
|
+
const appSchema = zod_1.z.object({
|
|
22
|
+
['app-name']: zod_1.z.string(),
|
|
23
|
+
['app-id']: zod_1.z.string().uuid(),
|
|
24
|
+
});
|
|
25
|
+
exports.authorizerHeaders = zod_1.z.union([userSchema, appSchema]);
|
|
16
26
|
exports.headersDefaultWithFiscalIds = zod_1.z.object({
|
|
17
27
|
tenantid: zod_1.z.string().uuid(),
|
|
18
28
|
username: zod_1.z.string(),
|