Skip to content

Commit 6a3b882

Browse files
authored
Merge branch 'main' into update-docu
2 parents 8053732 + 3665349 commit 6a3b882

File tree

9 files changed

+13255
-2561
lines changed

9 files changed

+13255
-2561
lines changed

.reuse/dep5

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2-
Upstream-Name: <YOUR-REPO-NAME>
3-
Upstream-Contact: <YOUR-CONTACT (MAIL ADDRESS ETC.)>
4-
Source: <https://github.com/cap-js-community/YOUR-REPO-NAME>
2+
Upstream-Name: notifications
3+
Upstream-Contact: The CAP team <[email protected]>
4+
Source: https://github.com/cap-js/notifications
55
Disclaimer: The code in this project may include calls to APIs ("API Calls") of
66
SAP or third-party products or services developed outside of this project
77
("External Products").
@@ -24,14 +24,6 @@ Disclaimer: The code in this project may include calls to APIs ("API Calls") of
2424
you any rights to use or access any SAP External Product, or provide any third
2525
parties the right to use of access any SAP External Product, through API Calls.
2626

27-
Files: <YOUR-FILE-OR-FOLDER-LIST>
28-
Copyright: <YEARS-RELEVANT-FOR-YOUR-PROJECT> SAP SE or an SAP affiliate company and <YOUR-PROJECT-NAME> contributors
27+
Files: *
28+
Copyright: 2023 SAP SE or an SAP affiliate company and audit-logging contributors.
2929
License: Apache-2.0
30-
31-
Files: <THIRD-PARTY-FILE-OR-FOLDER-LIST>
32-
Copyright: <COPYRIGHT-OF-THIRD-PARTY-CODE>
33-
License: <LICENSE-OF-THIRD-PARTY-CODE>
34-
35-
Files: <ANOTHER-THIRD-PARTY-FILE-OR-FOLDER-LIST>
36-
Copyright: <COPYRIGHT-OF-ANOTHER-THIRD-PARTY-CODE>
37-
License: <LICENSE-OF-ANOTHER- THIRD-PARTY-CODE>

README.md

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1+
[![REUSE status](https://api.reuse.software/badge/github.com/cap-js/notifications)](https://api.reuse.software/info/github.com/cap-js/notifications)
12

2-
The `@cap-js/notifications` package is a [CDS plugin](https://cap.cloud.sap/docs/node.js/cds-plugins#cds-plugin-packages) providing out-of-the box support for publishing business notifications.
3+
# Notifications Plugin
4+
5+
The `@cap-js/notifications` package is a [CDS plugin](https://cap.cloud.sap/docs/node.js/cds-plugins#cds-plugin-packages) that provides support for publishing business notifications.
36

47
### Table of Contents
58

69
- [Setup](#setup)
710
- [Usage](#usage)
811
- [Update Notification Configuration](#update-notification-configuration)
9-
- [Notification Destination](#notification-destination)
1012
- [Notification Types Path](#notification-types-path)
1113
- [Notification Type Prefix](#notification-type-prefix)
1214
- [Add Notification Types](#add-notification-types)
13-
- [Update handlers to publish notification](#update-handlers-to-publish-notification)
14-
- [Simple Notificaiton with title](#simple-notificaiton-with-title)
15-
- [Simple Notificaiton with title & description](#simple-notificaiton-with-title)
16-
- [Custom Notifications with notification types](#simple-notificaiton-with-title)
15+
- [Add code to send notifications](#add-code-to-send-notifications)
16+
- [Simple Notification with title](#simple-notification-with-title)
17+
- [Simple Notification with title and description](#simple-notification-with-title-and-description)
18+
- [Custom Notifications](#custom-notifications)
1719
- [Sample Application with notifications](#sample-application-with-notifications)
1820
- [In Local Environment](#in-local-environment)
1921
- [In Production Environment](#in-production-environment)
22+
- [Notification Destination](#notification-destination)
23+
- [Integrate with SAP Build Work Zone](#integrate-with-sap-build-work-zone)
2024
- [Contributing](#contributing)
2125
- [Code of Conduct](#code-of-conduct)
2226
- [Licensing](#licensing)
@@ -41,15 +45,11 @@ In this guide, we use the [Incidents Management reference sample app](https://gi
4145

4246
<img width="1300" alt="Default Notification config" style="border-radius:0.5rem" src="_assets/packageJsonConfig.gif">
4347

44-
#### **Notification Destination**
45-
46-
As a pre-requisite to publish the notification, you need to have a [destination](https://help.sap.com/docs/build-work-zone-standard-edition/sap-build-work-zone-standard-edition/enabling-notifications-for-custom-apps-on-sap-btp-cloud-foundry#configure-the-destination-to-the-notifications-service) configured to publish the notification. In the `package.json` by default destination name `SAP_Notification` is added, you can modify the destination name that you are configuring.
47-
48-
#### **Notification Types Path**
48+
#### Notification Types Path
4949

5050
When you run `cds add notifications`, it will add `notificationstype.json` file with template for a notification type in the project root folder. You can add the notification types in the `notificationtype.json` file for sending the custom notification types.
5151

52-
#### **Notification Type Prefix**
52+
#### Notification Type Prefix
5353

5454
To make notification types unique to the application, prefix is added to the type key. By default, `application name` is added as the prefix. You can update the `prefix` if required.
5555

@@ -78,34 +78,35 @@ Sample: If you want to send the notification when the new incident is reported,
7878
]
7979
```
8080

81-
### Update handlers to publish notification
81+
### Add code to send notifications
8282

8383
In the handler files, connect to the notifications plugin by:
8484

8585
```js
8686
const alert = await cds.connect.to('notifications');
8787
```
8888

89-
#### **Simple Notificaiton with title**
89+
#### Simple Notification with title
9090
You can use the following signature to send the simple notification with title
9191
```js
9292
alert.notify({
93-
recipients: recipients,
94-
priority: priority,
95-
title: title
93+
94+
priority: "HIGH",
95+
title: "New incident is reported!"
9696
});
9797
```
98-
#### **Simple Notificaiton with title & description**
98+
#### Simple Notification with title and description
9999
You can use the following signature to send the simple notification with title and description
100100
```js
101101
alert.notify({
102-
recipients: recipients,
103-
priority: priority,
104-
title: title,
105-
description: description
102+
recipients: ["[email protected]"],
103+
priority: "HIGH",
104+
title: "New high priority incident is assigned to you!",
105+
description: "Incident titled 'Engine overheating' created by 'customer X' with priority high is assigned to you!"
106106
});
107107
```
108-
#### **Custom Notifications with notification types**
108+
109+
#### **Custom Notifications**
109110
You can use these two signature to send the custom notification with pre-defined notification types.
110111

111112
##### **Passing the whole notification object**
@@ -131,7 +132,7 @@ alert.notify({
131132
Type: 'String'
132133
}
133134
],
134-
Recipients: recipients
135+
135136
});
136137
```
137138

@@ -192,14 +193,20 @@ Possible parameters:
192193

193194
### Sample Application with notifications
194195

195-
#### **In Local Environment**
196+
#### In Local Environment
196197
In local environment, when you publish notification, it is mocked to publish the nofication to the console.
197198

198199
<img width="1300" alt="Notify to console" style="border-radius:0.5rem;padding:1rem;background:rgb(24 24 24)" src="_assets/notifyToConsole.png">
199200

200-
#### **In Production Environment**
201+
#### In Production Environment
202+
203+
##### Notification Destination
204+
205+
As a pre-requisite to publish the notification, you need to have a [destination](https://help.sap.com/docs/build-work-zone-standard-edition/sap-build-work-zone-standard-edition/enabling-notifications-for-custom-apps-on-sap-btp-cloud-foundry#configure-the-destination-to-the-notifications-service) configured to publish the notification. In the `package.json` by default destination name `SAP_Notification` is added, you can modify the destination name that you are configuring.
206+
207+
##### Integrate with SAP Build Work Zone
201208

202-
Once application is deployed and integrated with SAP Build Work Zone, you can see the notification under fiori notifications icon!
209+
Once application is deployed and [integrated with SAP Build Work Zone](https://github.com/cap-js/calesi/tree/main/samples/notifications), you can see the notification under fiori notifications icon!
203210

204211
<img width="1300" alt="Sample Application Demo" style="border-radius:0.5rem;" src="_assets/incidentsNotificationDemo.gif">
205212

lib/utils.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const { existsSync, readFileSync } = require('fs');
22
const { basename } = require('path');
33
const cds = require("@sap/cds");
44
const LOG = cds.log('notifications');
5-
const { executeHttpRequest } = require("@sap-cloud-sdk/http-client");
65
const { getDestination } = require("@sap-cloud-sdk/connectivity");
76
const PRIORITIES = ["LOW", "NEUTRAL", "MEDIUM", "HIGH"];
87

@@ -23,12 +22,12 @@ const messages = {
2322
};
2423

2524
function validateNotificationTypes(notificationTypes) {
26-
notificationTypes.forEach((notificationType) => {
25+
for(notificationType of notificationTypes){
2726
if (!("NotificationTypeKey" in notificationType)) {
2827
LOG._warn && LOG.warn(messages.INVALID_NOTIFICATION_TYPES);
2928
return false;
3029
}
31-
});
30+
}
3231

3332
return true;
3433
}
@@ -128,22 +127,6 @@ function getNotificationTypesKeyWithPrefix(notificationTypeKey) {
128127
return `${prefix}/${notificationTypeKey}`;
129128
}
130129

131-
async function executeRequest(httpMethod, targetUrl, payload, notificationDestination, csrfHeaders) {
132-
let response = {};
133-
try {
134-
response = await executeHttpRequest(notificationDestination, {
135-
url: targetUrl,
136-
method: httpMethod,
137-
data: payload,
138-
headers: csrfHeaders,
139-
});
140-
} catch (e) {
141-
console.log(e);
142-
response = e.response.data;
143-
}
144-
return response;
145-
}
146-
147130
function buildDefaultNotification(
148131
recipients,
149132
priority = "NEUTRAL",
@@ -255,6 +238,5 @@ module.exports = {
255238
getNotificationDestination,
256239
getPrefix,
257240
getNotificationTypesKeyWithPrefix,
258-
executeRequest,
259241
buildNotification
260242
};

0 commit comments

Comments
 (0)