Coder Social home page Coder Social logo

ipinfo / node Goto Github PK

View Code? Open in Web Editor NEW
154.0 17.0 31.0 443 KB

Official Node client library for IPinfo API (IP geolocation and other types of IP data)

Home Page: https://ipinfo.io

License: Apache License 2.0

TypeScript 97.82% JavaScript 1.20% Shell 0.98%
ipinfo ip-geolocation ip-address ip-data nodejs

node's People

Contributors

abdullahdevrel avatar abu-usama avatar awaismslm avatar coderholic avatar deltwalrus avatar diegorbaquero avatar elsowiny avatar m1ke avatar masif-dev avatar nelson-chinedu avatar rm-umar avatar ryan6416 avatar shoaib-ashfaq avatar shubhamjain avatar sobanmahmood avatar st-polina avatar umanshahzad avatar ykhedher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node's Issues

Set Timeout

Hi.
I don't know if this is the right place to ask, sorry if it isn't.
Is it possible to implement a timeout? I realized that it takes 20 seconds to cancel the operation, it is too long.

Unexpected token < in JSON at position 1

Hi, we've seen this exception fire a few times now over the past months and it's unfortunately not getting handled and crashing our server ๐Ÿ˜ข .

We think a simple try/catch around the JSON.parse in IpinfoWrapper.ts:91 would do the trick. See callstack below. Let me know if you need anything else from us.

message: Unexpected token < in JSON at position 1
stack:
SyntaxError: Unexpected token < in JSON at position 1
    at JSON.parse (<anonymous>)
    at IncomingMessage.<anonymous> (/var/app/current/programs/server/npm/node_modules/node-ipinfo/dist/src/ipinfoWrapper.js:91:43)
    at IncomingMessage.emit (events.js:400:28)
    at IncomingMessage.emit (domain.js:475:12)
    at TLSSocket.socketCloseListener (_http_client.js:441:11)
    at TLSSocket.emit (events.js:412:35)
    at TLSSocket.emit (domain.js:475:12)
    at net.js:686:12
    at TCP.done (_tls_wrap.js:564:7)

Add optional IP selection handler

Add an optional IP selection handler to the SDK client initialization step which accepts the request context and expects returning an IP.

Add a default handler for this which looks at the X-Forwarded-For header and falls back to the source IP.

The resulting IP is the IP for which details are fetched.

TypeError: IPinfoWrapper is not a constructor when building a SvelteKit app

My SvelteKit app works fine in dev mode.

However when i attempt to build, i get TypeError: IPinfoWrapper is not a constructor. My code looks like this:

import IPinfoWrapper from 'node-ipinfo';
import { IPINFO_TOKEN } from "$env/static/private";

const ipinfoWrapper = new IPinfoWrapper(IPINFO_TOKEN);

const IPinfos = await ipinfoWrapper.lookupIp(requestIP);

The full version in my wip is here if that helps: https://github.com/gtnbssn/lEmplacementExactDuCoeur/blob/main/src/routes/api/connect/%2Bserver.ts

I have found a very similar previous issue here: #44

It doesn't help though.

Is there a typescript setting I need to change maybe?

Map integration

Create a simple function that accepts an IP list (max 500k) and returns the JSON response from https://ipinfo.io/map.

Ensure support for node v10

We should always support the oldest supported LTS available. There is no info about whether we support Node v10 in package.json. Confirm support level and fix it if necessary.

getBatch doesn't report 403 response

Report

The getBatch function hides a 403 response from server.

For example, if the provided token is invalid the API returns a 403 error. However this is not passed through to the output of the getBatch function.

Note however that lookupIp does throw an error in this case.

How to reproduce

import { IPinfoWrapper } from "node-ipinfo"

const ipinfo = new IPinfoWrapper('malformed token')

await ipinfo.getBatch(['8.8.8.8']) //returns {}
await ipinfo.lookupIp('8.8.8.8') //throws error with the 403 error from the server

Expected behaviour

The getBatch function should give some indication that the call has failed (e.g. by throwing an error or including some error data in the returned response).

Actual behaviour

getBatch returns an empty map (i.e. {}).

Impact

Difficult to spot when the passed token value is malformed (because it just looks like the IPs could not be found).

IPinfo.Lrucache example throws constructor error.

I'm trying use example cache.
However I'm getting following error.

TypeError: IPinfo.LruCache is not a constructor
const IPinfo = require("node-ipinfo");

let cacheOptions = {
    max: 5000,
    maxAge: 24 * 1000 * 60 * 60,
};
let cache = new IPinfo.LruCache(cacheOptions);
let ipinfo = new IPinfo("myToken", cache);

Nodejs version: v14.16.0

process is not defined (using Angular 8)

Hi!
I'm trying to use this library on my Angular 8 (8.2.14) application, but I got this error in the Chrome console:

Captura de pantalla de 2020-04-03 11-48-12

Also I've tried import it using this import IPinfoWrapper from 'node-ipinfo/dist/src/ipinfoWrapper';, without success.

How to solve this?
Thanks :)

Lru cache types are causing an error in tsc compile, Including third party type dev dependencies as dependencies should fix

node_modules/node-ipinfo/dist/src/cache/lruCache.d.ts:1:25 - error TS7016: Could not find a declaration file for module 'lru-cache'. 'C:/Users/elsow/Documents/Projs/adminAuth/node_modules/lru-cache/index.js' implicitly has an 'any' type.
Try npm i --save-dev @types/lru-cache if it exists or add a new declaration (.d.ts) file containing declare module 'lru-cache';

1 import { Options } from "lru-cache";

fixed this by npm i --save-dev @types/lru-cache for my overall application, but I know some other packages include third party types as dependencies to avoid this error

Lru cache types are causing an error in tsc compile

Compilation Errors:

"Could not find a declaration file for module 'lru-cache'."

Try npm i --save-dev @types/lru-cache if it exists or add a new declaration (.d.ts) file containing declare module 'lru-cache';

5 export { Options } from "lru-cache";

Even after I install @types/lru-cache I get the same error

Inline all data files

We have several files like eu.json, countries.json, continents.json and so on, which are loaded during initialization / startup of the client.

Instead of loading these as such, which has risks such as the asset not appearing in a production environment properly, and has a performance penalty during init of loading an on-disk file, we should inline the files into a static, in-memory map / dictionary or similar.

Use Fetch API instead of node's http(s) package

To enable compatibility with non-Node environments (e.g. Cloudflare Workers), it would be nice if this library can switch to using the Fetch API instead of node's http/https packages.

I had a glance at the code and I don't think there's anything within that requires usage of http or https.

Consider plain javascript+jsdoc & simplifying dependencies

This project is too small and simple to warrant the huge amount of tooling involved in it; it's only slowing down development and adding so many dependencies.

Consider converting the type info to good JSDoc comments and generating type files for TypeScript going forward. We can likely also remove almost all dependencies except the LRU cache.

This is not urgent and can be done as time permits.

Upgrade axios dependency to 0.21.1 to avoid Server-side request forgery

I ran npm audit today and a dependency of node-ipinfo has a vulnerability:

$ npm audit
                                                                                
                       === npm audit security report ===                        
                                                                                
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                Manual Review                                 โ”‚
โ”‚            Some vulnerabilities require your attention to resolve            โ”‚
โ”‚                                                                              โ”‚
โ”‚         Visit https://go.npm.me/audit-guide for additional guidance          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ High          โ”‚ Server-Side Request Forgery                                  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Package       โ”‚ axios                                                        โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Patched in    โ”‚ >=0.21.1                                                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Dependency of โ”‚ node-ipinfo                                                  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Path          โ”‚ node-ipinfo > axios                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ More info     โ”‚ https://npmjs.com/advisories/1594                            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
found 1 high severity vulnerability in 447 scanned packages

It seems that upgrading an indirect package is complicated (see StackOverflow thread), so the easiest would be to change the version in package.json, I think.

Use versioned cache key

Make sure the cache key contains a number to indicate the version of the cached data. Data changes that change what's expected in cached data require a version change.

I can't import IPinfoWrapper. IPinfoWrapper is undefined

First of all I wanted to say that I just created a new project in nest.js so i am using typescript instead of javascript.

I ran npm install node-ipinfo

And then I created a service that returns the city via IP:

import IPinfoWrapper from 'node-ipinfo';
import { Injectable } from '@nestjs/common';

@Injectable()
export default class IpInfoProvider {
  getCity(): string {
    console.log(IPinfoWrapper);
    const ipinfoWrapper = new IPinfoWrapper('token');
    return 'city-name-test';
  }
}

As you can see, I'm logging the IPinfoWrapper imported class, but I'm getting undefined, this means that when instantiating I get the following error: TypeError: node_ipinfo_1.default is not a constructor

The only way I'm able to instantiate the IPinfoWrapper is to go to the node_modules/node-ipinfo/index.js file and change the return

return m.default;

from: return m.default;
to return m;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.