google-geolocation
Advanced tools
Comparing version 2.0.0 to 2.1.3
22
index.js
@@ -9,5 +9,3 @@ /* | ||
const { doRequest } = require ('httpreq'); | ||
/** | ||
@@ -23,23 +21,25 @@ * Perform geolocation request | ||
module.exports = async ({ | ||
module.exports = async ( { | ||
key, | ||
timeout = 5000, | ||
}) => { | ||
} ) => { | ||
delete arguments[0].key; | ||
delete arguments[0].timeout; | ||
const url = `https://www.googleapis.com/geolocation/v1/geolocate?key=${key}`; | ||
const options = { | ||
method: 'POST', | ||
url: `https://www.googleapis.com/geolocation/v1/geolocate?key=${key}`, | ||
json: arguments[0], | ||
timeout, | ||
body: JSON.stringify( arguments[0] ), | ||
signal: AbortSignal.timeout( timeout ), | ||
}; | ||
const res = await doRequest (options); | ||
const data = JSON.parse (res.body); | ||
const res = await fetch( url, options ); | ||
const data = await res.json(); | ||
if (data.error) { | ||
const error = new Error (data.error.message); | ||
if ( data.error ) { | ||
const error = new Error( data.error.message ); | ||
error.code = data.error.code; | ||
error.reason = error.code; | ||
error.errors = data.error.errors; | ||
@@ -46,0 +46,0 @@ |
@@ -9,3 +9,3 @@ { | ||
"description": "Google Maps Geolocation API for Node.js (unofficial)", | ||
"version": "2.0.0", | ||
"version": "2.1.3", | ||
"repository": { | ||
@@ -19,11 +19,13 @@ "type": "git", | ||
"main": "index.js", | ||
"dependencies": { | ||
"httpreq": "^0.5.1" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"dotest": "^2.9.0" | ||
"dotest": "^2" | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=18" | ||
}, | ||
"files": [ | ||
"example.js" | ||
], | ||
"runkitExampleFilename": "example.js", | ||
"keywords": [ | ||
@@ -30,0 +32,0 @@ "accesspoints", |
@@ -7,3 +7,3 @@ # google-geolocation | ||
[![npm](https://img.shields.io/npm/v/google-geolocation.svg?maxAge=3600)](https://github.com/fvdm/nodejs-geolocation/blob/master/CHANGELOG.md) | ||
[![npm](https://img.shields.io/npm/v/google-geolocation.svg?maxAge=3600)](https://www.npmjs.com/package/google-geolocation) | ||
[![Build Status](https://github.com/fvdm/nodejs-geolocation/actions/workflows/node.js.yml/badge.svg?branch=master)](https://github.com/fvdm/nodejs-geolocation/actions/workflows/node.js.yml) | ||
@@ -13,2 +13,3 @@ [![Coverage Status](https://coveralls.io/repos/github/fvdm/nodejs-geolocation/badge.svg?branch=master)](https://coveralls.io/github/fvdm/nodejs-geolocation?branch=master) | ||
* [API documentation](https://developers.google.com/maps/documentation/geolocation/intro) | ||
* [Release notes](https://github.com/fvdm/nodejs-geolocation/releases) | ||
@@ -19,13 +20,13 @@ | ||
```js | ||
const geo = require ('google-geolocation'); | ||
const geo = require( 'google-geolocation' ); | ||
function out (obj) { | ||
console.dir (obj, { | ||
function out( obj ) { | ||
console.dir( obj, { | ||
depth: null, | ||
colors: true, | ||
}); | ||
} ); | ||
} | ||
// Get data | ||
geo ({ | ||
geo( { | ||
key: 'abc123', | ||
@@ -37,8 +38,5 @@ wifiAccessPoints: [{ | ||
}], | ||
}) | ||
.then (out) | ||
.catch (err => { | ||
out (err); | ||
process.exit (1); | ||
}) | ||
} ) | ||
.then( out ) | ||
.catch( out ) | ||
; | ||
@@ -59,2 +57,3 @@ ``` | ||
[timeout] | number | `5000` | Request timeout in ms | ||
... | mixed | | API parameters | ||
@@ -65,8 +64,8 @@ | ||
```js | ||
const geo = require ('google-geolocation'); | ||
const geo = require( 'google-geolocation' ); | ||
geo ({ | ||
geo( { | ||
key: 'abc123', | ||
timeout: 2000, | ||
}); | ||
} ); | ||
``` | ||
@@ -73,0 +72,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
0
0
6630
5
64
100
- Removedhttpreq@^0.5.1
- Removedhttpreq@0.5.2(transitive)