Skip to content

Commit

Permalink
fix(rest): changed webhook event topic to type (openwallet-foundation…
Browse files Browse the repository at this point in the history
…#117)

Signed-off-by: Jan <60812202+janrtvld@users.noreply.github.com>
  • Loading branch information
janrtvld committed Aug 26, 2022
1 parent 479a64f commit eb5e492
Show file tree
Hide file tree
Showing 7 changed files with 1,409 additions and 147 deletions.
24 changes: 12 additions & 12 deletions packages/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,30 @@
"@aries-framework/node": "^0.1.0",
"class-transformer": "0.5.1",
"class-validator": "0.13.1",
"class-validator-jsonschema": "^3.1.0",
"class-validator-jsonschema": "^3.1.1",
"cors": "^2.8.5",
"express": "^4.17.1",
"express": "^4.18.1",
"node-fetch": "^2.6.7",
"reflect-metadata": "^0.1.13",
"routing-controllers": "^0.9.0",
"routing-controllers-openapi": "^3.1.0",
"swagger-ui-express": "^4.1.6",
"tslog": "^3.2.2",
"tsyringe": "^4.6.0",
"swagger-ui-express": "^4.4.0",
"tslog": "^3.3.3",
"tsyringe": "^4.7.0",
"yargs": "^17.3.1"
},
"devDependencies": {
"@types/express": "^4.17.13",
"@types/jest": "^27.0.3",
"@types/node": "^16.11.10",
"@types/supertest": "^2.0.11",
"@types/node": "^17.0.41",
"@types/supertest": "^2.0.12",
"@types/swagger-ui-express": "^4.1.3",
"@types/uuid": "^8.3.3",
"@types/uuid": "^8.3.4",
"jest": "^27.3.1",
"ngrok": "^4.2.2",
"supertest": "^6.1.6",
"ngrok": "^4.3.1",
"supertest": "^6.2.3",
"ts-jest": "^27.0.7",
"ts-node-dev": "^1.1.8",
"typescript": "^4.5.2"
"ts-node-dev": "^2.0.0",
"typescript": "^4.7.3"
}
}
7 changes: 0 additions & 7 deletions packages/rest/samples/sample.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import type { ServerConfig } from '../src/utils/ServerConfig'

import { AutoAcceptCredential, LogLevel } from '@aries-framework/core'
import { connect } from 'ngrok'

import { startServer } from '../src/index'
import { TsLogger } from '../src/utils/logger'
import { setupAgent } from '../tests/utils/agent'

const run = async () => {
const logger = new TsLogger(LogLevel.debug)
const endpoint = await connect(3001)

const agent = await setupAgent({
port: 3001,
publicDidSeed: 'testtesttesttesttesttesttesttest',
endpoints: [endpoint],
name: 'Aries Test Agent',
logger: logger,
autoAcceptConnection: true,
autoAcceptCredential: AutoAcceptCredential.ContentApproved,
useLegacyDidSovPrefix: true,
})

const conf: ServerConfig = {
Expand Down
7 changes: 0 additions & 7 deletions packages/rest/samples/sampleWithApp.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import type { ServerConfig } from '../src/utils/ServerConfig'
import type { Express } from 'express'

import { AutoAcceptCredential, LogLevel } from '@aries-framework/core'
import { connect } from 'ngrok'
import { createExpressServer } from 'routing-controllers'

import { startServer } from '../src/index'
import { TsLogger } from '../src/utils/logger'
import { setupAgent } from '../tests/utils/agent'

import { GreetingController } from './utils/GreetingController'

const run = async () => {
const logger = new TsLogger(LogLevel.debug)
const endpoint = await connect(3001)

const agent = await setupAgent({
port: 3001,
publicDidSeed: 'testtesttesttesttesttesttesttest',
endpoints: [endpoint],
name: 'Aries Test Agent',
logger: logger,
autoAcceptConnection: true,
autoAcceptCredential: AutoAcceptCredential.ContentApproved,
useLegacyDidSovPrefix: true,
})

const app: Express = createExpressServer({
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/src/events/WebhookEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const sendWebhookEvent = async (webhookUrl: string, body: Record<string,
headers: { 'Content-Type': 'application/json' },
})
} catch (error) {
logger.error(`Error sending ${body.topic} webhook event to ${webhookUrl}`, {
logger.error(`Error sending ${body.type} webhook event to ${webhookUrl}`, {
cause: error,
})
}
Expand Down
84 changes: 44 additions & 40 deletions packages/rest/tests/utils/agent.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
import type { TsLogger } from '../../src/utils/logger'
import type { AutoAcceptCredential, InitConfig } from '@aries-framework/core'

import { Agent, ConnectionInvitationMessage, HttpOutboundTransport } from '@aries-framework/core'
import {
AutoAcceptCredential,
AutoAcceptProof,
Agent,
ConnectionInvitationMessage,
HttpOutboundTransport,
LogLevel,
} from '@aries-framework/core'
import { agentDependencies, HttpInboundTransport } from '@aries-framework/node'
import path from 'path'

import { TsLogger } from '../../src/utils/logger'

export const genesisPath = process.env.GENESIS_TXN_PATH
? path.resolve(process.env.GENESIS_TXN_PATH)
: path.join(__dirname, '../../../../network/genesis/local-genesis.txn')

export async function setupAgent({
port,
export const setupAgent = async ({
name,
publicDidSeed,
endpoints,
name,
logger,
autoAcceptConnection,
autoAcceptCredential,
useLegacyDidSovPrefix,
port,
}: {
port: number
name: string
publicDidSeed: string
endpoints: string[]
name: string
logger: TsLogger
autoAcceptConnection: boolean
autoAcceptCredential: AutoAcceptCredential
useLegacyDidSovPrefix: boolean
}) {
const agentConfig: InitConfig = {
label: name,
walletConfig: {
id: name,
key: name,
},
indyLedgers: [
{
id: 'LocalLedger',
genesisPath,
isProduction: false,
},
],
publicDidSeed: publicDidSeed,
endpoints: endpoints,
autoAcceptConnections: autoAcceptConnection,
autoAcceptCredentials: autoAcceptCredential,
useLegacyDidSovPrefix: useLegacyDidSovPrefix,
logger: logger,
}
port: number
}) => {
const logger = new TsLogger(LogLevel.debug)

const agent = new Agent(agentConfig, agentDependencies)
const agent = new Agent(
{
publicDidSeed,
label: name,
endpoints: endpoints,
autoAcceptConnections: true,
autoAcceptProofs: AutoAcceptProof.ContentApproved,
autoAcceptCredentials: AutoAcceptCredential.ContentApproved,
walletConfig: { id: name, key: name },
useLegacyDidSovPrefix: true,
logger: logger,
indyLedgers: [
{
id: 'LocalLedger',
genesisPath,
isProduction: false,
},
],
},
agentDependencies
)

const httpInbound = new HttpInboundTransport({
port: port,
Expand All @@ -70,7 +69,12 @@ export async function setupAgent({
} else {
const { invitation } = await agent.connections.createConnection()

res.send(invitation.toUrl({ domain: endpoints + '/invitation', useLegacyDidSovPrefix: useLegacyDidSovPrefix }))
res.send(
invitation.toUrl({
domain: endpoints + '/invitation',
useLegacyDidSovPrefix: agent.config.useLegacyDidSovPrefix,
})
)
}
})

Expand Down
10 changes: 0 additions & 10 deletions packages/rest/tests/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
import {
AutoAcceptCredential,
CredentialRecord,
JsonTransformer,
LogLevel,
OfferCredentialMessage,
ProofRecord,
ProofRequest,
} from '@aries-framework/core'
import { JsonEncoder } from '@aries-framework/core/build/utils/JsonEncoder'

import { TsLogger } from '../../src/utils/logger'

import { setupAgent } from './agent'

export async function getTestAgent(name: string, port: number) {
const logger = new TsLogger(LogLevel.fatal)

return await setupAgent({
port: port,
publicDidSeed: 'testtesttesttesttesttesttesttest',
endpoints: [`http://localhost:${port}`],
name: name,
logger: logger,
autoAcceptConnection: true,
autoAcceptCredential: AutoAcceptCredential.ContentApproved,
useLegacyDidSovPrefix: true,
})
}

Expand Down
Loading

0 comments on commit eb5e492

Please sign in to comment.