diff --git a/platforms/dreamsync-api/src/services/ConsentService.ts b/platforms/dreamsync-api/src/services/ConsentService.ts index 25ed1cfc2..00066f35a 100644 --- a/platforms/dreamsync-api/src/services/ConsentService.ts +++ b/platforms/dreamsync-api/src/services/ConsentService.ts @@ -5,6 +5,7 @@ import { Group } from "../database/entities/Group"; import { Message } from "../database/entities/Message"; import { UserService } from "./UserService"; import { GroupService } from "./GroupService"; +import { withOperationContext } from "../context/OperationContext"; export class ConsentService { private userService: UserService; @@ -20,7 +21,11 @@ export class ConsentService { * Process a consent response to a match notification (by Match ID) */ async processConsentResponse(messageText: string, senderId: string, groupId: string): Promise { - try { + // Generate unique operation ID for this consent processing + const operationId = `consent-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`; + + return withOperationContext('ConsentService', operationId, async () => { + try { // Check if the message text itself is a UUID (Match ID) const uuidRegex = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i; const isDirectMatchId = uuidRegex.test(messageText.trim()); @@ -150,9 +155,10 @@ export class ConsentService { } } - } catch (error) { - console.error("Error processing consent response:", error); - } + } catch (error) { + console.error("Error processing consent response:", error); + } + }); } /** diff --git a/platforms/dreamsync-api/src/web3adapter/watchers/subscriber.ts b/platforms/dreamsync-api/src/web3adapter/watchers/subscriber.ts index 7568346a9..d8a9d5484 100644 --- a/platforms/dreamsync-api/src/web3adapter/watchers/subscriber.ts +++ b/platforms/dreamsync-api/src/web3adapter/watchers/subscriber.ts @@ -10,6 +10,7 @@ import { Web3Adapter } from "web3-adapter"; import path from "path"; import dotenv from "dotenv"; import { AppDataSource } from "../../database/data-source"; +import { shouldProcessWebhook } from "../../context/OperationContext"; dotenv.config({ path: path.resolve(__dirname, "../../../../../.env") }); export const adapter = new Web3Adapter({ @@ -253,6 +254,12 @@ export class PostgresSubscriber implements EntitySubscriberInterface { private async handleChange(entity: any, tableName: string): Promise { console.log(`🔍 handleChange called for: ${tableName}, entityId: ${entity?.id}`); + // Check if this operation should be processed (only ConsentService operations for groups/messages) + if (!shouldProcessWebhook(entity?.id, tableName)) { + console.log(`⏭️ Skipping webhook for ${tableName}:${entity?.id} - not from ConsentService (protected entity)`); + return; + } + // Handle junction table changes - DON'T IGNORE group_participants! // @ts-ignore const junctionInfo = JUNCTION_TABLE_MAP[tableName]; @@ -344,6 +351,12 @@ export class PostgresSubscriber implements EntitySubscriberInterface { return; } + // Check if this junction table change should be processed (only ConsentService operations for groups) + if (!shouldProcessWebhook(parentId, junctionInfo.entity)) { + console.log(`⏭️ Skipping junction table webhook for ${junctionInfo.entity}:${parentId} - not from ConsentService (protected entity)`); + return; + } + const repository = AppDataSource.getRepository(junctionInfo.entity); const parentEntity = await repository.findOne({ where: { id: parentId }, @@ -408,6 +421,12 @@ export class PostgresSubscriber implements EntitySubscriberInterface { */ private async sendGroupWebhook(data: any): Promise { try { + // Check if this group webhook should be processed (only ConsentService operations for groups) + if (!shouldProcessWebhook(data.id, "groups")) { + console.log(`⏭️ Skipping group webhook for ${data.id} - not from ConsentService (protected entity)`); + return; + } + // Skip groups with Match ID in description (already processed) if (data.description && typeof data.description === 'string' && data.description.startsWith('Match ID:')) { console.log(`🔍 Skipping group webhook - has Match ID in description: ${data.description}`);