ipinfo / node Goto Github PK
View Code? Open in Web Editor NEWOfficial Node client library for IPinfo API (IP geolocation and other types of IP data)
Home Page: https://ipinfo.io
License: Apache License 2.0
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
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.
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 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.
Building with typescript results in this error (looks to be introduced with the latest release):
error TS2307: Cannot find module 'node-ipinfo' or its corresponding type declarations.
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?
https://ipinfo.io/developers/batch
Take into account use cases like ipinfo/python#35 to ensure batch ops support is scalable & robust.
Create a simple function that accepts an IP list (max 500k) and returns the JSON response from https://ipinfo.io/map
.
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.
Errors
, Country Name Lookup
, Location Information
, etc are missing examples in the README. We should fill 'em up.
Add documentation & examples for these functions to the README.md file, and also add API-level documentation in the code itself.
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.
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
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).
getBatch
returns an empty map (i.e. {}
).
Difficult to spot when the passed token value is malformed (because it just looks like the IPs could not be found).
yarn add [email protected] works, adding the dist directory plus LICENSE, package.json, README.md
yarn add [email protected] omits the dist directory
When the last few remaining issues on this repo are closed, consider this library "released" on https://github.com/ipinfo/libraries/.
Implement SDK support for IP summaries.
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
For some reason the library is using a third party HTTP client. This is unnecessary as we can just use Node.js's native client without adding on another dependency for the user.
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
The api request is blocked by client
Getting this error when I check for a bogon
response: Property 'bogon' does not exist on type 'IPinfo'.ts(2339)
.
However bogon
is a valid response property according to your documentation. From https://ipinfo.io/developers/data-types#ip-type-data:
If the IP is an anycast or a bogon, the API returns a field indicating that.
Bogon Address Information
curl ipinfo.io/127.0.0.1?token=a3989e849337bf
{
"ip": "127.0.0.1",
"bogon": true
}
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
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.
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.
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.
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.
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.
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
Line 7 in 4496107
return m.default;
return m;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.