-
Notifications
You must be signed in to change notification settings - Fork 7
/
request.js
42 lines (35 loc) · 857 Bytes
/
request.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
35
36
37
38
39
40
41
const Parser = require('fast-xml-parser').j2xParser;
const parser = new Parser({
attributeNamePrefix: '@',
ignoreAttributes: false
});
function getData(data) {
if (!data) {
return {};
}
return Object.keys(data).reduce((a, name) => {
const value = data[name];
if (value !== undefined) {
a[name] = (value === null) ? '' : value.toString();
}
return a;
}, {});
}
function createSOAPAction(service, actionName, data) {
const envelope = {
's:Envelope': {
'@xmlns:s': 'http://schemas.xmlsoap.org/soap/envelope/',
'@s:encodingStyle': 'http://schemas.xmlsoap.org/soap/encoding/',
's:Body': {
[`u:${actionName}`]: {
'@xmlns:u': service.serviceType,
...getData(data)
}
}
}
}
return parser.parse(envelope);
}
module.exports = {
createSOAPAction
}