mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-12 11:29:38 -06:00
fix(events): guard extra spread and prevent core field override
- Use (extra ?? {}) to handle undefined extra safely
- Spread extra first to prevent overriding core fields like event, instance, data
- Applied fix to all 7 event controllers
Addresses Sourcery AI review feedback.
This commit is contained in:
parent
fa6b5c28a6
commit
930d32df3a
@ -285,6 +285,7 @@ export class KafkaController extends EventController implements EventControllerI
|
|||||||
const logEnabled = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
|
const logEnabled = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
|
||||||
|
|
||||||
const message = {
|
const message = {
|
||||||
|
...(extra ?? {}),
|
||||||
event,
|
event,
|
||||||
instance: instanceName,
|
instance: instanceName,
|
||||||
data,
|
data,
|
||||||
@ -293,7 +294,6 @@ export class KafkaController extends EventController implements EventControllerI
|
|||||||
sender,
|
sender,
|
||||||
apikey: apiKey,
|
apikey: apiKey,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
...extra,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const messageValue = JSON.stringify(message);
|
const messageValue = JSON.stringify(message);
|
||||||
|
|||||||
@ -66,6 +66,7 @@ export class NatsController extends EventController implements EventControllerIn
|
|||||||
const logEnabled = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
|
const logEnabled = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
|
||||||
|
|
||||||
const message = {
|
const message = {
|
||||||
|
...(extra ?? {}),
|
||||||
event,
|
event,
|
||||||
instance: instanceName,
|
instance: instanceName,
|
||||||
data,
|
data,
|
||||||
@ -73,7 +74,6 @@ export class NatsController extends EventController implements EventControllerIn
|
|||||||
date_time: dateTime,
|
date_time: dateTime,
|
||||||
sender,
|
sender,
|
||||||
apikey: apiKey,
|
apikey: apiKey,
|
||||||
...extra,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Instância específica
|
// Instância específica
|
||||||
|
|||||||
@ -134,6 +134,7 @@ export class PusherController extends EventController implements EventController
|
|||||||
const enabledLog = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
|
const enabledLog = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
|
||||||
const eventName = event.replace(/_/g, '.').toLowerCase();
|
const eventName = event.replace(/_/g, '.').toLowerCase();
|
||||||
const pusherData = {
|
const pusherData = {
|
||||||
|
...(extra ?? {}),
|
||||||
event,
|
event,
|
||||||
instance: instanceName,
|
instance: instanceName,
|
||||||
data,
|
data,
|
||||||
@ -142,7 +143,6 @@ export class PusherController extends EventController implements EventController
|
|||||||
sender,
|
sender,
|
||||||
server_url: serverUrl,
|
server_url: serverUrl,
|
||||||
apikey: apiKey,
|
apikey: apiKey,
|
||||||
...extra,
|
|
||||||
};
|
};
|
||||||
if (event == 'qrcode.updated') {
|
if (event == 'qrcode.updated') {
|
||||||
delete pusherData.data.qrcode.base64;
|
delete pusherData.data.qrcode.base64;
|
||||||
|
|||||||
@ -234,6 +234,7 @@ export class RabbitmqController extends EventController implements EventControll
|
|||||||
const logEnabled = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
|
const logEnabled = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
|
||||||
|
|
||||||
const message = {
|
const message = {
|
||||||
|
...(extra ?? {}),
|
||||||
event,
|
event,
|
||||||
instance: instanceName,
|
instance: instanceName,
|
||||||
data,
|
data,
|
||||||
@ -241,7 +242,6 @@ export class RabbitmqController extends EventController implements EventControll
|
|||||||
date_time: dateTime,
|
date_time: dateTime,
|
||||||
sender,
|
sender,
|
||||||
apikey: apiKey,
|
apikey: apiKey,
|
||||||
...extra,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (instanceRabbitmq?.enabled && this.amqpChannel) {
|
if (instanceRabbitmq?.enabled && this.amqpChannel) {
|
||||||
|
|||||||
@ -129,6 +129,7 @@ export class SqsController extends EventController implements EventControllerInt
|
|||||||
const sqsUrl = `https://sqs.${sqsConfig.REGION}.amazonaws.com/${sqsConfig.ACCOUNT_ID}/${queueName}`;
|
const sqsUrl = `https://sqs.${sqsConfig.REGION}.amazonaws.com/${sqsConfig.ACCOUNT_ID}/${queueName}`;
|
||||||
|
|
||||||
const message = {
|
const message = {
|
||||||
|
...(extra ?? {}),
|
||||||
event,
|
event,
|
||||||
instance: instanceName,
|
instance: instanceName,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
@ -138,7 +139,6 @@ export class SqsController extends EventController implements EventControllerInt
|
|||||||
date_time: dateTime,
|
date_time: dateTime,
|
||||||
sender,
|
sender,
|
||||||
apikey: apiKey,
|
apikey: apiKey,
|
||||||
...extra,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const jsonStr = JSON.stringify(message);
|
const jsonStr = JSON.stringify(message);
|
||||||
|
|||||||
@ -91,6 +91,7 @@ export class WebhookController extends EventController implements EventControlle
|
|||||||
const regex = /^(https?:\/\/)/;
|
const regex = /^(https?:\/\/)/;
|
||||||
|
|
||||||
const webhookData = {
|
const webhookData = {
|
||||||
|
...(extra ?? {}),
|
||||||
event,
|
event,
|
||||||
instance: instanceName,
|
instance: instanceName,
|
||||||
data,
|
data,
|
||||||
@ -99,7 +100,6 @@ export class WebhookController extends EventController implements EventControlle
|
|||||||
sender,
|
sender,
|
||||||
server_url: serverUrl,
|
server_url: serverUrl,
|
||||||
apikey: apiKey,
|
apikey: apiKey,
|
||||||
...extra,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (local && instance?.enabled) {
|
if (local && instance?.enabled) {
|
||||||
|
|||||||
@ -128,6 +128,7 @@ export class WebsocketController extends EventController implements EventControl
|
|||||||
const configEv = event.replace(/[.-]/gm, '_').toUpperCase();
|
const configEv = event.replace(/[.-]/gm, '_').toUpperCase();
|
||||||
const logEnabled = configService.get<Log>('LOG').LEVEL.includes('WEBSOCKET');
|
const logEnabled = configService.get<Log>('LOG').LEVEL.includes('WEBSOCKET');
|
||||||
const message = {
|
const message = {
|
||||||
|
...(extra ?? {}),
|
||||||
event,
|
event,
|
||||||
instance: instanceName,
|
instance: instanceName,
|
||||||
data,
|
data,
|
||||||
@ -135,7 +136,6 @@ export class WebsocketController extends EventController implements EventControl
|
|||||||
date_time: dateTime,
|
date_time: dateTime,
|
||||||
sender,
|
sender,
|
||||||
apikey: apiKey,
|
apikey: apiKey,
|
||||||
...extra,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (configService.get<Websocket>('WEBSOCKET')?.GLOBAL_EVENTS) {
|
if (configService.get<Websocket>('WEBSOCKET')?.GLOBAL_EVENTS) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user