forked from circa10a/easy-soap-request
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.js
51 lines (51 loc) · 1.25 KB
/
index.d.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
43
44
45
46
47
48
49
50
51
/**
* Deno module for easy-soap-request
* @author Caleb Lemoine
* @param {object} opts easy-soap-request options
* @param {string} opts.method HTTP request method
* @param {string} opts.url endpoint URL
* @param {object} opts.headers HTTP headers, can be string or object
* @param {string} opts.xml SOAP envelope, can be read from file or passed as string
* @param {object} opts.extraOpts Object of additional fetch parameters
* @promise response
* @reject {error}
* @fulfill {body,statusCode}
* @returns {Promise.response{body,statusCode}}
*/
export default function soapRequest(opts = {
method: 'POST',
url: '',
headers: {},
xml: '',
extraOpts: {},
}) {
const {
method,
url,
headers,
xml,
extraOpts,
} = opts;
return new Promise((resolve, reject) => {
fetch(url, {
method: method || 'POST',
headers,
body: xml,
...extraOpts,
}).then(async (response) => {
resolve({
response: {
headers: response.headers,
body: await response.text(),
statusCode: response.status,
},
});
}).catch(async (error) => {
if (error.response) {
reject(await error.response.text());
} else {
reject(error);
}
});
});
}