diff --git a/src/events/CredentialEvents.ts b/src/events/CredentialEvents.ts index 9c94693e..9ebbbcda 100644 --- a/src/events/CredentialEvents.ts +++ b/src/events/CredentialEvents.ts @@ -19,12 +19,33 @@ export const credentialEvents = async (agent: Agent, config: ServerConfig) => { } if (record?.connectionId) { - const connectionRecord = await agent.connections.findById(record.connectionId!) + let connectionRecord + if (event.metadata.contextCorrelationId && event.metadata.contextCorrelationId !== 'default') { + await (agent as Agent).modules.tenants.withTenantAgent( + { tenantId: body.contextCorrelationId as string }, + async (tenantAgent) => { + connectionRecord = await tenantAgent.connections.findById(record.connectionId ? record.connectionId : '') + }, + ) + } else { + connectionRecord = await agent.connections.getById(record.connectionId) + } body.outOfBandId = connectionRecord?.outOfBandId } - const data = await agent.credentials.getFormatData(record.id) - body.credentialData = data + let formatData = null + if (event.metadata.contextCorrelationId && event.metadata.contextCorrelationId !== 'default') { + await (agent as Agent).modules.tenants.withTenantAgent( + { tenantId: body.contextCorrelationId as string }, + async (tenantAgent) => { + formatData = await tenantAgent.credentials.getFormatData(record.id) + }, + ) + } else { + formatData = await agent.credentials.getFormatData(record.id) + } + + body.credentialData = formatData if (config.webhookUrl) { await sendWebhookEvent(config.webhookUrl + '/credentials', body, agent.config.logger)