-
Notifications
You must be signed in to change notification settings - Fork 4
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 #740 from dhis2/master
chore: merge master into next
- Loading branch information
Showing
16 changed files
with
670 additions
and
393 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "client", | ||
"version": "2.32.2", | ||
"version": "2.33.0", | ||
"description": "The App Hub Client", | ||
"repository": "https://github.com/dhis2/app-hub", | ||
"author": "Birk Johansson <[email protected]>", | ||
|
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
const { | ||
convertAppToV1AppVersion, | ||
convertAppsToApiV1Format, | ||
getMediaUrl, | ||
} = require('./convertAppsToApiV1Format') | ||
|
||
module.exports = { | ||
convertAppToV1AppVersion: require('./convertAppsToApiV1Format') | ||
.convertAppToV1AppVersion, | ||
convertAppsToApiV1Format: require('./convertAppsToApiV1Format') | ||
.convertAppsToApiV1Format, | ||
convertAppToV1AppVersion, | ||
convertAppsToApiV1Format, | ||
getMediaUrl, | ||
} |
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
25 changes: 25 additions & 0 deletions
25
server/src/services/NotificationService/NotificationMessager.js
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,25 @@ | ||
const messagerTypes = { | ||
WEBHOOK: 'webhook', | ||
email: 'email', | ||
} | ||
|
||
class NotificationMessager { | ||
constructor(name, { type } = {}) { | ||
if (this.constructor === NotificationMessager) { | ||
throw new TypeError( | ||
'Class "NotificationMessager" cannot be instantiated directly.' | ||
) | ||
} | ||
this.name = name | ||
this.type = type | ||
} | ||
|
||
send() { | ||
throw new Error('Method "sendNotification" must be implemented.') | ||
} | ||
} | ||
|
||
module.exports = { | ||
messagerTypes, | ||
NotificationMessager, | ||
} |
72 changes: 72 additions & 0 deletions
72
server/src/services/NotificationService/NotificationService.js
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,72 @@ | ||
const Schmervice = require('@hapipal/schmervice') | ||
const { SlackWebhookMessager } = require('./SlackWebhookMessager.js') | ||
|
||
class NotificationService extends Schmervice.Service { | ||
constructor(server, schmerviceOptions, { messagers }) { | ||
super(server, schmerviceOptions) | ||
|
||
if (!messagers || messagers.length < 1) { | ||
server.logger.warn( | ||
'No messagers provided to NotificationService, notifications will not be sent.' | ||
) | ||
} else { | ||
const messagersName = messagers.map((m) => m.name).join(', ') | ||
server.logger.info( | ||
`Init NotificationService with messagers: ${messagersName}` | ||
) | ||
} | ||
|
||
this.messagers = messagers | ||
} | ||
|
||
async sendNewAppNotifications({ | ||
appName, | ||
imageUrl, | ||
link, | ||
organisationName, | ||
sourceUrl, | ||
}) { | ||
const newAppMessagers = this.messagers.filter( | ||
(m) => !!m.sendNewAppNotification | ||
) | ||
if (newAppMessagers.length < 1) { | ||
return Promise.resolve(null) | ||
} | ||
|
||
const promises = newAppMessagers.map((messager) => { | ||
this.server.logger.info( | ||
`Sending new app notification, using messager: ${messager.name}` | ||
) | ||
return messager.sendNewAppNotification({ | ||
appName, | ||
imageUrl, | ||
link, | ||
organisationName, | ||
sourceUrl, | ||
}) | ||
}) | ||
return Promise.all(promises) | ||
} | ||
} | ||
|
||
const createNotificationService = (server, schmerviceOptions) => { | ||
const service = new NotificationService(server, schmerviceOptions, { | ||
messagers: createMessagers(server), | ||
}) | ||
return Schmervice.withName('notificationService', service) | ||
} | ||
|
||
const createMessagers = (server) => { | ||
const messagers = [] | ||
const { config } = server.realm.settings.bind | ||
if (config.slack?.webhookUrl) { | ||
const slackMessager = new SlackWebhookMessager( | ||
'slack', | ||
config.slack.webhookUrl | ||
) | ||
messagers.push(slackMessager) | ||
} | ||
return messagers | ||
} | ||
|
||
module.exports = { NotificationService, createNotificationService } |
Oops, something went wrong.