-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetClient.ts
executable file
·68 lines (62 loc) · 1.33 KB
/
getClient.ts
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import EasySoap from "easysoap";
interface Params {
host: string;
path: string;
wsdl: string;
rejectUnauthorized: boolean;
}
interface Opts {
secure: boolean;
}
const callMethod = (
soapClient: any,
methodName: string,
params: any,
xmlns: string,
cb: any
) => {
soapClient
.call({
method: methodName,
attributes: {
xmlns: xmlns,
},
params: params,
})
.then((callResponse) => {
cb(
null,
callResponse.data,
callResponse.response.body,
callResponse.response.header
);
})
.catch((err) => {
cb(err, null, null, null);
});
};
async function getClient<T>(
params: Params,
opts: Opts,
xmlns: string
): Promise<T> {
return new Promise((resolve, reject) => {
const soapClient = EasySoap(params, opts);
soapClient
.getAllFunctions()
.then((functionArray) => {
const client = {};
for (var key in functionArray) {
const methodName = functionArray[key];
client[methodName] = (params, cb) => {
callMethod(soapClient, methodName, params, xmlns, cb);
};
}
resolve(client as T);
})
.catch((err) => {
reject(err);
});
});
}
export default getClient;