Socket
Socket
Sign inDemoInstall

mapbox

Package Overview
Dependencies
Maintainers
3
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mapbox - npm Package Compare versions

Comparing version 0.6.2 to 0.7.0

lib/callbackify.js

179

API.md

@@ -9,4 +9,2 @@ ## `MapboxClient`

* `options` **`Object`** additional options provided for configuration
* `options.endpoint` **`[string]`** location of the Mapbox API pointed-to. This can be customized to point to a Mapbox Atlas Server instance, or a different service, a mock, or a staging endpoint. Usually you don't need to customize this. (optional, default `https://api.mapbox.com`)
* `options.account` **`[string]`** account id to use for api requests. If not is specified, the account defaults to the owner of the provided accessToken.

@@ -21,2 +19,3 @@

| type | description |

@@ -38,4 +37,2 @@ | ---- | ----------- |

* `update` **`object`** an object describing features in insert and/or delete
* `update.put` **`[Array<object>]`** features to insert. Each feature must be a valid GeoJSON feature per http://geojson.org/geojson-spec.html#feature-objects
* `update.delete` **`[Array<string>]`** ids of features to delete
* `dataset` **`string`** the id for an existing dataset

@@ -48,5 +45,7 @@ * `callback` **`Function`** called with (err, results)

```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
var MapboxClient = require('mapbox');
var client = new MapboxClient('ACCESSTOKEN');
var inserts = [
{
"id": "1",
"type": "Feature",

@@ -62,2 +61,3 @@ "properties": {

{
"id": "2",
"type": "Feature",

@@ -77,3 +77,3 @@ "properties": {

];
mapboxClient.bulkFeatureUpdate({ put: inserts, delete: deletes }, dataset, function(err, results) {
client.bulkFeatureUpdate({ put: inserts, delete: deletes }, dataset, function(err, results) {
console.log(results);

@@ -115,2 +115,3 @@ // {

## `createDataset`

@@ -124,4 +125,2 @@

* `options` **`[object]`** an object defining a dataset's properties
* `options.name` **`[string]`** the dataset's name
* `options.description` **`[string]`** the dataset's description
* `callback` **`Function`** called with (err, dataset)

@@ -133,4 +132,5 @@

```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.createDataset({ name: 'foo', description: 'bar' }, function(err, dataset) {
var MapboxClient = require('mapbox');
var client = new MapboxClient('ACCESSTOKEN');
client.createDataset({ name: 'foo', description: 'bar' }, function(err, dataset) {
console.log(dataset);

@@ -150,2 +150,3 @@ // {

## `createUpload`

@@ -160,4 +161,2 @@

* `options` **`Object`** an object that defines the upload's properties
* `options.tileset` **`String`** id of the tileset to create or replace. This must consist of an account id and a unique key separated by a period. Reuse of a tileset value will overwrite existing data. To avoid overwriting existing data, you must ensure that you are using unique tileset ids.
* `options.url` **`String`** https url of a file staged on Amazon S3.
* `callback` **`Function`** called with (err, upload)

@@ -199,2 +198,3 @@

## `createUploadCredentials`

@@ -247,2 +247,3 @@

## `deleteDataset`

@@ -262,4 +263,5 @@

```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.deleteDataset('dataset-id', function(err) {
var MapboxClient = require('mapbox');
var client = new MapboxClient('ACCESSTOKEN');
client.deleteDataset('dataset-id', function(err) {
if (!err) console.log('deleted!');

@@ -271,2 +273,3 @@ });

## `deleteFeature`

@@ -287,4 +290,5 @@

```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.deleteFeature('feature-id', 'dataset-id', function(err, feature) {
var MapboxClient = require('mapbox');
var client = new MapboxClient('ACCESSTOKEN');
client.deleteFeature('feature-id', 'dataset-id', function(err, feature) {
if (!err) console.log('deleted!');

@@ -296,2 +300,3 @@ });

## `deleteUpload`

@@ -318,2 +323,3 @@

## `geocodeForward`

@@ -328,4 +334,2 @@

* `options` **`[Object]`** additional options meant to tune the request (optional, default `{}`)
* `options.proximity` **`Object`** a proximity argument: this is a geographical point given as an object with latitude and longitude properties. Search results closer to this point will be given higher priority.
* `options.dataset` **`[string]`** the desired data to be geocoded against. The default, mapbox.places, does not permit unlimited caching. `mapbox.places-permanent` is available on request and does permit permanent caching. (optional, default `mapbox.places`)
* `callback` **`Function`** called with (err, results)

@@ -351,2 +355,3 @@

## `geocodeReverse`

@@ -360,6 +365,3 @@

* `location` **`Object`** the geographical point to search
* `location.latitude` **`number`** decimal degrees latitude, in range -90 to 90
* `location.longitude` **`number`** decimal degrees longitude, in range -180 to 180
* `options` **`[Object]`** additional options meant to tune the request (optional, default `{}`)
* `options.dataset` **`[string]`** the desired data to be geocoded against. The default, mapbox.places, does not permit unlimited caching. `mapbox.places-permanent` is available on request and does permit permanent caching. (optional, default `mapbox.places`)
* `callback` **`Function`** called with (err, results)

@@ -381,2 +383,3 @@

## `getDirections`

@@ -392,6 +395,2 @@

* `options` **`[Object]`** additional options meant to tune the request (optional, default `{}`)
* `options.profile` **`[string]`** the directions profile, which determines how to prioritize different routes. Options are `'mapbox.driving'`, which assumes transportation via an automobile and will use highways, `'mapbox.walking'`, which avoids streets without sidewalks, and `'mapbox.cycling'`, which prefers streets with bicycle lanes and lower speed limits for transportation via bicycle. (optional, default `mapbox.driving`)
* `options.alternatives` **`[string]`** whether to generate alternative routes along with the preferred route. (optional, default `true`)
* `options.instructions` **`[string]`** format for turn-by-turn instructions along the route. (optional, default `text`)
* `options.geometry` **`[string]`** format for the returned route. Options are `'geojson'`, `'polyline'`, or `false`: `polyline` yields more compact responses which can be decoded on the client side. [GeoJSON](http://geojson.org/), the default, is compatible with libraries like [Mapbox GL](https://www.mapbox.com/mapbox-gl/), Leaflet and [Mapbox.js](https://www.mapbox.com/mapbox.js/). `false` omits the geometry entirely and only returns instructions. (optional, default `geojson`)
* `callback` **`Function`** called with (err, results)

@@ -428,2 +427,79 @@

## `getTilestats`
To retrieve statistics about a specific tileset.
### Parameters
* `tileset` **`String`** the id for the tileset
* `callback` **`Function`** called with (err, tilestats)
### Examples
```js
var client = new MapboxClient('ACCESSTOKEN');
client.getTilestats('tileset-id', function(err, info) {
console.log(info);
// {
// "account": {account},
// "tilesetid": "tileset-id",
// "layers": [
// {
// "account": {account},
// "tilesetid": "tileset-id",
// "layer": {layername},
// "count": 10,
// "attributes": [
// {attributename},
// {attributename},
// ]
// }
// ]
// }
});
```
Returns nothing, calls callback
## `getTilestatsAttribute`
To retrieve statistics about the attribute values of a particular attribute
within a tileset layer.
### Parameters
* `tileset` **`String`** the id for the tileset
* `layer` **`String`** the name of the layer in the tileset
* `attribute` **`String`** the name of the attribute in the layer
* `callback` **`Function`** called with (err)
### Examples
```js
var client = new MapboxClient('ACCESSTOKEN');
client.getTilestatsAttribute('tileset-id', 'layer-name', 'attr-name', function(err, info) {
console.log(info);
// {
// "account": {account},
// "tilesetid": "tileset-id",
// "layer": "layer-name",
// "attribute": "attr-name",
// "type": "Number",
// "min": 0,
// "max": 10,
// "values": [
// 0,
// 10
// ]
// }
});
```
Returns nothing, calls callback
## `insertFeature`

@@ -453,3 +529,4 @@

// Insert a brand new feature without an id
var mapboxClient = new MapboxClient('ACCESSTOKEN');
var MapboxClient = require('mapbox');
var client = new MapboxClient('ACCESSTOKEN');
var feature = {

@@ -465,3 +542,3 @@ "type": "Feature",

};
mapboxClient.insertFeature(feature, 'dataset-id', function(err, feature) {
client.insertFeature(feature, 'dataset-id', function(err, feature) {
console.log(feature);

@@ -483,3 +560,4 @@ // {

// Insert a brand new feature with an id, or overwrite an existing feature at that id
var mapboxClient = new MapboxClient('ACCESSTOKEN');
var MapboxClient = require('mapbox');
var client = new MapboxClient('ACCESSTOKEN');
var feature = {

@@ -496,3 +574,3 @@ "id": "feature-id",

};
mapboxClient.insertFeature(feature, 'dataset-id', function(err, feature) {
client.insertFeature(feature, 'dataset-id', function(err, feature) {
console.log(feature);

@@ -515,2 +593,3 @@ // {

## `listDatasets`

@@ -529,4 +608,5 @@

```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.listDatasets(function(err, datasets) {
var MapboxClient = require('mapbox');
var client = new MapboxClient('ACCESSTOKEN');
client.listDatasets(function(err, datasets) {
console.log(datasets);

@@ -556,2 +636,3 @@ // [

## `listFeatures`

@@ -571,4 +652,5 @@

```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.listFeatures('dataset-id', function(err, collection) {
var MapboxClient = require('mapbox');
var client = new MapboxClient('ACCESSTOKEN');
client.listFeatures('dataset-id', function(err, collection) {
console.log(collection);

@@ -597,2 +679,3 @@ {

## `listUploads`

@@ -642,2 +725,3 @@

## `matching`

@@ -653,5 +737,2 @@

* `options` **`[Object]`** additional options meant to tune the request (optional, default `{}`)
* `options.profile` **`[string]`** the directions profile, which determines how to prioritize different routes. Options are `'mapbox.driving'`, which assumes transportation via an automobile and will use highways, `'mapbox.walking'`, which avoids streets without sidewalks, and `'mapbox.cycling'`, which prefers streets with bicycle lanes and lower speed limits for transportation via bicycle. (optional, default `mapbox.driving`)
* `options.geometry` **`[string]`** format for the returned route. Options are `'geojson'`, `'polyline'`, or `false`: `polyline` yields more compact responses which can be decoded on the client side. [GeoJSON](http://geojson.org/), the default, is compatible with libraries like [Mapbox GL](https://www.mapbox.com/mapbox-gl/), Leaflet and [Mapbox.js](https://www.mapbox.com/mapbox.js/). `false` omits the geometry entirely and only returns matched points. (optional, default `geojson`)
* `options.gps_precision` **`[number]`** An integer in meters indicating the assumed precision of the used tracking device. Use higher numbers (5-10) for noisy traces and lower numbers (1-3) for clean traces. The default value is 4. (optional, default `4`)
* `callback` **`Function`** called with (err, results)

@@ -693,2 +774,3 @@

## `readDataset`

@@ -708,4 +790,5 @@

```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.readDataset('dataset-id', function(err, dataset) {
var MapboxClient = require('mapbox');
var client = new MapboxClient('ACCESSTOKEN');
client.readDataset('dataset-id', function(err, dataset) {
console.log(dataset);

@@ -725,2 +808,3 @@ // {

## `readFeature`

@@ -741,4 +825,5 @@

```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.readFeature('feature-id', 'dataset-id', function(err, feature) {
var MapboxClient = require('mapbox');
var client = new MapboxClient('ACCESSTOKEN');
client.readFeature('feature-id', 'dataset-id', function(err, feature) {
console.log(feature);

@@ -761,2 +846,3 @@ // {

## `readUpload`

@@ -795,2 +881,3 @@

## `surface`

@@ -812,5 +899,2 @@

* `options` **`[Object]`** additional options meant to tune the request (optional, default `{}`)
* `options.geojson` **`[string]`** whether to return data as a GeoJSON point (optional, default `false`)
* `options.zoom` **`[string]`** zoom level at which features are queried (optional, default `maximum`)
* `options.interpolate` **`[boolean]`** Whether to interpolate between matches in the feature collection. (optional, default `true`)
* `callback` **`Function`** called with (err, results)

@@ -827,2 +911,3 @@

## `updateDataset`

@@ -837,4 +922,2 @@

* `options` **`[object]`** an object defining updates to the dataset's properties
* `options.name` **`[string]`** the updated dataset's name
* `options.description` **`[string]`** the updated dataset's description
* `callback` **`Function`** called with (err, dataset)

@@ -846,5 +929,6 @@

```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
var MapboxClient = require('mapbox');
var client = new MapboxClient('ACCESSTOKEN');
var options = { name: 'foo' };
mapboxClient.updateDataset('dataset-id', options, function(err, dataset) {
client.updateDataset('dataset-id', options, function(err, dataset) {
console.log(dataset);

@@ -864,1 +948,2 @@ // {

@@ -0,1 +1,6 @@

## 0.7.0
- Improved error handling
- Added support for Tileset statistics API (in preview)
## 0.6.2

@@ -2,0 +7,0 @@

'use strict';
var makeClient = require('./make_service');
var xtend = require('xtend/mutable');
var MapboxGeocoder = require('./services/geocoder');
var MapboxSurface = require('./services/surface');
var MapboxDirections = require('./services/directions');
var MapboxUploads = require('./services/uploads');
var MapboxMatching = require('./services/matching');
var MapboxDatasets = require('./services/datasets');
var rest = require('rest');
var callbackify = require('./callbackify');
/**
* The JavaScript API to Mapbox services
*
* @class
* @throws {Error} if accessToken is not provided
* @param {string} accessToken a private or public access token
* @param {Object} options additional options provided for configuration
* @param {string} [options.endpoint=https://api.mapbox.com] location
* of the Mapbox API pointed-to. This can be customized to point to a
* Mapbox Atlas Server instance, or a different service, a mock,
* or a staging endpoint. Usually you don't need to customize this.
* @param {string} [options.account] account id to use for api
* requests. If not is specified, the account defaults to the owner
* of the provided accessToken.
* @example
* var client = new MapboxClient('ACCESSTOKEN');
*/
var MapboxClient = makeClient('MapboxClient');
xtend(MapboxClient.prototype,
MapboxGeocoder.prototype,
MapboxSurface.prototype,
MapboxDirections.prototype,
MapboxMatching.prototype,
MapboxDatasets.prototype,
MapboxUploads.prototype);
module.exports = MapboxClient;
// rest.js client with MIME support
module.exports = function(config) {
return rest
.wrap(require('rest/interceptor/errorCode'))
.wrap(require('rest/interceptor/pathPrefix'), { prefix: config.endpoint })
.wrap(require('rest/interceptor/mime'), { mime: 'application/json' })
.wrap(require('rest/interceptor/defaultRequest'), {
params: { access_token: config.accessToken }
})
.wrap(require('rest/interceptor/template'))
.wrap(callbackify);
};

@@ -1,15 +0,19 @@

var compile = require('es6-template-strings/compile');
// We keep all of the constants that declare endpoints in one
// place, so that we could concievably update this for API layout
// revisions.
module.exports.DEFAULT_ENDPOINT = 'https://api.mapbox.com';
module.exports.API_GEOCODER_FORWARD = compile('${endpoint}/v4/geocode/${dataset}/${encodeURIComponent(forwardQuery)}.json?${query}');
module.exports.API_GEOCODER_REVERSE = compile('${endpoint}/v4/geocode/${dataset}/${location.longitude},${location.latitude}.json?${query}');
module.exports.API_DIRECTIONS = compile('${endpoint}/v4/directions/${profile}/${encodedWaypoints}.json?${query}');
module.exports.API_SURFACE = compile('${endpoint}/v4/surface/${mapid}.json?${query}');
module.exports.API_UPLOADS = compile('${endpoint}/uploads/v1/${owner}?${query}');
module.exports.API_UPLOAD = compile('${endpoint}/uploads/v1/${owner}/${upload}?${query}');
module.exports.API_UPLOAD_CREDENTIALS = compile('${endpoint}/uploads/v1/${owner}/credentials?${query}');
module.exports.API_MATCHING = compile('${endpoint}/matching/v4/${profile}.json?${query}');
module.exports.API_DATASET_DATASETS = compile('${endpoint}/datasets/v1/${owner}?${query}');
module.exports.API_DATASET_DATASET = compile('${endpoint}/datasets/v1/${owner}/${dataset}?${query}');
module.exports.API_DATASET_FEATURES = compile('${endpoint}/datasets/v1/${owner}/${dataset}/features?${query}');
module.exports.API_DATASET_FEATURE = compile('${endpoint}/datasets/v1/${owner}/${dataset}/features/${id}?${query}');
module.exports.API_GEOCODER_FORWARD = '/v4/geocode/{dataset}/{query}.json';
module.exports.API_GEOCODER_REVERSE = '/v4/geocode/{dataset}/{location.longitude},{location.latitude}.json';
module.exports.API_DIRECTIONS = '/v4/directions/{profile}/{encodedWaypoints}.json';
module.exports.API_SURFACE = '/v4/surface/{mapid}.json{?layer,fields,points,geojson,interpolate,encoded_polyline}';
module.exports.API_UPLOADS = '/uploads/v1/{owner}';
module.exports.API_UPLOAD = '/uploads/v1/{owner}/{upload}';
module.exports.API_UPLOAD_CREDENTIALS = '/uploads/v1/{owner}/credentials';
module.exports.API_MATCHING = '/matching/v4/{profile}.json';
module.exports.API_DATASET_DATASETS = '/datasets/v1/{owner}';
module.exports.API_DATASET_DATASET = '/datasets/v1/{owner}/{dataset}';
module.exports.API_DATASET_FEATURES = '/datasets/v1/{owner}/{dataset}/features';
module.exports.API_DATASET_FEATURE = '/datasets/v1/{owner}/{dataset}/features/{id}';
module.exports.API_TILESTATS_STATISTICS = '/tilestats/v1/{owner}/{tileset}';
module.exports.API_TILESTATS_LAYER = '/tilestats/v1/{owner}/{tileset}/{layer}';
module.exports.API_TILESTATS_ATTRIBUTE = '/tilestats/v1/{owner}/{tileset}/{layer}/{attribute}';

@@ -5,2 +5,12 @@ 'use strict';

/**
* Format waypionts in a way that's friendly to the directions and surface
* API: comma-separated latitude, longitude pairs with semicolons between
* them.
* @private
* @param {Array<Object>} waypoints array of objects with latitude and longitude
* properties
* @returns {string} formatted points
* @throws {Error} if the input is invalid
*/
function formatPoints(waypoints) {

@@ -7,0 +17,0 @@ return waypoints.map(function(location) {

'use strict';
/**
* Access tokens actually are data, and using them we can derive
* a user's username. This method attempts to do just that,
* decoding the part of the token after the first `.` into
* a username.
*
* @private
* @param {string} token an access token
* @return {string} username
*/
function getUser(token) {

@@ -4,0 +14,0 @@ var data = token.split('.')[1];

@@ -5,4 +5,16 @@ 'use strict';

var constants = require('./constants');
var client = require('./client');
var getUser = require('./get_user');
/**
* Services all have the same constructor pattern: you initialize them
* with an access token and options, and they validate those arguments
* in a predictable way. This is a constructor-generator that makes
* it possible to require each service's API individually.
*
* @private
* @param {string} name the name of the Mapbox API this class will access:
* this is set to the name of the function so it will show up in tracebacks
* @returns {Function} constructor function
*/
function makeService(name) {

@@ -16,4 +28,3 @@

this.accessToken = accessToken;
this.endpoint = constants.DEFAULT_ENDPOINT;
var endpoint = constants.DEFAULT_ENDPOINT;

@@ -24,3 +35,3 @@ if (options !== undefined) {

invariant(typeof options.endpoint === 'string', 'endpoint must be a string');
this.endpoint = options.endpoint;
endpoint = options.endpoint;
}

@@ -33,2 +44,7 @@ if (options.account) {

this.client = client({
endpoint: endpoint,
accessToken: accessToken
});
this.owner = this.owner || getUser(accessToken);

@@ -35,0 +51,0 @@ invariant(!!this.owner, 'could not determine account from provided accessToken');

@@ -5,7 +5,5 @@ 'use strict';

geojsonhint = require('geojsonhint/object'),
request = require('superagent'),
hat = require('hat'),
makeService = require('../make_service'),
constants = require('../constants'),
makeURL = require('../make_url');
constants = require('../constants');

@@ -21,4 +19,5 @@ var Datasets = module.exports = makeService('MapboxDatasets');

* @example
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* mapboxClient.listDatasets(function(err, datasets) {
* var MapboxClient = require('mapbox');
* var client = new MapboxClient('ACCESSTOKEN');
* client.listDatasets(function(err, datasets) {
* console.log(datasets);

@@ -48,6 +47,8 @@ * // [

var url = makeURL(this, constants.API_DATASET_DATASETS, { owner: this.owner });
request(url, function(err, res) {
callback(err, res.body);
this.client({
path: constants.API_DATASET_DATASETS,
params: {
owner: this.owner
},
callback: callback
});

@@ -66,4 +67,5 @@ };

* @example
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* mapboxClient.createDataset({ name: 'foo', description: 'bar' }, function(err, dataset) {
* var MapboxClient = require('mapbox');
* var client = new MapboxClient('ACCESSTOKEN');
* client.createDataset({ name: 'foo', description: 'bar' }, function(err, dataset) {
* console.log(dataset);

@@ -90,10 +92,10 @@ * // {

var url = makeURL(this, constants.API_DATASET_DATASETS, { owner: this.owner });
request
.post(url)
.send(options)
.end(function(err, res) {
callback(err, res.body);
});
this.client({
path: constants.API_DATASET_DATASETS,
params: {
owner: this.owner
},
entity: options,
callback: callback
});
};

@@ -109,4 +111,5 @@

* @example
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* mapboxClient.readDataset('dataset-id', function(err, dataset) {
* var MapboxClient = require('mapbox');
* var client = new MapboxClient('ACCESSTOKEN');
* client.readDataset('dataset-id', function(err, dataset) {
* console.log(dataset);

@@ -127,10 +130,10 @@ * // {

var url = makeURL(this, constants.API_DATASET_DATASET, {
owner: this.owner,
dataset: dataset
this.client({
path: constants.API_DATASET_DATASET,
params: {
owner: this.owner,
dataset: dataset
},
callback: callback
});
request(url, function(err, res) {
callback(err, res.body);
});
};

@@ -149,5 +152,6 @@

* @example
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* var MapboxClient = require('mapbox');
* var client = new MapboxClient('ACCESSTOKEN');
* var options = { name: 'foo' };
* mapboxClient.updateDataset('dataset-id', options, function(err, dataset) {
* client.updateDataset('dataset-id', options, function(err, dataset) {
* console.log(dataset);

@@ -170,13 +174,12 @@ * // {

var url = makeURL(this, constants.API_DATASET_DATASET, {
owner: this.owner,
dataset: dataset
this.client({
path: constants.API_DATASET_DATASET,
params: {
owner: this.owner,
dataset: dataset
},
method: 'patch',
entity: options,
callback: callback
});
request
.patch(url)
.send(options)
.end(function(err, res) {
callback(err, res.body);
});
};

@@ -192,4 +195,5 @@

* @example
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* mapboxClient.deleteDataset('dataset-id', function(err) {
* var MapboxClient = require('mapbox');
* var client = new MapboxClient('ACCESSTOKEN');
* client.deleteDataset('dataset-id', function(err) {
* if (!err) console.log('deleted!');

@@ -202,12 +206,11 @@ * });

var url = makeURL(this, constants.API_DATASET_DATASET, {
owner: this.owner,
dataset: dataset
this.client({
path: constants.API_DATASET_DATASET,
params: {
owner: this.owner,
dataset: dataset
},
method: 'delete',
callback: callback
});
request
.del(url)
.end(function(err) {
callback(err);
});
};

@@ -223,4 +226,5 @@

* @example
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* mapboxClient.listFeatures('dataset-id', function(err, collection) {
* var MapboxClient = require('mapbox');
* var client = new MapboxClient('ACCESSTOKEN');
* client.listFeatures('dataset-id', function(err, collection) {
* console.log(collection);

@@ -250,10 +254,10 @@ * {

var url = makeURL(this, constants.API_DATASET_FEATURES, {
owner: this.owner,
dataset: dataset
this.client({
path: constants.API_DATASET_FEATURES,
params: {
owner: this.owner,
dataset: dataset
},
callback: callback
});
request(url, function(err, res) {
callback(err, res.body);
});
};

@@ -279,3 +283,4 @@

* // Insert a brand new feature without an id
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* var MapboxClient = require('mapbox');
* var client = new MapboxClient('ACCESSTOKEN');
* var feature = {

@@ -291,3 +296,3 @@ * "type": "Feature",

* };
* mapboxClient.insertFeature(feature, 'dataset-id', function(err, feature) {
* client.insertFeature(feature, 'dataset-id', function(err, feature) {
* console.log(feature);

@@ -308,3 +313,4 @@ * // {

* // Insert a brand new feature with an id, or overwrite an existing feature at that id
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* var MapboxClient = require('mapbox');
* var client = new MapboxClient('ACCESSTOKEN');
* var feature = {

@@ -321,3 +327,3 @@ * "id": "feature-id",

* };
* mapboxClient.insertFeature(feature, 'dataset-id', function(err, feature) {
* client.insertFeature(feature, 'dataset-id', function(err, feature) {
* console.log(feature);

@@ -345,14 +351,13 @@ * // {

var url = makeURL(this, constants.API_DATASET_FEATURE, {
owner: this.owner,
dataset: dataset,
id: id
this.client({
path: constants.API_DATASET_FEATURE,
params: {
owner: this.owner,
dataset: dataset,
id: id
},
method: 'put',
entity: feature,
callback: callback
});
request
.put(url)
.send(feature)
.end(function(err, res) {
callback(err, res.body);
});
};

@@ -369,4 +374,5 @@

* @example
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* mapboxClient.readFeature('feature-id', 'dataset-id', function(err, feature) {
* var MapboxClient = require('mapbox');
* var client = new MapboxClient('ACCESSTOKEN');
* client.readFeature('feature-id', 'dataset-id', function(err, feature) {
* console.log(feature);

@@ -391,11 +397,11 @@ * // {

var url = makeURL(this, constants.API_DATASET_FEATURE, {
owner: this.owner,
dataset: dataset,
id: id
this.client({
path: constants.API_DATASET_FEATURE,
params: {
owner: this.owner,
dataset: dataset,
id: id
},
callback: callback
});
request(url, function(err, res) {
callback(err, res.body);
});
};

@@ -412,4 +418,5 @@

* @example
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* mapboxClient.deleteFeature('feature-id', 'dataset-id', function(err, feature) {
* var MapboxClient = require('mapbox');
* var client = new MapboxClient('ACCESSTOKEN');
* client.deleteFeature('feature-id', 'dataset-id', function(err, feature) {
* if (!err) console.log('deleted!');

@@ -423,13 +430,12 @@ * });

var url = makeURL(this, constants.API_DATASET_FEATURE, {
owner: this.owner,
dataset: dataset,
id: id
this.client({
path: constants.API_DATASET_FEATURE,
params: {
owner: this.owner,
dataset: dataset,
id: id
},
method: 'delete',
callback: callback
});
request
.del(url)
.end(function(err, res) {
callback(err, res.body);
});
};

@@ -453,5 +459,7 @@

* @example
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* var MapboxClient = require('mapbox');
* var client = new MapboxClient('ACCESSTOKEN');
* var inserts = [
* {
* "id": "1",
* "type": "Feature",

@@ -467,2 +475,3 @@ * "properties": {

* {
* "id": "2",
* "type": "Feature",

@@ -482,3 +491,3 @@ * "properties": {

* ];
* mapboxClient.bulkFeatureUpdate({ put: inserts, delete: deletes }, dataset, function(err, results) {
* client.bulkFeatureUpdate({ put: inserts, delete: deletes }, dataset, function(err, results) {
* console.log(results);

@@ -539,13 +548,12 @@ * // {

var url = makeURL(this, constants.API_DATASET_FEATURES, {
owner: this.owner,
dataset: dataset
this.client({
path: constants.API_DATASET_FEATURES,
params: {
owner: this.owner,
dataset: dataset
},
method: 'post',
entity: { put: inserts, delete: deletes },
callback: callback
});
request
.post(url)
.send({ put: inserts, delete: deletes })
.end(function(err, res) {
callback(err, res.body);
});
};
'use strict';
var invariant = require('invariant'),
request = require('superagent'),
formatPoints = require('../format_points'),
makeService = require('../make_service'),
makeURL = require('../make_url'),
constants = require('../constants');

@@ -101,16 +99,15 @@

var url = makeURL(this, constants.API_DIRECTIONS, {
encodedWaypoints: encodedWaypoints,
profile: profile
}, {
instructions: instructions,
geometry: geometry,
alternatives: alternatives
this.client({
path: constants.API_DIRECTIONS,
params: {
encodedWaypoints: encodedWaypoints,
profile: profile,
instructions: instructions,
geometry: geometry,
alternatives: alternatives
},
callback: callback
});
request(url, function(err, res) {
callback(err, res.body);
});
};
module.exports = MapboxDirections;
'use strict';
var invariant = require('invariant'),
request = require('superagent'),
makeService = require('../make_service'),
makeURL = require('../make_url'),
constants = require('../constants');

@@ -54,3 +52,7 @@

var queryOptions = {};
var queryOptions = {
query: query,
dataset: 'mapbox.places'
};
if (options.proximity) {

@@ -63,15 +65,11 @@ invariant(typeof options.proximity.latitude === 'number' &&

var dataset = 'mapbox.places';
if (options.dataset) {
invariant(typeof options.dataset === 'string', 'dataset option must be string');
dataset = options.dataset;
queryOptions.dataset = options.dataset;
}
var url = makeURL(this, constants.API_GEOCODER_FORWARD, {
forwardQuery: query,
dataset: dataset
}, queryOptions);
request(url, function(err, res) {
callback(err, res.body);
this.client({
path: constants.API_GEOCODER_FORWARD,
params: queryOptions,
callback: callback
});

@@ -126,9 +124,9 @@ };

var url = makeURL(this, constants.API_GEOCODER_REVERSE, {
location: location,
dataset: dataset
}, {});
request(url, function(err, res) {
callback(err, res.body);
this.client({
path: constants.API_GEOCODER_REVERSE,
params: {
location: location,
dataset: dataset
},
callback: callback
});

@@ -135,0 +133,0 @@ };

'use strict';
var invariant = require('invariant'),
request = require('superagent'),
geojsonhint = require('geojsonhint/object'),
makeService = require('../make_service'),
makeURL = require('../make_url'),
constants = require('../constants');

@@ -103,16 +101,15 @@

var url = makeURL(this, constants.API_MATCHING, {
profile: profile
}, {
geometry: geometry,
gps_precision: gps_precision
this.client({
path: constants.API_MATCHING,
params: {
profile: profile,
geometry: geometry,
gps_precision: gps_precision
},
method: 'post',
entity: trace,
callback: callback
});
request.post(url)
.send(trace)
.end(function(err, res) {
callback(err, res.body);
});
};
module.exports = MapboxMatching;
'use strict';
var invariant = require('invariant'),
request = require('superagent'),
formatPoints = require('../format_points'),
makeService = require('../make_service'),
makeURL = require('../make_url'),
constants = require('../constants');

@@ -75,2 +73,3 @@

layer: layer,
mapid: mapid,
fields: fields.join(','),

@@ -91,8 +90,6 @@ interpolate: interpolate

var url = makeURL(this, constants.API_SURFACE, {
mapid: mapid
}, surfaceOptions);
request(url, function(err, res) {
callback(err, res.body);
this.client({
path: constants.API_SURFACE,
params: surfaceOptions,
callback: callback
});

@@ -99,0 +96,0 @@ };

'use strict';
var invariant = require('invariant'),
request = require('superagent'),
makeService = require('../make_service'),
constants = require('../constants'),
makeURL = require('../make_url');
constants = require('../constants');

@@ -49,6 +47,6 @@ var Uploads = module.exports = makeService('MapboxUploads');

var url = makeURL(this, constants.API_UPLOADS, { owner: this.owner });
request(url, function(err, res) {
callback(err, res.body);
this.client({
path: constants.API_UPLOADS,
params: { owner: this.owner },
callback: callback
});

@@ -98,9 +96,7 @@ };

var url = makeURL(this, constants.API_UPLOAD_CREDENTIALS, { owner: this.owner });
request
.get(url)
.end(function(err, res) {
callback(err, res.body);
});
this.client({
path: constants.API_UPLOAD_CREDENTIALS,
params: { owner: this.owner },
callback: callback
});
};

@@ -154,10 +150,8 @@

var url = makeURL(this, constants.API_UPLOADS, { owner: this.owner });
request
.post(url)
.send(options)
.end(function(err, res) {
callback(err, res.body);
});
this.client({
path: constants.API_UPLOADS,
params: { owner: this.owner },
entity: options,
callback: callback
});
};

@@ -193,10 +187,10 @@

var url = makeURL(this, constants.API_UPLOAD, {
owner: this.owner,
upload: upload
this.client({
path: constants.API_UPLOAD,
params: {
owner: this.owner,
upload: upload
},
callback: callback
});
request(url, function(err, res) {
callback(err, res.body);
});
};

@@ -220,12 +214,11 @@

var url = makeURL(this, constants.API_UPLOAD, {
owner: this.owner,
upload: upload
this.client({
method: 'delete',
path: constants.API_UPLOAD,
params: {
owner: this.owner,
upload: upload
},
callback: callback
});
request
.del(url)
.end(function(err) {
callback(err);
});
};
{
"name": "mapbox",
"version": "0.6.2",
"version": "0.7.0",
"description": "interface to mapbox services",
"main": "lib/client.js",
"main": "lib/mapbox.js",
"scripts": {
"lint": "eslint --no-eslintrc -c .eslintrc lib test/*.js",
"test": "tap --coverage test/*.js",
"test": "tap --coverage test/browser.js test/*.js",
"browser-test": "browserify -t envify -t brfs test/browser.js test/*.js | smokestack | tap-status",
"docs": "documentation . --format=md > API.md",
"build": "npm run build-dist && npm run build-min",
"build-dist": "browserify -s MapboxClient lib/client.js > dist/mapbox-sdk.js",
"build-dist": "browserify -s MapboxClient lib/mapbox.js > dist/mapbox-sdk.js",
"build-min": "uglifyjs -c -m < dist/mapbox-sdk.js > dist/mapbox-sdk.min.js"

@@ -32,13 +33,17 @@ },

"aws-sdk": "^2.1.41",
"brfs": "^1.4.1",
"browserify": "^11.0.0",
"documentation": "^2.1.0-alpha2",
"envify": "^3.4.0",
"eslint": "^0.24.1",
"geojson-random": "^0.2.2",
"geojsonhint": "^1.1.0",
"hat": "0.0.3",
"polyline": "^0.1.0",
"smokestack": "^3.3.0",
"tap": "^1.3.1",
"tap-status": "^1.0.1",
"uglifyjs": "^2.4.10"
},
"dependencies": {
"browser-process-hrtime": "^0.1.2",
"browser-stdout": "1.3.0",
"es6-template-strings": "^1.0.0",

@@ -48,5 +53,5 @@ "geojsonhint": "^1.0.1",

"invariant": "^2.1.0",
"superagent": "^1.2.0",
"rest": "^1.3.1",
"xtend": "^4.0.0"
}
}

@@ -119,5 +119,4 @@ /* eslint no-shadow: 0 */

assert.ok(client, 'created dataset client');
client.readDataset('peanuts', function(err, response) {
assert.equal(err.status, 422, 'expected HTTP error');
assert.equal(response.message, 'No dataset', 'expected message');
client.readDataset('peanuts', function(err /*, response */) {
assert.equal(err.message, 'No dataset', 'expected message');
assert.end();

@@ -233,5 +232,4 @@ });

assert.ok(client, 'created dataset client');
client.readFeature('club', testDatasets[0], function(err, response) {
assert.equal(err.status, 404, 'expected error code');
assert.equal(response.message, 'Feature does not exist', 'expected error message');
client.readFeature('club', testDatasets[0], function(err /*, response */) {
assert.equal(err.message, 'Feature does not exist', 'expected error message');
assert.end();

@@ -293,3 +291,3 @@ });

assert.ifError(err, 'success');
assert.deepEqual(response, {}, 'empty response');
assert.deepEqual(response, '', 'empty response');
assert.end();

@@ -302,5 +300,4 @@ });

assert.ok(client, 'created dataset client');
client.deleteFeature('blt', testDatasets[0], function(err, response) {
assert.equal(err.status, 404, 'expected error code');
assert.equal(response.message, 'Feature does not exist', 'expected error message');
client.deleteFeature('blt', testDatasets[0], function(err /*, response */) {
assert.equal(err.message, 'Feature does not exist', 'expected error message');
assert.end();

@@ -307,0 +304,0 @@ });

@@ -5,4 +5,2 @@ /* eslint no-shadow: 0 */

var test = require('tap').test,
// fs = require('fs'),
// path = require('path'),
geojsonhint = require('geojsonhint'),

@@ -9,0 +7,0 @@ MapboxClient = require('../lib/services/geocoder');

@@ -63,3 +63,5 @@ /* eslint no-shadow: 0 */

var service = new TestService(validToken, { endpoint: 'donuts' });
assert.equal(service.endpoint, 'donuts', 'success');
assert.ok(service);
// TODO endpoint is no longer exposed
// assert.equal(service.endpoint, 'donuts', 'success');
assert.end();

@@ -66,0 +68,0 @@ });

@@ -31,3 +31,4 @@ /* eslint no-shadow: 0 */

t.ok(client);
t.equal(client.accessToken, deadToken);
// TODO accessToken is no longer exposed
// t.equal(client.accessToken, deadToken);
t.end();

@@ -46,4 +47,5 @@ });

var customClient = new MapboxClient(deadToken, { endpoint: 'foo.bar' });
t.equal(customClient.endpoint, 'foo.bar', 'receives an endpoint from options');
// TODO endpoint is no longer exposed
// t.equal(customClient.endpoint, 'foo.bar', 'receives an endpoint from options');
t.end();
});

@@ -8,2 +8,3 @@ /* eslint no-shadow: 0 */

var hat = require('hat');
var path = require('path');
var fs = require('fs');

@@ -50,4 +51,4 @@

Key: credentials.key,
Body: fs.createReadStream(__dirname + '/fixtures/valid-onlytiles.mbtiles')
}, function(err, resp) {
Body: fs.readFileSync(path.join(__dirname, '/fixtures/valid-onlytiles.mbtiles'))
}, function(err /*, resp */) {
assert.ifError(err, 'success');

@@ -103,5 +104,4 @@ testStagedFiles.push(credentials);

tileset: 'blah'
}, function(err, upload) {
assert.equal(err.status, 422);
assert.equal(upload.message, 'Missing property "url"');
}, function(err /*, upload */) {
assert.equal(err.message, 'Missing property "url"');
assert.end();

@@ -143,3 +143,3 @@ });

poll();
});
}, { timeout: 10000 });

@@ -149,5 +149,4 @@ readUpload.test('does not exist', function(assert) {

assert.ok(client, 'created upload client');
client.readUpload('fakeo', function(err, upload) {
assert.equal(err.status, 404);
assert.equal(upload.message, 'Not Found');
client.readUpload('fakeo', function(err /*, upload */) {
assert.equal(err.message, 'Not Found');
assert.end();

@@ -176,3 +175,3 @@ });

assert.ok(client, 'created upload client');
client.listUploads(function(err, uploads) {
client.listUploads(function(err/*, uploads */) {
assert.ifError(err, 'success');

@@ -203,3 +202,3 @@ assert.end();

var upload = testUploads.shift();
client.deleteUpload(completedUpload.id, function(err, uploads) {
client.deleteUpload(completedUpload.id, function(err/*, uploads*/) {
assert.ifError(err, 'success');

@@ -206,0 +205,0 @@ assert.end();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc