easy-soap-request
easy-soap-request copied to clipboard
Deno Feedback
Deno supports await on root so no need to wrap your deno example in the closure.
This would be fine.
// usage of module
import soapRequest from 'https://deno.land/x/easy_soap_request/index.d.js';
// example data
const url = 'https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php';
const sampleHeaders = {
'user-agent': 'sampleTest',
'Content-Type': 'text/xml;charset=UTF-8',
'soapAction': 'https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListZipCode',
};
// usage of module
const xml = await Deno.readFile('test/zip-code-envelope.xml');
const { response } = await soapRequest({ url: url, headers: sampleHeaders, xml: xml });
const { headers, body, statusCode } = response;
console.log(headers);
console.log(body);
console.log(statusCode);
I also noticed that the typing is off. the xml prop is typed as string but being passed in as a Uint8Array. Also method and extraOpts are required and not optional so it is throwing type errors. Some of the props are missing.
Changing your index.d.ts to something like this should fix the typing. Of course you could obfuscate the axios types if you want but it would provide a better experience for people who are consuming this lib if it has solid types.
import { AxiosRequestConfig, AxiosResponse } from 'axios'
export interface SoapRequest {
url: string;
headers: Headers | Record<string, string>;
xml: string | Uint8Array;
method?: 'POST';
extraOpts?: AxiosRequestConfig;
timeout?: number;
proxy?: AxiosRequestConfig['proxy'];
maxBodyLength?: AxiosRequestConfig['maxBodyLength'];
maxContentLength?: AxiosRequestConfig['maxContentLength'];
}
export interface SoapResponse<T = string> {
response: {
headers: AxiosResponse['headers'],
body: AxiosResponse<T>['data'],
statusCode: AxiosResponse['status'],
}
}
/**
* @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 {int} opts.timeout Milliseconds before timing out request
* @param {object} opts.proxy Object with proxy configuration
* @param {int} opts.maxBodyLength Limit body size being sent(bytes)
* @param {int} opts.maxContentLength Limit content size being sent(bytes)
* @param {object} opts.extraOpts Object of additional axios parameters
* @promise response
* @reject {error}
* @fulfill {body,statusCode}
* @returns {Promise.response{body,statusCode}}
*/
export default function soapRequest <T = string>(opts: SoapRequest): Promise<SoapResponse<T>>
Deno was very new when I first wrote the implementation. I was/am also not an expert. I'm open to PR's though!