Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vies-vat

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vies-vat - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

152

lib/index.js
// VIES-VAT - bitinix@gmail.com
const https = require('https')
const https = require('https');
const euCountries = ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'EL', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'XI']
const euCountries = ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'EL', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'XI'];
module.exports = async function (json, callback) {
var res = await build(json)
var res = await build(json);
if (typeof callback === 'function') {
callback(res.error, res.viesInfo)
callback(res.error, res.viesInfo);
} else {
return res
return res;
}
}
};

@@ -19,34 +19,32 @@ async function build(json) {

if (!json) {
resolve({ error: 'vies Badly formed request - Check vatNumber & countryCode', viesInfo: false })
return
resolve({ error: 'vies Badly formed request - Check vatNumber & countryCode', viesInfo: false });
return;
}
if (!json.vatNumber ||
!json.countryCode) {
resolve({ error: 'vies Badly formed request - Check vatNumber & countryCode', viesInfo: false })
return
if (!json.vatNumber || !json.countryCode) {
resolve({ error: 'vies Badly formed request - Check vatNumber & countryCode', viesInfo: false });
return;
}
if (json.vatNumber.length == 0) {
resolve({ error: 'vies Badly formed request - vatNumber is empty', viesInfo: false })
return
resolve({ error: 'vies Badly formed request - vatNumber is empty', viesInfo: false });
return;
}
if (json.countryCode.length == 0) {
resolve({ error: 'vies Badly formed request - countryCode is empty ', viesInfo: false })
return
resolve({ error: 'vies Badly formed request - countryCode is empty ', viesInfo: false });
return;
}
if (!euCountries.includes(json.countryCode)) {
resolve({ error: 'vies Badly formed request - Not EU Country', viesInfo: false })
return
resolve({ error: 'vies Badly formed request - Not EU Country', viesInfo: false });
return;
}
var timeout = 30000
var timeout = 30000;
if (json.timeout) {
timeout = json.timeout
timeout = json.timeout;
}
var call = {}
var call = {};
call.xml = `

@@ -65,3 +63,3 @@ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"

</soap:Body>
</soap:Envelope>`
</soap:Envelope>`;

@@ -76,3 +74,3 @@ call.options = {

'Content-Type': 'text/xml; charset=utf-8',
'Accept': 'text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8',
Accept: 'text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding': 'none',

@@ -82,13 +80,13 @@ 'User-Agent': 'VIES-VAT',

'Content-Length': call.xml.length,
'Connection': 'close'
Connection: 'close'
}
};
if (json.debug) call.debug = true
if (json.debug) call.debug = true;
if (json.debug) console.log('vies debug - Request to VIES Starting')
if (json.debug) console.log('vies debug - Request to VIES Starting');
const response = await euCall(call)
const response = await euCall(call);
if (json.debug) console.log('vies debug - Request to VIES Completed')
if (json.debug) console.log('vies debug - Request to VIES Completed');

@@ -102,20 +100,20 @@ var output = {

address: false
}
};
if (response.error) {
output.error = 'vies call error - check common issues'
resolve({ error: output.error, viesInfo: output })
return
output.error = 'vies call error - check common issues';
resolve({ error: output.error, viesInfo: output });
return;
}
if (!response.body) {
output.error = 'vies call error - check common issues'
resolve({ error: output.error, viesInfo: output })
return
output.error = 'vies call error - check common issues';
resolve({ error: output.error, viesInfo: output });
return;
}
if (!response.body.includes('<ns2:valid>true</ns2:valid>')) {
if (call.debug) console.error(`vies debug - Error 2019 - ${error} `)
resolve({ error: false, viesInfo: output })
return
if (call.debug) console.error(`vies debug - Error 2019 - ${error} `);
resolve({ error: false, viesInfo: output });
return;
}

@@ -125,25 +123,22 @@

valid: true,
countryCode: await tag(response.body, 'countryCode'),
vatNumber: await tag(response.body, 'vatNumber'),
requestDate: await tag(response.body, 'requestDate'),
name: await tag(response.body, 'name'),
address: await tag(response.body, 'address'),
}
countryCode: await tag(response.body),
vatNumber: await tag(response.body),
requestDate: await tag(response.body),
name: await tag(response.body),
address: await tag(response.body)
};
resolve({ error: false, viesInfo: output })
return
})
resolve({ error: false, viesInfo: output });
return;
});
}
async function tag(str, tag) {
// Remove the tags - 26-01-23
async function tag(str) {
return new Promise((resolve) => {
try {
let fnd = new RegExp(`<ns2:${tag}>(.*?)<\/ns2:${tag}>`, 'ig')
let rpl = new RegExp(`<\/?${tag}>`, 'ig')
str.match(fnd).map(function (val) {
var selected = val.replace(rpl, '');
resolve(selected)
});
let regex = /(<([^>]+)>)/gi;
resolve(str.replace(regex, ''));
} catch (e) {
resolve(false)
resolve(false);
}

@@ -156,6 +151,5 @@ });

return new Promise((resolve) => {
var message = 'error'
resolve(str)
})
var message = 'error';
resolve(str);
});
}

@@ -166,3 +160,3 @@

try {
const req = https.request(call.options, res => {
const req = https.request(call.options, (res) => {
res.setEncoding('utf8');

@@ -175,33 +169,33 @@ var body = '';

res.on('end', function () {
body = JSON.stringify(body)
body = JSON.stringify(body);
if (res.statusCode != 200) {
if (call.debug) console.log(`vies debug - status:${res.statusCode} ${body} `)
resolve({ 'error': true, 'message': 'vies Error in call to EU', 'status': res.statusCode, body: false })
if (call.debug) console.log(`vies debug - status:${res.statusCode} ${body} `);
resolve({ error: true, message: 'vies Error in call to EU', status: res.statusCode, body: false });
} else {
if (call.debug) console.log(`vies debug - status:${res.statusCode} Successful call `)
resolve({ 'error': false, 'message': 'vies Successful Call to EU', 'status': res.statusCode, body: body })
if (call.debug) console.log(`vies debug - status:${res.statusCode} Successful call `);
resolve({ error: false, message: 'vies Successful Call to EU', status: res.statusCode, body: body });
}
});
})
});
req.on('error', error => {
if (call.debug) console.error(`vies debug - Error 2020 - ${error} `)
resolve({ 'error': true, message: 'vies call error - check common issues' })
req.on('error', (error) => {
if (call.debug) console.error(`vies debug - Error 2020 - ${error} `);
resolve({ error: true, message: 'vies call error - check common issues' });
req.abort();
})
});
req.on('timeout', () => {
if (call.debug) console.error(`vies debug - Error 2021 - Timeout`)
resolve({ 'error': true, message: 'VIES-VAT Timeout - check common issues' })
if (call.debug) console.error(`vies debug - Error 2021 - Timeout`);
resolve({ error: true, message: 'VIES-VAT Timeout - check common issues' });
req.abort();
});
req.write(call.xml)
req.end()
req.write(call.xml);
req.end();
} catch (error) {
if (call.debug) console.error(`vies debug - Catch Error 2023 - ${error} `)
resolve({ 'error': true, message: 'vies call error - check common issues' })
if (call.debug) console.error(`vies debug - Catch Error 2023 - ${error} `);
resolve({ error: true, message: 'vies call error - check common issues' });
req.abort();
}
})
}
});
}
{
"name": "vies-vat",
"version": "1.2.2",
"description": "A EU VAT Number validation via European Union VIES API including company information",
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bitinix/vies-vat.git"
},
"keywords": [
"VIES",
"VAT",
"VATEU",
"EU",
"NPM",
"Number",
"Tax",
"Validation",
"node.js"
],
"author": "Peter Bradbury ( bitinix )",
"license": "MIT",
"bugs": {
"url": "https://github.com/bitinix/vies-vat/issues"
},
"homepage": "https://github.com/bitinix/vies-vat#readme"
}
"name": "vies-vat",
"version": "1.2.3",
"description": "A EU VAT Number validation via European Union VIES API including company information",
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bitinix/vies-vat.git"
},
"keywords": [
"VIES",
"VAT",
"VATEU",
"EU",
"NPM",
"Number",
"Tax",
"Validation",
"node.js"
],
"author": "Peter Bradbury ( bitinix )",
"license": "MIT",
"bugs": {
"url": "https://github.com/bitinix/vies-vat/issues"
},
"homepage": "https://github.com/bitinix/vies-vat#readme"
}

@@ -0,4 +1,3 @@

# VIES-VAT - European VAT Number Validation
# VIES-VAT - European VAT Number Validation
<p dir='auto'>

@@ -12,11 +11,16 @@ <a href="https://bitinix.com"><img alt="VIES-VAT status Badge" src="https://img.shields.io/badge/build-passing-brightgreen" style="max-width: 100%;"></a>

## What is VIES-VAT ?
A lightweight quick and easy to use NPM package written in node.js A simple request with country code & VAT number ( timeout & debug optional ) will allow you to verify the validity of a VAT number issued by any European Union Member State via the VIES System. The returned response will show whether the VAT number is valid or not and any extra company information where available.
A lightweight quick and easy to use NPM package written in node.js A simple request with country code & VAT number ( timeout & debug optional ) will allow you to verify the validity of a VAT number issued by any European Union Member State via the VIES System. The returned
response will show whether the VAT number is valid or not and any extra company information where available.
## What is VIES ?
VIES (VAT Information Exchange System) is an electronic means of validating VAT-identification ( VATIN ) numbers of economic operators registered in the European Union for cross border transactions on goods or service.
## Integration Support
Contact the developer at bitinix@gmail.com
## Get started
```bash

@@ -27,6 +31,9 @@ npm install --save VIES-VAT

#### Valid CountryCodes
```bash
AT BE BG HR CY CZ DK EE FI FR DE EL HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE XI
```
#### Callback example
```javascript

@@ -36,30 +43,31 @@ var vies = require('VIES-VAT');

var viesOptions = {
"countryCode": "xx", // ie FR
"vatNumber": 'xxxxxx', // vat Number without country code
"timeout": 10000 // optional - default 30000 ( 30 seconds )
}
countryCode: 'xx', // ie FR
vatNumber: 'xxxxxx', // vat Number without country code
timeout: 10000 // optional - default 30000 ( 30 seconds )
};
vies(viesOptions, function (error, viesInfo) {
if (error) console.log('vies callback test - error ', error)
console.log('vies callback test ', viesInfo)
if (error) console.log('vies callback test - error ', error);
console.log('vies callback test ', viesInfo);
});
```
```
#### async/await example
```javascript
var vies = require('VIES-VAT');
awaitTest()
awaitTest();
async function awaitTest() {
var viesOptions = {
"countryCode": "xx", // ie FR
"vatNumber": 'xxxxxx', // vat Number without country code
"timeout": 10000 // optional - default 30000 ( 30 seconds )
}
countryCode: 'xx', // ie FR
vatNumber: 'xxxxxx', // vat Number without country code
timeout: 10000 // optional - default 30000 ( 30 seconds )
};
var res = await vies(viesOptions)
if (res.error) console.log('vies sync test - error ', res.error)
var res = await vies(viesOptions);
if (res.error) console.log('vies sync test - error ', res.error);
console.log('vies sync test Result ', res.viesInfo)
console.log('vies sync test Result ', res.viesInfo);
}

@@ -69,2 +77,3 @@ ```

##### Valid Response
```javascript

@@ -75,3 +84,3 @@ {

vatNumber: 'xxxxxxx',
requestDate: '2021-12-08+01:00',
requestDate: '2022-12-08+01:00',
name: 'Company Name', // if available

@@ -81,3 +90,5 @@ address: 'Company Address' // if available

```
##### Invalid Response
```javascript

@@ -88,3 +99,3 @@ {

vatNumber: 'xxxxxxxxxx',
requestDate: '2021-12-08+01:00',
requestDate: '2022-12-08+01:00',
name: false,

@@ -95,66 +106,65 @@ address: false,

```
##### Error Messages
```javascript
'vies Badly formed request - Check vatNumber & countryCode'
'vies Badly formed request - vatNumber is empty'
'vies Badly formed request - countryCode is empty'
'vies Badly formed request - Not EU Country'
'vies vies call error'
'vies Timeout'
'vies Badly formed request - Check vatNumber & countryCode';
'vies Badly formed request - vatNumber is empty';
'vies Badly formed request - countryCode is empty';
'vies Badly formed request - Not EU Country';
'vies vies call error';
'vies Timeout';
```
##### Debug
Add the Debug key to your options<br />
This will give more details of the call including errors<br />
Add the Debug key to your options<br /> This will give more details of the call including errors<br />
```javascript
debugTest()
debugTest();
async function debugTest() {
var viesOptions = {
"countryCode": "xx", // ie FR
"vatNumber": 'xxxxxx', // vat Number without country code
"timeout": 60000, // optional - default 30000 ( 30 seconds )
"debug": true // optional - default false
}
var res = await vies(viesOptions)
if (res.error) console.log('vies debug test - error ', res.error)
console.log('vies debug test Result ', res.viesInfo)
var viesOptions = {
countryCode: 'xx', // ie FR
vatNumber: 'xxxxxx', // vat Number without country code
timeout: 60000, // optional - default 30000 ( 30 seconds )
debug: true // optional - default false
};
var res = await vies(viesOptions);
if (res.error) console.log('vies debug test - error ', res.error);
console.log('vies debug test Result ', res.viesInfo);
}
```
## Common Issues
### Receive Error when testing a valid VAT Number
This could be an internet connection issue or dns lookup<br />
Check that you can ping 'ec.europa.eu' from your server<br />
Add the following entry to your host file:-<br />
147.67.34.30 ec.europa.eu<br />
<br />
This could be an internet connection issue or dns lookup<br /> Check that you can ping 'ec.europa.eu' from your server<br /> Add the following entry to your host file:-<br /> 147.67.34.30 ec.europa.eu<br /> <br />
## Change Log
### 1.2.3
Fix Parsing Issue<br />
### 1.2.2
Apply EU Updates<br />
### 1.2.1
Make for public use on GITHUB<br />
## License
The MIT License (MIT)
Copyright (c) 2022 bitinix@gmail.com<br />
Copyright (c) 2023 bitinix@gmail.com<br />
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc