Skip to content

Commit

Permalink
refactor: upgrade credo to version 0.5.3
Browse files Browse the repository at this point in the history
Signed-off-by: Sai Ranjit Tummalapalli <[email protected]>
  • Loading branch information
sairanjit committed May 24, 2024
1 parent 57b3841 commit f4eefb2
Show file tree
Hide file tree
Showing 26 changed files with 1,696 additions and 1,339 deletions.
12 changes: 8 additions & 4 deletions dev.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { config } from 'dotenv'
import { connect } from 'ngrok'
import { connect } from '@ngrok/ngrok'

config()

Expand All @@ -9,13 +9,17 @@ const port = 3000
* Connect to ngrok and then set the port and url on the environment before importing
* the index file.
*/
void connect(port).then((url) => {
// TODO: have to add auth token now to use ngrok check this later
void connect({
port,
}).then((app) => {
// eslint-disable-next-line no-console
console.log('Got ngrok url:', url)
console.log('Got ngrok url:', app.url())
const url = app.url()

process.env.NODE_ENV = 'development'
process.env.AGENT_PORT = `${port}`
process.env.AGENT_ENDPOINTS = `${url},${url.replace('http', 'ws')}`
process.env.AGENT_ENDPOINTS = `${url},${url?.replace('http', 'ws')}`
process.env.SHORTENER_BASE_URL = `${url}/s`

require('./src/index')
Expand Down
25 changes: 11 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
"type": "git",
"url": "https://github.com/animo/animo-mediator"
},
"engines": {
"node": "^18.0.0"
},
"packageManager": "[email protected]",
"scripts": {
"test": "jest",
Expand All @@ -32,30 +29,30 @@
"postinstall": "patch-package"
},
"dependencies": {
"@aries-framework/askar": "0.4.2",
"@aries-framework/core": "0.4.2",
"@aries-framework/node": "0.4.2",
"@hyperledger/aries-askar-nodejs": "^0.1.1",
"@credo-ts/askar": "0.5.3",
"@credo-ts/core": "0.5.3",
"@credo-ts/node": "0.5.3",
"@hyperledger/aries-askar-nodejs": "0.2.1",
"express": "^4.18.1",
"prettier": "^2.8.4",
"tslog": "^3.3.3",
"tsyringe": "^4.7.0",
"ws": "^8.8.1"
"tsyringe": "^4.8.0",
"ws": "^8.13.0"
},
"devDependencies": {
"@ngrok/ngrok": "^1.2.0",
"@types/express": "^4.17.13",
"@types/jest": "^29.2.0",
"@types/node": "^16",
"@types/node-fetch": "^2.6.4",
"@types/node": "^18.18.8",
"@types/node-fetch": "^2.6.11",
"dotenv": "^16.0.1",
"jest": "^29.2.2",
"ngrok": "^4.3.1",
"patch-package": "^8.0.0",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
},
"resolutions": {
"ref-napi": "npm:@2060.io/ref-napi"
"engines": {
"node": ">=18"
}
}
112 changes: 0 additions & 112 deletions patches/@aries-framework+core+0.4.2.patch

This file was deleted.

12 changes: 5 additions & 7 deletions src/agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AskarModule, AskarMultiWalletDatabaseScheme } from '@aries-framework/askar'
import { AskarModule, AskarMultiWalletDatabaseScheme } from '@credo-ts/askar'
import {
Agent,
CacheModule,
Expand All @@ -11,8 +11,8 @@ import {
OutOfBandState,
WalletConfig,
WsOutboundTransport,
} from '@aries-framework/core'
import { HttpInboundTransport, WsInboundTransport, agentDependencies } from '@aries-framework/node'
} from '@credo-ts/core'
import { HttpInboundTransport, WsInboundTransport, agentDependencies } from '@credo-ts/node'
import { ariesAskar } from '@hyperledger/aries-askar-nodejs'
import type { Socket } from 'net'

Expand All @@ -35,12 +35,10 @@ import { Logger } from './logger'
import { StorageMessageQueueModule } from './storage/StorageMessageQueueModule'
import { PushNotificationsFcmModule } from './push-notifications/fcm'
import { routingEvents } from './events/RoutingEvents'
import { initializeApp } from 'firebase-admin/app'
import { credential } from 'firebase-admin'

function createModules() {
const modules = {
StorageModule: new StorageMessageQueueModule(),
storageModule: new StorageMessageQueueModule(),
cache: new CacheModule({
cache: new InMemoryLruCache({ limit: 500 }),
}),
Expand Down Expand Up @@ -142,7 +140,7 @@ export async function createAgent() {
if (USE_PUSH_NOTIFICATIONS && NOTIFICATION_WEBHOOK_URL) {
routingEvents(agent)
}

// When an 'upgrade' to WS is made on our http server, we forward the
// request to the WS server
httpInboundTransport.server?.on('upgrade', (request, socket, head) => {
Expand Down
7 changes: 3 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LogLevel } from '@aries-framework/core'
import * as dotenv from 'dotenv';
dotenv.config();
import { LogLevel } from '@credo-ts/core'
import * as dotenv from 'dotenv'
dotenv.config()

export const AGENT_PORT = process.env.AGENT_PORT ? Number(process.env.AGENT_PORT) : 3000
export const AGENT_NAME = process.env.AGENT_NAME || 'Animo Mediator'
Expand All @@ -26,4 +26,3 @@ export const IS_DEV = process.env.NODE_ENV === 'development'
export const USE_PUSH_NOTIFICATIONS = process.env.USE_PUSH_NOTIFICATIONS === 'true'

export const NOTIFICATION_WEBHOOK_URL = process.env.NOTIFICATION_WEBHOOK_URL || 'http://localhost:5000'

2 changes: 1 addition & 1 deletion src/database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AskarWalletPostgresStorageConfig } from '@aries-framework/askar/build/wallet'
import type { AskarWalletPostgresStorageConfig } from '@credo-ts/askar/build/wallet'

import { POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST } from './constants'

Expand Down
19 changes: 0 additions & 19 deletions src/events/RoutingEvents.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OutOfBandRepository, OutOfBandRole, OutOfBandState } from '@aries-framework/core'
import { OutOfBandRepository, OutOfBandRole, OutOfBandState } from '@credo-ts/core'

import { createAgent } from './agent'
import { INVITATION_URL } from './constants'
Expand Down
4 changes: 2 additions & 2 deletions src/logger/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { LogLevel, BaseLogger } from '@aries-framework/core'
import { LogLevel, BaseLogger } from '@credo-ts/core'
import { Logger as TSLogger } from 'tslog'

import { replaceError } from './replaceError'
Expand All @@ -23,7 +23,7 @@ export class Logger extends BaseLogger {
super(logLevel)

this.logger = new TSLogger({
name: 'DIDComm Chat',
name: 'Mediator Agent',
minLevel: this.logLevel == LogLevel.off ? 'fatal' : this.tsLogLevelMap[this.logLevel],
ignoreStackLevels: 5,
})
Expand Down
18 changes: 1 addition & 17 deletions src/push-notifications/fcm/PushNotificationsFcmApi.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import type { FcmDeviceInfo } from './models'

import {
OutboundMessageContext,
AgentContext,
ConnectionService,
injectable,
MessageSender,
} from '@aries-framework/core'
import { OutboundMessageContext, AgentContext, ConnectionService, injectable, MessageSender } from '@credo-ts/core'

import { PushNotificationsFcmService } from './services/PushNotificationsFcmService'
import {
Expand Down Expand Up @@ -62,14 +56,4 @@ export class PushNotificationsFcmApi {
})
await this.messageSender.sendMessage(outbound)
}

/**
* Send push notification to device
*
* @param connectionId The connection ID string
* @returns Promise<void>
*/
public async sendNotification(connectionId: string, messageType: string) {
return this.pushNotificationsService.sendNotification(this.agentContext, connectionId, messageType)
}
}
4 changes: 2 additions & 2 deletions src/push-notifications/fcm/PushNotificationsFcmModule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DependencyManager, FeatureRegistry, Module } from '@aries-framework/core'
import type { DependencyManager, FeatureRegistry, Module } from '@credo-ts/core'

import { Protocol } from '@aries-framework/core'
import { Protocol } from '@credo-ts/core'

import { PushNotificationsFcmApi } from './PushNotificationsFcmApi'
import { PushNotificationsFcmService } from './services/PushNotificationsFcmService'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PushNotificationsFcmProblemReportReason } from './PushNotificationsFcmProblemReportReason'
import type { ProblemReportErrorOptions } from '@aries-framework/core'
import type { ProblemReportErrorOptions } from '@credo-ts/core'

import { ProblemReportError } from '@aries-framework/core'
import { ProblemReportError } from '@credo-ts/core'

import { PushNotificationsFcmProblemReportMessage } from '../messages'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MessageHandler, MessageHandlerInboundMessage } from '@aries-framework/core'
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core'

import { PushNotificationsFcmDeviceInfoMessage } from '../messages'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MessageHandler, MessageHandlerInboundMessage } from '@aries-framework/core'
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core'

import { PushNotificationsFcmProblemReportMessage } from '../messages'
import { PushNotificationsFcmService } from '../services'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MessageHandler, MessageHandlerInboundMessage } from '@aries-framework/core'
import type { MessageHandler, MessageHandlerInboundMessage } from '@credo-ts/core'

import { PushNotificationsFcmService } from '../services/PushNotificationsFcmService'
import { PushNotificationsFcmSetDeviceInfoMessage } from '../messages'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FcmDeviceInfo } from '../models'

import { AgentMessage, IsValidMessageType, parseMessageType } from '@aries-framework/core'
import { AgentMessage, IsValidMessageType, parseMessageType } from '@credo-ts/core'
import { Expose } from 'class-transformer'
import { IsString, ValidateIf } from 'class-validator'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ProblemReportMessageOptions } from '@aries-framework/core'
import type { ProblemReportMessageOptions } from '@credo-ts/core'

import { IsValidMessageType, parseMessageType, ProblemReportMessage } from '@aries-framework/core'
import { IsValidMessageType, parseMessageType, ProblemReportMessage } from '@credo-ts/core'

export type PushNotificationsFcmProblemReportMessageOptions = ProblemReportMessageOptions

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FcmDeviceInfo } from '../models'

import { AgentMessage, IsValidMessageType, parseMessageType } from '@aries-framework/core'
import { AgentMessage, IsValidMessageType, parseMessageType } from '@credo-ts/core'
import { Expose } from 'class-transformer'
import { IsString, ValidateIf } from 'class-validator'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TagsBase } from '@aries-framework/core'
import type { TagsBase } from '@credo-ts/core'

import { utils, BaseRecord } from '@aries-framework/core'
import { utils, BaseRecord } from '@credo-ts/core'

export type DefaultPushNotificationsFcmTags = {
connectionId: string
Expand Down
Loading

0 comments on commit f4eefb2

Please sign in to comment.