Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

external-ip

Package Overview
Dependencies
49
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

2

lib/cli.js

@@ -6,2 +6,3 @@ #!/usr/bin/env node

const extIP = require('./extIP');
const version = require('../package.json').version;

@@ -14,2 +15,3 @@ const collect = (service, services) => {

program
.version(version)
.option('-R, --replace', 'replace internal services instead of extending them.')

@@ -16,0 +18,0 @@ .option('-s, --services <url>', 'service url, see examples, required if using -R', collect, [])

15

lib/extIP.js

@@ -7,2 +7,3 @@ 'use strict';

// validate the external configuration
const isValid = utils.validateConfig(externalConfig);

@@ -15,5 +16,9 @@

// merge the external configuration with the default
const config = utils.mergeConfig(externalConfig, defaultConfig);
// create a request instance for each service in the configuration
const requests = config.services.map((url) => utils.requestFactory(config, url));
// sequential and parallel mode handlers
const getIP = {

@@ -29,4 +34,5 @@ sequential: (cb) => {

current += 1;
// when every single service has failed tell the bad news
if (current === requests.length) {
return cb(errors, null);
return cb(utils.concatErrors(errors), null);
}

@@ -55,3 +61,3 @@ return loop();

const onResponse = function (err, ip) {
const onResponse = (err, ip) => {

@@ -70,5 +76,3 @@ if (done) {

if (errors.length === requests.length) {
done = true;
abort(ongoingRequests); //async
return cb(errors, null);
return cb(utils.concatErrors(errors), null);
}

@@ -82,3 +86,4 @@ };

// return the sequential or the parallel handler according to the configuration
return getIP[config.getIP];
};

@@ -65,7 +65,7 @@ 'use strict';

if (error) {
return cb(new Error(JSON.stringify({ code: error.code, url })), null);
return cb(new Error(`${error.code} from ${url}`), null);
}
// Parse and validate the body
body = body.toString().replace('\n', '');
return cb.apply(null, isIP(body) ? [null, body] : [new Error(JSON.stringify({ code: 'invalid IP', url })), null]);
return cb.apply(null, isIP(body) ? [null, body] : [new Error(`Got invalid IP from ${url}`), null]);
});

@@ -75,2 +75,12 @@ };

const concatErrors = (errors) => {
if (errors.length === 1) {
return errors[0];
}
let msg = errors.reduce((acc, current) => {
return acc + ` ${current.message} \n`;
}, 'Multiple errors: \n');
return new Error(msg);
};
module.exports = {

@@ -81,2 +91,3 @@ isIP,

requestFactory,
concatErrors
};
{
"name": "external-ip",
"version": "1.0.0",
"version": "1.0.1",
"description": "A node.js library to get your external ip from multiple services",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,7 +6,7 @@ 'use strict';

// Integration test
var extIP = require('../index');
var utils = require('../lib/utils');
var expect = require('chai').expect;
const extIP = require('../index');
const utils = require('../lib/utils');
const expect = require('chai').expect;
var timeout = 3000;
const timeout = 3000;

@@ -17,3 +17,3 @@

this.timeout(timeout);
var getIP = extIP();
let getIP = extIP();
getIP(function (err, ip) {

@@ -29,3 +29,3 @@ expect(err).to.equal(null);

var getIP = extIP({
let getIP = extIP({
replace: true, // true: replace the default services list, false: extend it, default: false

@@ -32,0 +32,0 @@ services: ['http://ident.me/', 'http://icanhazip.com/'],

@@ -5,4 +5,4 @@ 'use strict';

var utils = require('../lib/utils');
var expect = require('chai').expect;
const utils = require('../lib/utils');
const expect = require('chai').expect;

@@ -27,3 +27,3 @@

it('should allow valid config', function () {
var config = {
const config = {
a: {

@@ -55,3 +55,3 @@ replace: false,

var config = {
const config = {
a: {

@@ -79,3 +79,3 @@ replace: 'batman',

var config = {
const config = {
default: {

@@ -99,3 +99,3 @@ replace: false,

var merged = utils.mergeConfig(config.a, config.default);
let merged = utils.mergeConfig(config.a, config.default);
expect(merged).to.have.property('timeout', 500);

@@ -102,0 +102,0 @@ expect(merged).to.have.property('services').with.lengthOf(2);

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

//'http://ip.appspot.com/',
//'http://ifconfig.co/x-real-ip',
//'http://ifconfig.io/ip',
'http://ip.appspot.com/',
'http://ifconfig.co/x-real-ip',
'http://ifconfig.io/ip',
'http://whatismyip.akamai.com/',

@@ -5,0 +5,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc