ipregistry/ipregistry-javascript

Access to remaining credits returns `null`

evdama opened this issue ยท 8 comments

I've about 800k credits in my ipregistry account but since a while now I noticed from the logs I'm always getting null in my response. That wasn't the case a few months back iirc because back then i got the remaining credits logged correctly and I could use if (request.session.IPRegistryAPI.response.credits.remaining >= 1) { do stuff if there's credits left} which now breaks...

Screen Shot 2020-10-02 at 21 44 45

Above is the log from my firebase SSR function running the below code

// this is the callToIPRegistryAPI function which is used below

import ipregistry from '@ipregistry/client'

export default async ( ipAddress, filters ) => {
  try {
    // cache 16384 client entries for 24 hours
    const client = new ipregistry.IpregistryClient( 'my ipr key here', new ipregistry.DefaultCache( 16384, 3600 * 24 * 1000 ) )
    return await client.lookup( ipAddress, ipregistry.IpregistryOptions.hostname( true ), ipregistry.IpregistryOptions.filter( filters ) )

  } catch ( error ) {

    console.error('๐Ÿ”ด IPRegistry error code: ' + error.code)
    console.error('๐Ÿ”ด IPRegistry error message: ' + error.message)
    console.error('๐Ÿ”ด IPRegistry error resolution: ' + error.resolution)

  }
}

which is then used and console.logged which in turn gives null as shown in the screenshot above.

        request.session.IPRegistryAPI.response = await callToIPRegistryAPI( request.session.clientIPAddress.ip, 'hostname,location[in_eu,country.name,country.flag.emoji,region.name],security[is_threat,is_anonymous,is_tor_exit,is_bogon]' )
        console.log('request.session.IPRegistryAPI.response is: ', request.session.IPRegistryAPI.response)

What could cause the return value of null even though there are 800k credits left? I can't see an issue with my code and also it worked in the past and nothing changed with my code since then ๐Ÿค”

@evdama Thanks for opening this issue. It seems you are using version 2.0.0 of the library.

We deprecated a response header about 6 months ago:
https://ipregistry.co/changelog#posts/new-api-response-header-and-query-option

This header was used by version 2.0.0 of the library to return the remaining number of credits.

The deprecation date of the header was August 14. Near the end of August, we removed this header from the Ipregistry responses. A new version of the library (3.0.0) that no longer makes use of the deprecated header is available since June. Unfortunately, the old version 2.0.0 is broken.

As a fix, I suggest upgrading to version 3.0.0. Here is the changelog:
https://github.com/ipregistry/ipregistry-javascript/blob/master/CHANGELOG.md

We will be more careful in the future.

Although I suggest upgrading to version 3.0.0, a hotfix has been published under version 2.0.1.

thanks for looking at the issue so fast...
I should have mentioned that the issue I'm having is with "@ipregistry/client": "^3.0.0" already so I've been using the most recent version since the time it was available.

@evdama I am able to reproduce the issue with version 2.0.0 only. Do you have a package-lock.json or yarn.lock file in your project? if that's the case, could you please check the version in the lock file?

That's the entire dependency tree from the my package-lock.json

    "@ipregistry/client": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/@ipregistry/client/-/client-3.0.0.tgz",
      "integrity": "sha512-DwYbGnE7+JdTCKYplEOrCmDq+SxXr2DXdhIpdgrY7g3z50eo3JRSlEgCwo93ieCn7WkVU2ZEYN+CtnSenyUhMg==",
      "dev": true,
      "requires": {
        "axios": "^0.19.2",
        "lru-cache": "^5.1.1"
      },
      "dependencies": {
        "axios": {
          "version": "0.19.2",
          "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
          "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
          "dev": true,
          "requires": {
            "follow-redirects": "1.5.10"
          }
        },
        "debug": {
          "version": "3.1.0",
          "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
          "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
          "dev": true,
          "requires": {
            "ms": "2.0.0"
          }
        },
        "follow-redirects": {
          "version": "1.5.10",
          "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
          "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
          "dev": true,
          "requires": {
            "debug": "=3.1.0"
          }
        },
        "lru-cache": {
          "version": "5.1.1",
          "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
          "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==",
          "dev": true,
          "requires": {
            "yallist": "^3.0.2"
          }
        },
        "yallist": {
          "version": "3.1.1",
          "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
          "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
          "dev": true
        }
      }
    },

Thanks for the information and my apologies. There was a packaging issue with the package published on npmjs. I have published a new version (3.0.1). Could you please give a try and let me know how it works for you?

Excellent, seems fixed as this code from my Sapper server.js

        request.session.IPRegistryAPI.response = await callToIPRegistryAPI( request.session.clientIPAddress.ip, 'hostname,location[in_eu,country.name,country.flag.emoji,region.name],security[is_threat,is_anonymous,is_tor_exit,is_bogon]' )
        console.log('๐ŸŸจ request.session.IPRegistryAPI.response.credits is: ', request.session.IPRegistryAPI.response.credits)
        console.log('๐ŸŸง request.session.IPRegistryAPI.response.data is: ', request.session.IPRegistryAPI.response.data)

now returns the proper remaining count and so I can use it to apply some logic based on the remaining counter

if (request.session.IPRegistryAPI.response.credits.remaining >= 1) { code to check if connections are categorized as is_threat, is_tor, is_bogon... and drop them if so sending return await response.status( 400 ).end()}

Screen Shot 2020-10-03 at 18 23 26

Great. Thanks for the update.