-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataServiceClient.js
42 lines (34 loc) · 1.21 KB
/
DataServiceClient.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
42
import uuidv4 from 'uuid/v4';
import soap from 'soap';
import fs from 'fs';
export default async function DataServiceClient(action, args) {
let url = 'http://schemas.kvk.nl/contracts/kvk/dataservice/catalogus/2015/02/KVK-KvKDataservice.wsdl';
let client;
try {
client = await soap.createClientAsync(url);
} catch (error) {
console.log(error);
}
let uu = uuidv4();
client.setEndpoint('https://webservices.preprod.kvk.nl/postbus2');
client.addSoapHeader(`<wsa:Action Id="_2">http://es.kvk.nl/${action}</wsa:Action>`);
client.addSoapHeader(`<wsa:MessageID Id="_3">uuid:${uu}</wsa:MessageID>`);
client.addSoapHeader(`<wsa:To Id="_4">http://es.kvk.nl/KVK-DataservicePP/2015/02</wsa:To>`);
let privateKey = fs.readFileSync('./keys/privateKey.pem');
let publicKey = fs.readFileSync('./keys/innovatielab-2018.kvk.nl.cer');
let wsSecurity = new soap.WSSecurityCert(privateKey, publicKey);
client.setSecurity(wsSecurity);
client.setSSLSecurity(
new soap.ClientSSLSecurity(
'./keys/privateKey.pem',
'./keys/innovatielab-2018.kvk.nl.cer'
)
);
let result
try {
result = await client[`${action}Async`](args);
} catch (error) {
console.log(error);
}
return result
}