Skip to content

Commit

Permalink
Merge 7741647 into 23e3336
Browse files Browse the repository at this point in the history
  • Loading branch information
circa10a committed Apr 25, 2020
2 parents 23e3336 + 7741647 commit 0fd1f1c
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
"sourceType": "module",
"ecmaVersion": 9
},
"ignorePatterns": ["**/*.d.js"],
"rules": {
"quote-props": "warn"
},
"globals": {
"fetch": false,
"Deno": false
}
}
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ sudo: false

language: node_js

services:
- docker

node_js:
- lts/*

Expand All @@ -11,6 +14,7 @@ install:
script:
- npm run lint
- npm test
- npm run test-deno
- npm run coverage
- npm run bundle

Expand Down
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
# 3.3.0(2020-04-25)

## Added

### Deno support

- [#36] https://github.com/circa10a/easy-soap-request/issues/36)

# 3.2.2(2020-04-08)

## Updated

Update dependencies

# 3.2.1 (2020-03-13)

## Fixed
## Fixed

- [#32] (https://github.com/circa10a/easy-soap-request/pull/32)

# 3.2.0 (2019-10-19)

## Fixed
## Fixed

- [#29] (https://github.com/circa10a/easy-soap-request/issues/29)

Expand Down
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

[![NPM](https://nodei.co/npm/easy-soap-request.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/easy-soap-request)

A small library to make SOAP requests easier via Node.js or in the browser
A small library to make SOAP requests easier via Node.js, Deno, and your browser

## Installation

Expand All @@ -37,7 +37,7 @@ const sampleHeaders = {
'Content-Type': 'text/xml;charset=UTF-8',
'soapAction': 'https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListZipCode',
};
const xml = fs.readFileSync('test/zipCodeEnvelope.xml', 'utf-8');
const xml = fs.readFileSync('test/zip-code-envelope.xml', 'utf-8');

// usage of module
(async () => {
Expand All @@ -49,6 +49,31 @@ const xml = fs.readFileSync('test/zipCodeEnvelope.xml', 'utf-8');
})();
```

### Deno

```js
import soapRequest from 'https://raw.githubusercontent.com/circa10a/easy-soap-request/master/index.d.js';
import { readFileStr } from 'https://deno.land/std/fs/mod.ts';

// 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
(async () => {
const xml = await readFileStr('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);
})();
```

### Browser

> Note: CORS policies apply
Expand Down
50 changes: 50 additions & 0 deletions index.d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Deno module for easy-soap-request
* @author Caleb Lemoine
* @param {object} opts easy-soap-request options
* @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 = {
url: '',
headers: {},
xml: '',
extraOpts: {},
}) {
const {
url,
headers,
xml,
extraOpts,
} = opts;
return new Promise((resolve, reject) => {
fetch(url, {
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) {
console.error(`SOAP FAIL: ${error}`);
reject(await error.response.text());
} else {
console.error(`SOAP FAIL: ${error}`);
reject(error);
}
});
});
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"bundle": "webpack --config ./webpack.config.js",
"clean": "rm -rf node_modules/",
"coverage": "export NODE_ENV=test; nyc report --reporter=text-lcov | coveralls",
"lint": "eslint '*.js' 'test/*.js'",
"lint-fix": "eslint **/*.js --fix",
"lint": "eslint .",
"lint-fix": "eslint . --fix",
"serve": "npm run bundle && webpack-dev-server --config ./webpack.config.js",
"test": "nyc mocha"
"test": "nyc mocha **/*test.js",
"test-deno": "docker run --rm -it -v $PWD:/tmp -w /tmp hayd/alpine-deno test --allow-read --allow-net test/*.d.js"
},
"repository": {
"type": "git",
Expand Down
57 changes: 57 additions & 0 deletions test/retrieve-lng-lat-test.d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { readFileStr } from 'https://deno.land/std/fs/mod.ts';
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts';
import soapRequest from '../index.d.js';


const url = 'https://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php';
const urlFail = 'https://graphical.weather.gov:80/xml/SOAP_server/ndfdXMLserver.php';
const headers = {
'user-agent': 'easy-soap-request-test',
'Content-Type': 'text/xml;charset=UTF-8',
SOAPAction: 'https://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#LatLonListZipCode',
};

const coordinates = '32.9612,-96.8372';

Deno.test({
name: `Zip Code 75001 should return ${coordinates}`,
fn: async () => {
const xml = await readFileStr('test/zip-code-envelope.xml');
const { response } = await soapRequest({ url, headers, xml });
const { body, statusCode } = response;
assertEquals(body.includes(coordinates), true);
assertEquals(statusCode, 200);
},
});

Deno.test({
name: 'Should catch Promise Rejection',
fn: async () => {
try {
const xmlFail = await readFileStr('test/zip-code-envelope-fail.xml');
const { response } = await soapRequest({ url, headers, xmlFail });
const { statusCode } = response;
assertEquals(statusCode, 200);
} catch (e) {
// Test promise rejection for coverage
}
},
});

Deno.test({
name: 'Should catch connection error Promise Rejection',
fn: async () => {
try {
const xmlFail = await readFileStr('test/zip-code-envelope-fail.xml');
const { response } = await soapRequest({
url: urlFail,
headers,
xml: xmlFail,
});
const { statusCode } = response;
assertEquals(statusCode, 200);
} catch (e) {
// Test promise rejection for coverage
}
},
});

0 comments on commit 0fd1f1c

Please sign in to comment.