@seidor-cloud-produtos/orbit-backend-lib 2.0.18 → 2.0.20
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 -0
- package/dist/clean-arch/application/cache/cache.js +14 -3
- package/dist/clean-arch/domain/entities/value-objects/cnpj.d.ts +17 -0
- package/dist/clean-arch/domain/entities/value-objects/cnpj.js +61 -0
- package/dist/clean-arch/domain/entities/value-objects/cnpj.spec.d.ts +1 -0
- package/dist/clean-arch/domain/entities/value-objects/cnpj.spec.js +57 -0
- package/dist/clean-arch/domain/errors/invalid-cnpj-error.d.ts +4 -0
- package/dist/clean-arch/domain/errors/invalid-cnpj-error.js +11 -0
- package/dist/clean-arch/infra/cache/clients/redis.d.ts +3 -0
- package/dist/clean-arch/infra/cache/clients/redis.js +1 -1
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.d.ts +3 -1
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.js +8 -2
- package/dist/clean-arch/infra/scaledjob/runner.d.ts +1 -3
- package/dist/clean-arch/infra/scaledjob/runner.js +44 -25
- package/dist/clean-arch/infra/scaledjob/runner.spec.js +6 -12
- package/dist/clean-arch/infra/scaledjob/types.d.ts +1 -0
- package/dist/infra/authorizations/validator/auth-validator.js +4 -1
- package/package.json +3 -2
|
@@ -25,4 +25,5 @@ export declare abstract class Cache {
|
|
|
25
25
|
isRunning(options?: MethodOptions, isContingency?: boolean): Promise<boolean>;
|
|
26
26
|
close(options?: MethodOptions): Promise<void>;
|
|
27
27
|
protected handleException(e: Error): Promise<void>;
|
|
28
|
+
getOrFetchAndCache<T>(keyCache: string, expiration: number | undefined, promise: () => Promise<T>, options?: MethodOptions): Promise<T | undefined>;
|
|
28
29
|
}
|
|
@@ -18,8 +18,8 @@ class Cache {
|
|
|
18
18
|
}
|
|
19
19
|
setElegibleClients(contingencyClients) {
|
|
20
20
|
this.elegibleClients = [
|
|
21
|
-
this.client,
|
|
22
21
|
...(contingencyClients || []),
|
|
22
|
+
this.client,
|
|
23
23
|
];
|
|
24
24
|
}
|
|
25
25
|
setOptions(options) {
|
|
@@ -39,9 +39,12 @@ class Cache {
|
|
|
39
39
|
await currentClient.start();
|
|
40
40
|
isRunning = await currentClient.isRunning();
|
|
41
41
|
}
|
|
42
|
-
catch
|
|
42
|
+
catch { }
|
|
43
43
|
if (isRunning) {
|
|
44
|
-
|
|
44
|
+
try {
|
|
45
|
+
await this.client.close();
|
|
46
|
+
}
|
|
47
|
+
catch { }
|
|
45
48
|
this.client = currentClient;
|
|
46
49
|
break;
|
|
47
50
|
}
|
|
@@ -164,5 +167,13 @@ class Cache {
|
|
|
164
167
|
catch { }
|
|
165
168
|
throw e;
|
|
166
169
|
}
|
|
170
|
+
async getOrFetchAndCache(keyCache, expiration = this.DEFAULT_EXPIRATION_SECONDS, promise, options) {
|
|
171
|
+
let data = await this.get(keyCache, options);
|
|
172
|
+
if (!data) {
|
|
173
|
+
data = await promise();
|
|
174
|
+
this.set(keyCache, data, expiration, options);
|
|
175
|
+
}
|
|
176
|
+
return data;
|
|
177
|
+
}
|
|
167
178
|
}
|
|
168
179
|
exports.Cache = Cache;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default class Cnpj {
|
|
2
|
+
readonly value: string;
|
|
3
|
+
private constructor();
|
|
4
|
+
static create(cnpj: string): Cnpj;
|
|
5
|
+
static createCorrectly(cnpj: string): Cnpj;
|
|
6
|
+
private static tamanhoCNPJSemDV;
|
|
7
|
+
private static regexCNPJSemDV;
|
|
8
|
+
private static regexCNPJ;
|
|
9
|
+
private static regexMascara;
|
|
10
|
+
private static regexNaoPermitidos;
|
|
11
|
+
private static valorBase;
|
|
12
|
+
private static pesosDV;
|
|
13
|
+
private static cnpjZerado;
|
|
14
|
+
private static clear;
|
|
15
|
+
static isValid(input: string): boolean;
|
|
16
|
+
private static calculaDV;
|
|
17
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/* eslint-disable no-useless-escape */
|
|
5
|
+
const invalid_cnpj_error_1 = tslib_1.__importDefault(require("../../../domain/errors/invalid-cnpj-error"));
|
|
6
|
+
class Cnpj {
|
|
7
|
+
value;
|
|
8
|
+
constructor(cnpj) {
|
|
9
|
+
this.value = cnpj;
|
|
10
|
+
}
|
|
11
|
+
static create(cnpj) {
|
|
12
|
+
if (!this.isValid(cnpj)) {
|
|
13
|
+
throw new invalid_cnpj_error_1.default(cnpj);
|
|
14
|
+
}
|
|
15
|
+
return new Cnpj(this.clear(cnpj));
|
|
16
|
+
}
|
|
17
|
+
static createCorrectly(cnpj) {
|
|
18
|
+
return new Cnpj(this.clear(cnpj));
|
|
19
|
+
}
|
|
20
|
+
static tamanhoCNPJSemDV = 12;
|
|
21
|
+
static regexCNPJSemDV = /^[A-Z0-9]{12}$/;
|
|
22
|
+
static regexCNPJ = /^[A-Z0-9]{12}\d{2}$/;
|
|
23
|
+
static regexMascara = /[.\/-]/g;
|
|
24
|
+
static regexNaoPermitidos = /[^A-Z0-9.\/-]/i;
|
|
25
|
+
static valorBase = '0'.charCodeAt(0);
|
|
26
|
+
static pesosDV = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
27
|
+
static cnpjZerado = '0'.repeat(14);
|
|
28
|
+
static clear(input) {
|
|
29
|
+
return input.replace(this.regexMascara, '').toUpperCase();
|
|
30
|
+
}
|
|
31
|
+
static isValid(input) {
|
|
32
|
+
if (this.regexNaoPermitidos.test(input))
|
|
33
|
+
return false;
|
|
34
|
+
const raw = this.clear(input);
|
|
35
|
+
if (raw.length !== 14 || raw === this.cnpjZerado)
|
|
36
|
+
return false;
|
|
37
|
+
if (!this.regexCNPJ.test(raw))
|
|
38
|
+
return false;
|
|
39
|
+
const base = raw.substring(0, this.tamanhoCNPJSemDV);
|
|
40
|
+
const dvInformado = raw.substring(this.tamanhoCNPJSemDV);
|
|
41
|
+
const dvCalculado = this.calculaDV(base);
|
|
42
|
+
return dvInformado === dvCalculado;
|
|
43
|
+
}
|
|
44
|
+
static calculaDV(base) {
|
|
45
|
+
if (!this.regexCNPJSemDV.test(base)) {
|
|
46
|
+
throw new Error('Base do CNPJ inválida para cálculo de DV');
|
|
47
|
+
}
|
|
48
|
+
let soma1 = 0;
|
|
49
|
+
let soma2 = 0;
|
|
50
|
+
for (let i = 0; i < this.tamanhoCNPJSemDV; i++) {
|
|
51
|
+
const valor = base.charCodeAt(i) - this.valorBase;
|
|
52
|
+
soma1 += valor * this.pesosDV[i + 1];
|
|
53
|
+
soma2 += valor * this.pesosDV[i];
|
|
54
|
+
}
|
|
55
|
+
const dv1 = soma1 % 11 < 2 ? 0 : 11 - (soma1 % 11);
|
|
56
|
+
soma2 += dv1 * this.pesosDV[this.tamanhoCNPJSemDV];
|
|
57
|
+
const dv2 = soma2 % 11 < 2 ? 0 : 11 - (soma2 % 11);
|
|
58
|
+
return `${dv1}${dv2}`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.default = Cnpj;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const invalid_cnpj_error_1 = tslib_1.__importDefault(require("../../errors/invalid-cnpj-error"));
|
|
5
|
+
const cnpj_1 = tslib_1.__importDefault(require("./cnpj"));
|
|
6
|
+
describe('Value Object - Cnpj', () => {
|
|
7
|
+
it('should be able to crete a new cnpj (numeric)', () => {
|
|
8
|
+
const cnpj = cnpj_1.default.create('46230439000101');
|
|
9
|
+
expect(cnpj.value).toBe('46230439000101');
|
|
10
|
+
});
|
|
11
|
+
it('should be able to return error when cnpj is wrong', () => {
|
|
12
|
+
expect(() => cnpj_1.default.create('12344556')).toThrow(invalid_cnpj_error_1.default);
|
|
13
|
+
});
|
|
14
|
+
it('should be able to return error when cnpj only has one number', () => {
|
|
15
|
+
expect(() => cnpj_1.default.create('11111111111111')).toThrow(invalid_cnpj_error_1.default);
|
|
16
|
+
});
|
|
17
|
+
it('should be able to return error when digit 0 is diff', () => {
|
|
18
|
+
expect(() => cnpj_1.default.create('46230439000111')).toThrow(invalid_cnpj_error_1.default);
|
|
19
|
+
});
|
|
20
|
+
it('should be able to create correctly without validation', () => {
|
|
21
|
+
const cnpj = cnpj_1.default.createCorrectly('46230439000101');
|
|
22
|
+
expect(cnpj.value).toBe('46230439000101');
|
|
23
|
+
});
|
|
24
|
+
// --- cenários alfanuméricos existentes ---
|
|
25
|
+
it('should be able to create a valid alphanumeric cnpj (plain)', () => {
|
|
26
|
+
const raw = '12ABC34501DE35';
|
|
27
|
+
const cnpj = cnpj_1.default.create(raw);
|
|
28
|
+
expect(cnpj.value).toBe(raw);
|
|
29
|
+
});
|
|
30
|
+
it('should be able to create a valid alphanumeric cnpj (formatted)', () => {
|
|
31
|
+
const formatted = '12.ABC.345/01DE-35';
|
|
32
|
+
const cnpj = cnpj_1.default.create(formatted);
|
|
33
|
+
expect(cnpj.value).toBe('12ABC34501DE35');
|
|
34
|
+
});
|
|
35
|
+
it('should throw for alphanumeric cnpj with wrong check digit', () => {
|
|
36
|
+
expect(() => cnpj_1.default.create('12ABC34501DE36')).toThrow(invalid_cnpj_error_1.default);
|
|
37
|
+
});
|
|
38
|
+
it('should throw for alphanumeric cnpj with invalid character', () => {
|
|
39
|
+
expect(() => cnpj_1.default.create('12AB@34501DE35')).toThrow(invalid_cnpj_error_1.default);
|
|
40
|
+
});
|
|
41
|
+
it('should throw for alphanumeric cnpj too short', () => {
|
|
42
|
+
expect(() => cnpj_1.default.create('12ABC34501D')).toThrow(invalid_cnpj_error_1.default);
|
|
43
|
+
});
|
|
44
|
+
it('should throw for cnpj all zeros', () => {
|
|
45
|
+
expect(() => cnpj_1.default.create('00000000000000')).toThrow(invalid_cnpj_error_1.default);
|
|
46
|
+
});
|
|
47
|
+
it('should accept lowercase alphanumeric cnpj and normalize to uppercase', () => {
|
|
48
|
+
const lower = '12abc34501de35';
|
|
49
|
+
const cnpj = cnpj_1.default.create(lower);
|
|
50
|
+
expect(cnpj.value).toBe('12ABC34501DE35');
|
|
51
|
+
});
|
|
52
|
+
it('createCorrectly should remove mask from formatted alphanumeric cnpj without validating', () => {
|
|
53
|
+
const formatted = '12.ABC.345/01DE-XX'; // invalid DV/characters but mask is removed
|
|
54
|
+
const cnpj = cnpj_1.default.createCorrectly(formatted);
|
|
55
|
+
expect(cnpj.value).toBe('12ABC34501DEXX');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const domain_error_1 = tslib_1.__importDefault(require("./domain-error"));
|
|
5
|
+
class InvalidCnpjError extends domain_error_1.default {
|
|
6
|
+
constructor(cnpj) {
|
|
7
|
+
super(`The cnpj "${cnpj}" is invalid.`, 400);
|
|
8
|
+
this.name = 'InvalidCnpjError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.default = InvalidCnpjError;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { RedisOptions as LibRedisOptions } from 'ioredis';
|
|
2
2
|
import { CacheClient, CacheClientOptions } from '../../../application/cache/client';
|
|
3
|
+
export type ListenersType = {
|
|
4
|
+
error?: (error: Error) => void;
|
|
5
|
+
} | undefined;
|
|
3
6
|
export interface RedisOptions extends LibRedisOptions, CacheClientOptions {
|
|
4
7
|
}
|
|
5
8
|
export declare class Redis extends CacheClient {
|
|
@@ -12,7 +12,9 @@ export default class AmqpQueue implements QueueConnection {
|
|
|
12
12
|
private messagesInMemory;
|
|
13
13
|
private controller;
|
|
14
14
|
private channels;
|
|
15
|
-
|
|
15
|
+
protected socketOptions?: any;
|
|
16
|
+
constructor(uri?: string, socketOptions?: any);
|
|
17
|
+
private setSocketOptions;
|
|
16
18
|
connect(vHost: string): Promise<AmqpQueue>;
|
|
17
19
|
close(): Promise<void>;
|
|
18
20
|
get(queueName: string, options?: amqp.Options.Get | undefined): Promise<AmqpQueueGetResult | null>;
|
|
@@ -10,12 +10,18 @@ class AmqpQueue {
|
|
|
10
10
|
messagesInMemory = [];
|
|
11
11
|
controller;
|
|
12
12
|
channels = new Map();
|
|
13
|
-
|
|
13
|
+
socketOptions;
|
|
14
|
+
constructor(uri = process.env.BROKER_AMQP, socketOptions) {
|
|
14
15
|
this.uri = uri;
|
|
16
|
+
this.setSocketOptions(socketOptions);
|
|
17
|
+
}
|
|
18
|
+
setSocketOptions(socketOptions) {
|
|
19
|
+
this.socketOptions = socketOptions;
|
|
20
|
+
return this;
|
|
15
21
|
}
|
|
16
22
|
async connect(vHost) {
|
|
17
23
|
const urlConnection = `${this.uri}${vHost === '/' ? '/' : `/${vHost}`}`;
|
|
18
|
-
this.connection = await amqplib_1.default.connect(urlConnection);
|
|
24
|
+
this.connection = await amqplib_1.default.connect(urlConnection, this.socketOptions);
|
|
19
25
|
this.vHost = vHost;
|
|
20
26
|
await this.treatReconnection(vHost);
|
|
21
27
|
if (process.env.NODE_ENV !== 'test') {
|
|
@@ -2,15 +2,13 @@ import Handler from '../../../clean-arch/application/queue/handler';
|
|
|
2
2
|
import AmqpQueue from '../queue/rabbitmq/amqp-lib';
|
|
3
3
|
import { AmqpQueueGetResult } from '../queue/rabbitmq/types';
|
|
4
4
|
import { RabbitMQScaledJobOptions } from './types';
|
|
5
|
-
import LoggerGateway from 'lib/clean-arch/application/logger';
|
|
6
5
|
export declare class RabbitMQScaledJobRunner<T = any> {
|
|
7
6
|
private readonly amqpQueue;
|
|
8
7
|
private readonly queueName;
|
|
9
8
|
private readonly vHost;
|
|
10
9
|
private readonly handler;
|
|
11
10
|
private readonly options;
|
|
12
|
-
|
|
13
|
-
constructor(amqpQueue: AmqpQueue, queueName: string, vHost: string, handler: Handler, options: RabbitMQScaledJobOptions, logger: LoggerGateway);
|
|
11
|
+
constructor(amqpQueue: AmqpQueue, queueName: string, vHost: string, handler: Handler, options: RabbitMQScaledJobOptions);
|
|
14
12
|
private handleError;
|
|
15
13
|
protected errorStrategy(getResult: AmqpQueueGetResult): Promise<void>;
|
|
16
14
|
private rejectTimeout;
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RabbitMQScaledJobRunner = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const logger_in_memory_1 = tslib_1.__importDefault(require("../logger/logger-in-memory"));
|
|
4
6
|
class RabbitMQScaledJobRunner {
|
|
5
7
|
amqpQueue;
|
|
6
8
|
queueName;
|
|
7
9
|
vHost;
|
|
8
10
|
handler;
|
|
9
11
|
options;
|
|
10
|
-
|
|
11
|
-
constructor(amqpQueue, queueName, vHost, handler, options, logger) {
|
|
12
|
+
constructor(amqpQueue, queueName, vHost, handler, options) {
|
|
12
13
|
this.amqpQueue = amqpQueue;
|
|
13
14
|
this.queueName = queueName;
|
|
14
15
|
this.vHost = vHost;
|
|
15
16
|
this.handler = handler;
|
|
16
17
|
this.options = options;
|
|
17
|
-
this.logger = logger;
|
|
18
18
|
}
|
|
19
19
|
async handleError(error, getResult) {
|
|
20
|
-
this.logger.log(`[RabbitMQScaledJobRunner] Erro: ${error.message}`);
|
|
21
20
|
if (!getResult) {
|
|
22
21
|
return;
|
|
23
22
|
}
|
|
@@ -32,46 +31,66 @@ class RabbitMQScaledJobRunner {
|
|
|
32
31
|
return await this.amqpQueue.nack(channel, rawMessage, false);
|
|
33
32
|
}
|
|
34
33
|
catch {
|
|
35
|
-
|
|
34
|
+
logger_in_memory_1.default.log('[RabbitMQScaledJobRunner] Falha ao aplicar estratégia de erro');
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
rejectTimeout() {
|
|
39
38
|
return new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout')), this.options.timeoutMs));
|
|
40
39
|
}
|
|
41
40
|
async finishProcess() {
|
|
42
|
-
|
|
41
|
+
logger_in_memory_1.default.debug()?.log('[RabbitMQScaledJobRunner] Finished process');
|
|
43
42
|
}
|
|
44
43
|
async run() {
|
|
45
44
|
let getResult = null;
|
|
45
|
+
let consumedMessages = 0;
|
|
46
|
+
const messagesToGet = this.options.numberOfMessagesToGet ?? 1;
|
|
46
47
|
try {
|
|
47
48
|
await this.amqpQueue.connect(this.vHost);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
while (consumedMessages < messagesToGet) {
|
|
50
|
+
try {
|
|
51
|
+
getResult = await this.amqpQueue.get(this.queueName, {
|
|
52
|
+
noAck: !this.options.manualAck,
|
|
53
|
+
});
|
|
54
|
+
if (!getResult) {
|
|
55
|
+
logger_in_memory_1.default.log('[RabbitMQScaledJobRunner] Nenhuma mensagem disponível.');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const { channel, rawMessage } = getResult;
|
|
59
|
+
const msg = this.options.parse(rawMessage);
|
|
60
|
+
logger_in_memory_1.default
|
|
61
|
+
.debug()
|
|
62
|
+
?.log(`[RabbitMQScaledJobRunner] Mensagem recebida ${JSON.stringify(msg, null, 2)}`);
|
|
63
|
+
await Promise.race([this.handler.handle(msg), this.rejectTimeout()]);
|
|
64
|
+
if (this.options.manualAck) {
|
|
65
|
+
await this.amqpQueue.ack(channel, rawMessage);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
logger_in_memory_1.default.log(`[RabbitMQScaledJobRunner] Erro: ${error.message}`);
|
|
70
|
+
if (getResult && this.options.manualAck) {
|
|
71
|
+
await this.handleError(error, getResult);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
if (getResult) {
|
|
76
|
+
getResult = null;
|
|
77
|
+
consumedMessages += 1;
|
|
78
|
+
logger_in_memory_1.default
|
|
79
|
+
.debug()
|
|
80
|
+
?.log(`[RabbitMQScaledJobRunner] Mensagens consumidas: ${consumedMessages}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
61
83
|
}
|
|
62
84
|
}
|
|
63
|
-
catch (
|
|
64
|
-
|
|
65
|
-
if (getResult && this.options.manualAck) {
|
|
66
|
-
await this.handleError(err, getResult);
|
|
67
|
-
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
logger_in_memory_1.default.log(`[RabbitMQScaledJobRunner] Erro: ${JSON.stringify(error)}`);
|
|
68
87
|
}
|
|
69
88
|
finally {
|
|
70
89
|
try {
|
|
71
90
|
await this.amqpQueue.close();
|
|
72
91
|
}
|
|
73
92
|
catch {
|
|
74
|
-
|
|
93
|
+
logger_in_memory_1.default.log('[RabbitMQScaledJobRunner] Erro ao fechar conexão');
|
|
75
94
|
await this.finishProcess();
|
|
76
95
|
}
|
|
77
96
|
}
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
4
|
const runner_1 = require("./runner");
|
|
5
|
-
const logger_in_memory_1 = require("../logger/logger-in-memory");
|
|
6
5
|
(0, vitest_1.describe)('RabbitMQScaledJobRunner', () => {
|
|
7
6
|
let amqpQueue;
|
|
8
7
|
let handler;
|
|
9
8
|
let options;
|
|
10
|
-
let
|
|
9
|
+
let onFinally;
|
|
11
10
|
let runner;
|
|
12
11
|
(0, vitest_1.beforeEach)(() => {
|
|
13
12
|
amqpQueue = {
|
|
@@ -24,7 +23,8 @@ const logger_in_memory_1 = require("../logger/logger-in-memory");
|
|
|
24
23
|
errorStrategy: 'nack-dlq',
|
|
25
24
|
parse: vitest_1.vi.fn((raw) => ({ ok: true, msg: 'parsed' })),
|
|
26
25
|
};
|
|
27
|
-
|
|
26
|
+
onFinally = vitest_1.vi.fn();
|
|
27
|
+
runner = new runner_1.RabbitMQScaledJobRunner(amqpQueue, 'queue', 'vhost', handler, options);
|
|
28
28
|
});
|
|
29
29
|
(0, vitest_1.it)('should connect, get, handle, ack and close (happy path)', async () => {
|
|
30
30
|
const rawMessage = { content: Buffer.from('msg') };
|
|
@@ -51,9 +51,7 @@ const logger_in_memory_1 = require("../logger/logger-in-memory");
|
|
|
51
51
|
const rawMessage = { content: Buffer.from('msg') };
|
|
52
52
|
const channel = {};
|
|
53
53
|
amqpQueue.get.mockResolvedValue({ channel, rawMessage });
|
|
54
|
-
handler.handle = vitest_1.vi.fn(() => {
|
|
55
|
-
throw new Error('fail');
|
|
56
|
-
});
|
|
54
|
+
handler.handle = vitest_1.vi.fn(() => { throw new Error('fail'); });
|
|
57
55
|
await runner.run();
|
|
58
56
|
(0, vitest_1.expect)(amqpQueue.nack).toHaveBeenCalledWith(channel, rawMessage, true);
|
|
59
57
|
});
|
|
@@ -62,9 +60,7 @@ const logger_in_memory_1 = require("../logger/logger-in-memory");
|
|
|
62
60
|
const rawMessage = { content: Buffer.from('msg') };
|
|
63
61
|
const channel = {};
|
|
64
62
|
amqpQueue.get.mockResolvedValue({ channel, rawMessage });
|
|
65
|
-
handler.handle = vitest_1.vi.fn(() => {
|
|
66
|
-
throw new Error('fail');
|
|
67
|
-
});
|
|
63
|
+
handler.handle = vitest_1.vi.fn(() => { throw new Error('fail'); });
|
|
68
64
|
await runner.run();
|
|
69
65
|
(0, vitest_1.expect)(amqpQueue.nack).toHaveBeenCalledWith(channel, rawMessage, false);
|
|
70
66
|
});
|
|
@@ -110,9 +106,7 @@ const logger_in_memory_1 = require("../logger/logger-in-memory");
|
|
|
110
106
|
const rawMessage = { content: Buffer.from('msg') };
|
|
111
107
|
const channel = {};
|
|
112
108
|
amqpQueue.get.mockResolvedValue({ channel, rawMessage });
|
|
113
|
-
handler.handle = vitest_1.vi.fn(() => {
|
|
114
|
-
throw new Error('fail');
|
|
115
|
-
});
|
|
109
|
+
handler.handle = vitest_1.vi.fn(() => { throw new Error('fail'); });
|
|
116
110
|
await runner.run();
|
|
117
111
|
(0, vitest_1.expect)(amqpQueue.nack).toHaveBeenCalledWith(channel, rawMessage, false);
|
|
118
112
|
});
|
|
@@ -16,8 +16,11 @@ class AuthValidator {
|
|
|
16
16
|
isAuthorized() {
|
|
17
17
|
const notReceiptAuthorizations = this.requestData.authorizations === undefined ||
|
|
18
18
|
this.requestData.authorizations === null;
|
|
19
|
+
if (notReceiptAuthorizations) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
19
22
|
const hasAuthorizations = auth_matcher_1.default.isMatch(this.query, this.requestData.authorizations);
|
|
20
|
-
return
|
|
23
|
+
return hasAuthorizations;
|
|
21
24
|
}
|
|
22
25
|
async setup() {
|
|
23
26
|
this.requestData = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seidor-cloud-produtos/orbit-backend-lib",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.20",
|
|
4
4
|
"description": "Internal lib for backend components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"@types/compression": "1.7.5",
|
|
52
52
|
"@types/cors": "2.8.17",
|
|
53
53
|
"@types/express": "4.17.21",
|
|
54
|
+
"@types/jest": "30.0.0",
|
|
54
55
|
"@types/supertest": "6.0.2",
|
|
55
56
|
"@typescript-eslint/eslint-plugin": "5.59.9",
|
|
56
57
|
"@typescript-eslint/parser": "5.59.9",
|
|
@@ -79,7 +80,7 @@
|
|
|
79
80
|
"dependencies": {
|
|
80
81
|
"@fastify/cors": "8.3.0",
|
|
81
82
|
"@nestjs/common": "8.4.7",
|
|
82
|
-
"amqplib": "0.10.
|
|
83
|
+
"amqplib": "0.10.9",
|
|
83
84
|
"axios": "1.8.2",
|
|
84
85
|
"compression": "1.7.4",
|
|
85
86
|
"discord.js": "14.16.3",
|