Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: push notifications #28

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b99c6c4
feat: add fcm module initial apis
sairanjit Sep 13, 2023
e8a0a6e
refactor: fcm message handlers
sairanjit Sep 18, 2023
9611cfc
feat: add firebase config and send notifications using firebase cloud…
sairanjit Sep 20, 2023
0075e18
fix: update old fcm record if device token is updated
sairanjit Sep 21, 2023
54d6285
fix: add apns config while sending notifications
sairanjit Sep 22, 2023
44eb696
refactor: add send notification method to service
sairanjit Sep 22, 2023
bedb00f
refactor: skip sending notification if connection is active
sairanjit Sep 22, 2023
ecf3c15
feat: added fcm notification module
Jan 11, 2024
6e15546
refacor: remove the unnecessary module and added validations in notif…
Jan 12, 2024
6eddaa5
refcator: remove the unnecessary firebase-admin package and module
Jan 12, 2024
c71eab1
private the process notification function
Jan 12, 2024
57b3841
Merge pull request #3 from credebl/feat/notification-fcm
sairanjit Feb 19, 2024
f4eefb2
refactor: upgrade credo to version 0.5.3
sairanjit May 24, 2024
41fa64e
feat: add patch for message type
sairanjit May 24, 2024
3275990
refactor: update label
sairanjit May 27, 2024
bb20a89
Merge pull request #6 from credebl/feat/upgrade-051
amitpadmani-awts May 27, 2024
fd371ac
fix: imports for routing events
sairanjit May 27, 2024
e92bf71
Merge pull request #8 from credebl/fix/imports
amitpadmani-awts May 27, 2024
1f84915
fix: add dotenv to dependencies
sairanjit May 27, 2024
b67de3e
Merge pull request #9 from credebl/fix/dotenv-package
KulkarniShashank May 27, 2024
03606af
fix: backup storage
sairanjit May 27, 2024
bcd4db0
Merge pull request #10 from credebl/fix/backup-storage
sairanjit May 27, 2024
3a5cd2d
fix: docker file patches
sairanjit May 27, 2024
46e0777
Merge pull request #11 from credebl/fix/dockerfile-patches
KulkarniShashank May 27, 2024
ab6dddf
chore: upgrade dependencies
sairanjit Jun 28, 2024
5980086
ci: update node version
sairanjit Jun 28, 2024
021e0ac
refactor: added logs
sairanjit Jul 15, 2024
3a78132
Merge pull request #16 from credebl/chore/upgrade-deps
amitpadmani-awts Jul 15, 2024
e454a98
Compass.yml file for config-as-code
atlassian-compass[bot] Oct 30, 2024
592881a
Merge pull request #20 from credebl/compass-github-importer
ajile-in Oct 30, 2024
bd1966a
refactor: cleanup custom logic
sairanjit Dec 20, 2024
67df61f
refactor: env value
sairanjit Dec 20, 2024
0aaa371
fix: build
sairanjit Dec 20, 2024
3f64f7f
chore(deps): update dependencies
ankita-p17 Dec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ POSTGRES_PASSWORD=
POSTGRES_HOST=
POSTGRES_ADMIN_USER=
POSTGRES_ADMIN_PASSWORD=

USE_PUSH_NOTIFICATIONS='true'
NOTIFICATION_WEBHOOK_URL=

# We need NGROK Auth token in development and you can get one from here https://dashboard.ngrok.com/get-started/your-authtoken
NGROK_AUTH_TOKEN=
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 18.x
node-version: 20.x
cache: yarn

# Installing the project dependencies
Expand Down
18 changes: 12 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ FROM ubuntu:20.04 as base
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update -y && apt-get install -y \
apt-transport-https \
curl \
make \
gcc \
g++
apt-transport-https \
curl \
make \
gcc \
g++

# nodejs
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash

# install depdencies and enable corepack
RUN apt-get update -y && apt-get install -y --allow-unauthenticated nodejs
Expand All @@ -28,6 +28,9 @@ WORKDIR /www
COPY package.json /www/package.json
COPY yarn.lock /www/yarn.lock

# Copy patches folder
COPY patches /www/patches

# Run yarn install
RUN yarn install

Expand All @@ -47,6 +50,9 @@ COPY --from=setup /tmp/yarn-cache /tmp/yarn-cache
COPY package.json /www/package.json
COPY yarn.lock /www/yarn.lock

# Copy patches folder
COPY patches /www/patches

WORKDIR /www

# Run yarn install
Expand Down
18 changes: 18 additions & 0 deletions compass.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: mediator-agent
id: ari:cloud:compass:6095931c-8137-4ae1-822a-2d7411835fc7:component/9029b47a-062e-4e25-a761-a2c0fc9ebd98/1808a975-2eb6-4535-9e65-5ebc4d0bdf51
description: An easy to set-up Aries and DIDComm v1 mediator built on Aries Framework JavaScript.
configVersion: 1
typeId: SERVICE
ownerId: ari:cloud:identity::team/6fe50e36-8efb-47a6-aab5-ea47bd10ec4e
fields:
tier: 4
links:
- name: null
type: REPOSITORY
url: https://github.com/credebl/mediator-agent
relationships:
DEPENDS_ON: []
labels:
- language:typescript
- source:github
customFields: null
13 changes: 9 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,18 @@ 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,
authtoken: process.env.NGROK_AUTH_TOKEN,
}).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
34 changes: 16 additions & 18 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 @@ -28,32 +25,33 @@
"prepublishOnly": "yarn run build",
"dev": "ts-node dev",
"start": "NODE_ENV=production node build/index.js",
"validate": "yarn build && yarn check-format"
"validate": "yarn build && yarn check-format",
"postinstall": "npx patch-package"
},
"dependencies": {
"@aries-framework/askar": "^0.4.1",
"@aries-framework/core": "^0.4.1",
"@aries-framework/node": "^0.4.1",
"@hyperledger/aries-askar-nodejs": "^0.1.0",
"express": "^4.18.1",
"prettier": "^2.8.4",
"@credo-ts/askar": "^0.5.0",
"@credo-ts/core": "^0.5.0",
"@credo-ts/node": "^0.5.0",
"@hyperledger/aries-askar-nodejs": "^0.2.0",
"dotenv": "^16.4.5",
"express": "^4.21.2",
"tslog": "^3.3.3",
"tsyringe": "^4.7.0",
"ws": "^8.8.1"
"tsyringe": "^4.8.0",
"ws": "^8.17.1"
},
"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",
"dotenv": "^16.0.1",
"@types/node": "^20.14.9",
"@types/node-fetch": "^2.6.11",
"jest": "^29.2.2",
"ngrok": "^4.3.1",
"prettier": "^2.8.4",
"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"
}
}
45 changes: 45 additions & 0 deletions patches/@credo-ts+core+0.5.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
diff --git a/node_modules/@credo-ts/core/build/agent/MessageSender.js b/node_modules/@credo-ts/core/build/agent/MessageSender.js
index 689b024..656a3b5 100644
--- a/node_modules/@credo-ts/core/build/agent/MessageSender.js
+++ b/node_modules/@credo-ts/core/build/agent/MessageSender.js
@@ -75,7 +75,7 @@ let MessageSender = class MessageSender {
this.logger.debug('Sending message');
await session.send(agentContext, encryptedMessage);
}
- async sendPackage(agentContext, { connection, encryptedMessage, recipientKey, options, }) {
+ async sendPackage(agentContext, { connection, encryptedMessage, recipientKey, options, messageType, }) {
var _a, e_1, _b, _c;
var _d;
const errors = [];
@@ -145,6 +145,7 @@ let MessageSender = class MessageSender {
connectionId: connection.id,
recipientDids: [(0, helpers_1.verkeyToDidKey)(recipientKey)],
payload: encryptedMessage,
+ messageType,
});
return;
}
diff --git a/node_modules/@credo-ts/core/build/modules/message-pickup/storage/MessagePickupRepositoryOptions.d.ts b/node_modules/@credo-ts/core/build/modules/message-pickup/storage/MessagePickupRepositoryOptions.d.ts
index decb61a..b0c4342 100644
--- a/node_modules/@credo-ts/core/build/modules/message-pickup/storage/MessagePickupRepositoryOptions.d.ts
+++ b/node_modules/@credo-ts/core/build/modules/message-pickup/storage/MessagePickupRepositoryOptions.d.ts
@@ -13,6 +13,7 @@ export interface AddMessageOptions {
connectionId: string;
recipientDids: string[];
payload: EncryptedMessage;
+ messageType?: string;
}
export interface RemoveMessagesOptions {
connectionId: string;
diff --git a/node_modules/@credo-ts/core/build/modules/routing/services/MediatorService.js b/node_modules/@credo-ts/core/build/modules/routing/services/MediatorService.js
index 6818a3b..6474136 100644
--- a/node_modules/@credo-ts/core/build/modules/routing/services/MediatorService.js
+++ b/node_modules/@credo-ts/core/build/modules/routing/services/MediatorService.js
@@ -99,6 +99,7 @@ let MediatorService = class MediatorService {
connection,
recipientKey: (0, helpers_1.verkeyToDidKey)(message.to),
encryptedMessage: message.message,
+ messageType: message.messageType,
});
}
}
25 changes: 13 additions & 12 deletions src/agent.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { AskarModule, AskarMultiWalletDatabaseScheme } from '@aries-framework/askar'
import { AskarModule, AskarMultiWalletDatabaseScheme } from '@credo-ts/askar'
import {
Agent,
CacheModule,
ConnectionsModule,
DidCommMimeType,
HttpOutboundTransport,
InMemoryLruCache,
MediatorModule,
OutOfBandRole,
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 @@ -23,13 +21,11 @@ import { AGENT_ENDPOINTS, AGENT_NAME, AGENT_PORT, LOG_LEVEL, POSTGRES_HOST, WALL
import { askarPostgresConfig } from './database'
import { Logger } from './logger'
import { StorageMessageQueueModule } from './storage/StorageMessageQueueModule'
import { PushNotificationsFcmModule } from './push-notifications/fcm'

function createModules() {
const modules = {
StorageModule: new StorageMessageQueueModule(),
cache: new CacheModule({
cache: new InMemoryLruCache({ limit: 500 }),
}),
storageModule: new StorageMessageQueueModule(),
connections: new ConnectionsModule({
autoAcceptConnections: true,
}),
Expand All @@ -40,6 +36,7 @@ function createModules() {
ariesAskar,
multiWalletDatabaseScheme: AskarMultiWalletDatabaseScheme.ProfilePerWallet,
}),
pushNotificationsFcm: new PushNotificationsFcmModule(),
}

return modules
Expand Down Expand Up @@ -80,9 +77,8 @@ export async function createAgent() {
walletConfig: walletConfig,
useDidSovPrefixWhereAllowed: true,
logger: logger,
// FIXME: We should probably remove this at some point, but it will require custom logic
// Also, doesn't work with multi-tenancy yet
autoUpdateStorageOnStartup: true,
backupBeforeStorageUpdate: false,
didCommMimeType: DidCommMimeType.V0,
},
dependencies: agentDependencies,
Expand All @@ -103,6 +99,11 @@ export async function createAgent() {
agent.registerInboundTransport(wsInboundTransport)
agent.registerOutboundTransport(wsOutboundTransport)

// Added health check endpoint
httpInboundTransport.app.get('/health', async (_req, res) => {
res.status(200).send('Ok')
})

// eslint-disable-next-line @typescript-eslint/no-misused-promises
httpInboundTransport.app.get('/invite', async (req, res) => {
if (!req.query._oobid || typeof req.query._oobid !== 'string') {
Expand Down Expand Up @@ -134,4 +135,4 @@ export async function createAgent() {
return agent
}

export type MediatorAgent = ReturnType<typeof createAgent>
export type MediatorAgent = Agent<ReturnType<typeof createModules>>
14 changes: 10 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { LogLevel } from '@aries-framework/core'
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'
export const WALLET_NAME = process.env.WALLET_NAME || 'animo-mediator-dev'
export const WALLET_KEY = process.env.WALLET_KEY || 'animo-mediator-dev'
export const AGENT_NAME = process.env.AGENT_NAME || 'CREDEBL Mediator'
export const WALLET_NAME = process.env.WALLET_NAME || 'credebl-mediator-dev'
export const WALLET_KEY = process.env.WALLET_KEY || 'credebl-mediator-dev'
export const AGENT_ENDPOINTS = process.env.AGENT_ENDPOINTS?.split(',') ?? [
`http://localhost:${AGENT_PORT}`,
`ws://localhost:${AGENT_PORT}`,
Expand All @@ -20,3 +22,7 @@ export const INVITATION_URL = process.env.INVITATION_URL
export const LOG_LEVEL = LogLevel.debug

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
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
Loading