@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 +1 -1
- package/srv/notifyToConsole.js +5 -2
- package/srv/notifyToRest.js +7 -3
package/package.json
CHANGED
package/srv/notifyToConsole.js
CHANGED
|
@@ -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
|
|
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(
|
|
21
|
+
buildNotification(message),
|
|
19
22
|
'\n---------------------------------------------------------------\n',
|
|
20
23
|
)
|
|
21
24
|
|
package/srv/notifyToRest.js
CHANGED
|
@@ -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
|
|
14
|
+
this.on(eventsToListen, req => this.postNotification(req))
|
|
15
15
|
return super.init()
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
async postNotification(
|
|
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(
|
|
35
|
+
data: buildNotification(message),
|
|
32
36
|
headers: csrfHeaders,
|
|
33
37
|
});
|
|
34
38
|
} catch (err) {
|