Skip to content

Commit

Permalink
refactor:add outOfBandId into issuance webhook event (#94)
Browse files Browse the repository at this point in the history
Signed-off-by: tipusinghaw <[email protected]>
  • Loading branch information
pallavighule authored and tipusinghaw committed Apr 30, 2024
1 parent 07de941 commit e4f0df6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/events/CredentialEvents.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { RestMultiTenantAgentModules } from '../cliAgent'
import type { ServerConfig } from '../utils/ServerConfig'
import type { Agent, CredentialStateChangedEvent } from '@credo-ts/core'

Expand All @@ -6,11 +7,26 @@ import { CredentialEventTypes } from '@credo-ts/core'
import { sendWebSocketEvent } from './WebSocketEvents'
import { sendWebhookEvent } from './WebhookEvent'

export const credentialEvents = async (agent: Agent, config: ServerConfig) => {
export const credentialEvents = async (agent: Agent<RestMultiTenantAgentModules>, config: ServerConfig) => {
agent.events.on(CredentialEventTypes.CredentialStateChanged, async (event: CredentialStateChangedEvent) => {
const record = event.payload.credentialRecord
const body = { ...record.toJSON(), ...event.metadata }

const body: Record<string, unknown> = {
...record.toJSON(),
...event.metadata,
outOfBandId: null,
}

if (event.metadata.contextCorrelationId !== 'default' && record?.connectionId) {
await agent.modules.tenants.withTenantAgent(
{ tenantId: event.metadata.contextCorrelationId },
async (tenantAgent) => {
const connectionRecord = await tenantAgent.connections.findById(record.connectionId!)

body.outOfBandId = connectionRecord?.outOfBandId
}
)
}
// Only send webhook if webhook url is configured
if (config.webhookUrl) {
await sendWebhookEvent(config.webhookUrl + '/credentials', body, agent.config.logger)
Expand Down

0 comments on commit e4f0df6

Please sign in to comment.