@neoimpulse/cap-js-notifications 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neoimpulse/cap-js-notifications",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A CDS plugin to provide an easy action for the notification service",
5
5
  "main": "cds-plugin.js",
6
6
  "scripts": {
@@ -11,11 +11,14 @@ module.exports = class NotifyToConsole extends cds.Service {
11
11
 
12
12
  this.on(eventsToListen, req => {
13
13
  LOG._debug && LOG.debug('Handling notification event:', req.event)
14
- const notification = req.data; if (!notification) return
14
+ const data = req.data;
15
+ const type = data.type
16
+ const message = data.message
17
+ message.type = type
15
18
  console.log (
16
19
  '\n---------------------------------------------------------------\n' +
17
20
  'Notification:', req.event,
18
- buildNotification(notification),
21
+ buildNotification(message),
19
22
  '\n---------------------------------------------------------------\n',
20
23
  )
21
24
 
@@ -11,11 +11,15 @@ module.exports = exports = class NotifyToRest extends cds.Service {
11
11
  const notificationTypes = readFile(cds.env.requires?.notifications?.types);
12
12
  const eventsToListen = notificationTypes.map(notificationType => notificationType.NotificationTypeKey);
13
13
  LOG._info && LOG.info(`Listening to events: ${eventsToListen.join(", ")}`);
14
- this.on(eventsToListen, req => this.postNotification(req.data))
14
+ this.on(eventsToListen, req => this.postNotification(req))
15
15
  return super.init()
16
16
  }
17
17
 
18
- async postNotification(notificationData) {
18
+ async postNotification(req) {
19
+ const data = req.data;
20
+ const type = data.type
21
+ const message = data.message
22
+ message.type = type
19
23
  const notificationDestination = await getNotificationDestination();
20
24
  const csrfHeaders = await buildHeadersForDestination(notificationDestination, {
21
25
  url: NOTIFICATIONS_API_ENDPOINT,
@@ -28,7 +32,7 @@ module.exports = exports = class NotifyToRest extends cds.Service {
28
32
  await executeHttpRequest(notificationDestination, {
29
33
  url: `${NOTIFICATIONS_API_ENDPOINT}/Notifications`,
30
34
  method: "post",
31
- data: buildNotification(notificationData),
35
+ data: buildNotification(message),
32
36
  headers: csrfHeaders,
33
37
  });
34
38
  } catch (err) {