-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from credebl/refactor/mediator
feat: push notifications
- Loading branch information
Showing
39 changed files
with
2,304 additions
and
501 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,6 @@ | |
"type": "git", | ||
"url": "https://github.com/animo/animo-mediator" | ||
}, | ||
"engines": { | ||
"node": "^18.0.0" | ||
}, | ||
"packageManager": "[email protected]", | ||
"scripts": { | ||
"test": "jest", | ||
|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type { FcmDeviceInfo } from './models' | ||
|
||
import { OutboundMessageContext, AgentContext, ConnectionService, injectable, MessageSender } from '@credo-ts/core' | ||
|
||
import { PushNotificationsFcmService } from './services/PushNotificationsFcmService' | ||
import { | ||
PushNotificationsFcmDeviceInfoHandler, | ||
PushNotificationsFcmProblemReportHandler, | ||
PushNotificationsFcmSetDeviceInfoHandler, | ||
} from './handlers' | ||
|
||
@injectable() | ||
export class PushNotificationsFcmApi { | ||
private messageSender: MessageSender | ||
private pushNotificationsService: PushNotificationsFcmService | ||
private connectionService: ConnectionService | ||
private agentContext: AgentContext | ||
|
||
public constructor( | ||
messageSender: MessageSender, | ||
pushNotificationsService: PushNotificationsFcmService, | ||
connectionService: ConnectionService, | ||
agentContext: AgentContext | ||
) { | ||
this.messageSender = messageSender | ||
this.pushNotificationsService = pushNotificationsService | ||
this.connectionService = connectionService | ||
this.agentContext = agentContext | ||
|
||
this.agentContext.dependencyManager.registerMessageHandlers([ | ||
new PushNotificationsFcmSetDeviceInfoHandler(this.pushNotificationsService), | ||
new PushNotificationsFcmDeviceInfoHandler(), | ||
new PushNotificationsFcmProblemReportHandler(this.pushNotificationsService), | ||
]) | ||
} | ||
|
||
/** | ||
* Sends the requested fcm device info (token) to another agent via a `connectionId` | ||
* Response for `push-notifications-fcm/get-device-info` | ||
* | ||
* @param connectionId The connection ID string | ||
* @param threadId get-device-info message ID | ||
* @param deviceInfo The FCM device info | ||
* @returns Promise<void> | ||
*/ | ||
public async deviceInfo(options: { connectionId: string; threadId: string; deviceInfo: FcmDeviceInfo }) { | ||
const { connectionId, threadId, deviceInfo } = options | ||
const connection = await this.connectionService.getById(this.agentContext, connectionId) | ||
connection.assertReady() | ||
|
||
const message = this.pushNotificationsService.createDeviceInfo({ threadId, deviceInfo }) | ||
|
||
const outbound = new OutboundMessageContext(message, { | ||
agentContext: this.agentContext, | ||
connection: connection, | ||
}) | ||
await this.messageSender.sendMessage(outbound) | ||
} | ||
} |
Oops, something went wrong.