diff --git a/packages/nocap/adapters/default/EveryAdapterDefault/package.json b/packages/nocap/adapters/default/EveryAdapterDefault/package.json index 1ca7e92c..5afca048 100644 --- a/packages/nocap/adapters/default/EveryAdapterDefault/package.json +++ b/packages/nocap/adapters/default/EveryAdapterDefault/package.json @@ -1,12 +1,12 @@ { "name": "@nostrwatch/nocap-every-adapter-default", - "version": "1.2.1", + "version": "1.2.2", "type": "module", "main": "index.js", "license": "MIT", "dependencies": { "@nostrwatch/nocap-dns-adapter-default": "^1.0.2", - "@nostrwatch/nocap-geo-adapter-default": "^1.0.2", + "@nostrwatch/nocap-geo-adapter-default": "^1.0.3", "@nostrwatch/nocap-info-adapter-default": "^1.0.1", "@nostrwatch/nocap-ssl-adapter-default": "^1.0.1", "@nostrwatch/nocap-websocket-adapter-default": "^1.2.0" diff --git a/packages/nocap/adapters/default/GeoAdapterDefault/index.js b/packages/nocap/adapters/default/GeoAdapterDefault/index.js index f6ad30c4..2703952b 100644 --- a/packages/nocap/adapters/default/GeoAdapterDefault/index.js +++ b/packages/nocap/adapters/default/GeoAdapterDefault/index.js @@ -5,11 +5,23 @@ import { fetch } from 'cross-fetch' this.$ = parent } + isNodeEnvironment() { + return typeof global !== 'undefined' && global?.process?.versions?.node; + } + + getApiKey() { + if (this.isNodeEnvironment()) { + return process.env.IP_API_KEY ? process.env.IP_API_KEY : this.$.config.adapterOptions.geo.apiKey; + } else { + return this.$.config.adapterOptions.geo.apiKey; + } + } + async check_geo(){ let endpoint const iparr = this.$.results.get('dns')?.data.ipv4 const ip = iparr[iparr.length-1] - const apiKey = typeof process !== 'undefined' && process?.env?.IP_API_KEY? process.env.IP_API_KEY: this.$.config.adapterOptions.geo.apiKey + const apiKey = this.getApiKey(); //todo, enable override via options const fields = 'proxy,mobile,timezone,continent,continentCode,country,countryCode,region,regionName,city,district,zip,lat,lon,isp,as,asname,query' if(typeof ip !== 'string') diff --git a/packages/nocap/adapters/default/GeoAdapterDefault/package.json b/packages/nocap/adapters/default/GeoAdapterDefault/package.json index 1f0c92a0..301d9d35 100644 --- a/packages/nocap/adapters/default/GeoAdapterDefault/package.json +++ b/packages/nocap/adapters/default/GeoAdapterDefault/package.json @@ -1,6 +1,6 @@ { "name": "@nostrwatch/nocap-geo-adapter-default", - "version": "1.0.2", + "version": "1.0.3", "type": "module", "main": "index.js", "license": "MIT", diff --git a/packages/nocap/package.json b/packages/nocap/package.json index 3537d8c8..ae1ccd57 100644 --- a/packages/nocap/package.json +++ b/packages/nocap/package.json @@ -1,6 +1,6 @@ { "name": "@nostrwatch/nocap", - "version": "0.4.6", + "version": "0.4.7", "main": "src/index.js", "type": "module", "license": "MIT", @@ -10,7 +10,7 @@ }, "dependencies": { "@nostrwatch/logger": "^0.0.5", - "@nostrwatch/nocap-every-adapter-default": "^1.2.1", + "@nostrwatch/nocap-every-adapter-default": "^1.2.2", "@nostrwatch/utils": "^0.0.3", "fetch-h2": "3.0.2", "get-ssl-certificate": "2.3.3",