-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
34 lines (30 loc) · 965 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const cds = require("@sap/cds");
const { readDestination } = require("sap-cf-destconn");
const Destination = require("./src/Destination");
function to(destination) {
return new Promise((resolve, reject) => {
const config = cds.env.requires[destination];
if (!config) {
reject(new Error(`CDSE: Missing destination configuration for ${destination}!`));
}
if (!config.credentials) {
reject(new Error("CDSE: External service configuration without credentials is not supported!"));
}
if (config.credentials.destination) {
readDestination(config.credentials.destination)
.then(credentials => {
resolve(new Destination(credentials.destinationConfiguration));
})
.catch(reject);
} else if (config.credentials.url) {
resolve(new Destination(config.credentials));
} else {
reject(new Error(`CDSE: Missing credentials configuration for destination ${destination}`));
}
});
}
module.exports = {
connect: {
to: to
}
};