Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mapbox

Package Overview
Dependencies
Maintainers
43
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 1.0.0-beta to 1.0.0-beta1

CONTRIBUTING.md

6

CHANGELOG.md

@@ -0,1 +1,5 @@

## 1.0.0-beta1
* Add `bbox` option to geocoder API
## 1.0.0-beta

@@ -6,2 +10,4 @@

`mapbox/lib/services/geocoder`
- The `DatasetClient#bulkFeatureUpdate` method is renamed
`DatasetClient#batcFeatureUpdate` to match the rest of the Mapbox ecosystem.

@@ -8,0 +14,0 @@ ## 0.12.0

26

lib/constants.js

@@ -5,11 +5,17 @@ // We keep all of the constants that declare endpoints in one

module.exports.DEFAULT_ENDPOINT = 'https://api.mapbox.com';
module.exports.API_GEOCODING_FORWARD = '/geocoding/v5/{dataset}/{query}.json{?proximity,country,types}';
module.exports.API_GEOCODING_FORWARD = '/geocoding/v5/{dataset}/{query}.json{?proximity,country,types,bbox}';
module.exports.API_GEOCODING_REVERSE = '/geocoding/v5/{dataset}/{longitude},{latitude}.json{?types}';
module.exports.API_DIRECTIONS = '/v4/directions/{profile}/{encodedWaypoints}.json{?alternatives,instructions,geometry,steps}';
module.exports.API_DISTANCE = '/distances/v1/mapbox/{profile}';
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}';

@@ -19,5 +25,21 @@ module.exports.API_DATASET_DATASET = '/datasets/v1/{owner}/{dataset}';

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}';
module.exports.API_STATIC = '/v4/{mapid}{+overlay}/{+xyz}/{width}x{height}{+retina}{.format}';
module.exports.API_STATIC = '/v4/{mapid}{+overlay}/{+xyz}/{width}x{height}{+retina}{.format}{?api_token}';
module.exports.API_STYLES_LIST = '/styles/v1/{owner}';
module.exports.API_STYLES_CREATE = '/styles/v1/{owner}';
module.exports.API_STYLES_READ = '/styles/v1/{owner}/{styleid}';
module.exports.API_STYLES_UPDATE = '/styles/v1/{owner}/{styleid}';
module.exports.API_STYLES_DELETE = '/styles/v1/{owner}/{styleid}';
module.exports.API_STYLES_EMBED = '/styles/v1/{owner}/{styleid}.html{?zoomwheel,title,access_token}';
module.exports.API_STYLES_SPRITE = '/styles/v1/{owner}/{styleid}/sprite{+retina}{.format}';
module.exports.API_STYLES_SPRITE_ADD_ICON = '/styles/v1/{owner}/{styleid}/sprite/{iconName}';
module.exports.API_STYLES_SPRITE_DELETE_ICON = '/styles/v1/{owner}/{styleid}/sprite/{iconName}';
module.exports.API_STYLES_FONT_GLYPH_RANGES = '/fonts/v1/{owner}/{font}/{start}-{end}.pbf'
module.exports.API_STYLES_SPRITE_DELETE_ICON = '/styles/v1/{owner}/{styleid}/sprite/{iconName}';

15

lib/encode_overlay.js
'use strict';
var assert = require('assert'),
assertLocation = require('./assert_location'),
polyline = require('polyline'),
geojsonhint = require('geojsonhint/object');
var invariant = require('../vendor/invariant'),
invariantLocation = require('./invariant_location'),
polyline = require('../vendor/polyline');

@@ -16,3 +15,3 @@ /**

return markers.map(function(marker) {
assertLocation(marker);
invariantLocation(marker);
var size = marker.size || 'l';

@@ -36,4 +35,3 @@ var symbol = marker.symbol || 'circle';

function encodePath(path) {
assert(geojsonhint.hint(path.geojson).length === 0, 'path overlay must be valid GeoJSON');
assert.equal(path.geojson.type, 'LineString', 'path line must be a LineString');
invariant(path.geojson.type === 'LineString', 'path line must be a LineString');
var encoded = polyline.fromGeoJSON(path.geojson);

@@ -58,5 +56,4 @@

function encodeGeoJSON(geojson) {
assert(geojsonhint.hint(geojson).length === 0, 'overlay must be valid GeoJSON');
var encoded = encodeURIComponent(JSON.stringify(geojson));
assert(encoded.length < 4096, 'encoded GeoJSON must be shorter than 4096 characters long');
invariant(encoded.length < 4096, 'encoded GeoJSON must be shorter than 4096 characters long');
return 'geojson(' + encoded + ')';

@@ -63,0 +60,0 @@ }

'use strict';
var assertLocation = require('./assert_location');
var invariantLocation = require('./invariant_location');

@@ -17,3 +17,3 @@ /**

return waypoints.map(function(location) {
assertLocation(location);
invariantLocation(location);
return location.longitude + ',' + location.latitude;

@@ -20,0 +20,0 @@ }).join(';');

'use strict';
var atob = require('atob');
var b64 = require('rest/util/base64');

@@ -20,14 +20,9 @@ /**

// window.atob does not require padding
if (!process.browser) {
var mod = data.length % 4;
if (mod === 2) data += '==';
if (mod === 3) data += '=';
if (mod === 1 || mod > 3) return null;
} else {
data = data.replace(/=/g, '');
}
var mod = data.length % 4;
if (mod === 2) data += '==';
if (mod === 3) data += '=';
if (mod === 1 || mod > 3) return null;
try {
return JSON.parse(atob(data)).u;
return JSON.parse(b64.decode(data)).u;
} catch(err) {

@@ -34,0 +29,0 @@ return null;

'use strict';
var assert = require('assert');
var invariant = require('../vendor/invariant');
var constants = require('./constants');

@@ -24,3 +24,3 @@ var client = require('./client');

assert(typeof accessToken === 'string',
invariant(typeof accessToken === 'string',
'accessToken required to instantiate Mapbox client');

@@ -31,9 +31,9 @@

if (options !== undefined) {
assert(typeof options === 'object', 'options must be an object');
invariant(typeof options === 'object', 'options must be an object');
if (options.endpoint) {
assert(typeof options.endpoint === 'string', 'endpoint must be a string');
invariant(typeof options.endpoint === 'string', 'endpoint must be a string');
endpoint = options.endpoint;
}
if (options.account) {
assert(typeof options.account === 'string', 'account must be a string');
invariant(typeof options.account === 'string', 'account must be a string');
this.owner = options.account;

@@ -51,3 +51,3 @@ }

this.owner = this.owner || getUser(accessToken);
assert(!!this.owner, 'could not determine account from provided accessToken');
invariant(!!this.owner, 'could not determine account from provided accessToken');

@@ -54,0 +54,0 @@ }

'use strict';
var makeClient = require('./make_service');
var xtend = require('xtend/mutable');
var xtend = require('../vendor/xtend').extendMutable;
var getUser = require('./get_user');
var MapboxGeocoding = require('./services/geocoding');

@@ -47,2 +48,4 @@ var MapboxSurface = require('./services/surface');

MapboxClient.getUser = getUser;
module.exports = MapboxClient;
'use strict';
var assert = require('assert'),
geojsonhint = require('geojsonhint/object'),
hat = require('hat'),
var invariant = require('../../vendor/invariant'),
hat = require('../../vendor/hat'),
makeService = require('../make_service'),

@@ -43,5 +42,3 @@ constants = require('../constants');

Datasets.prototype.listDatasets = function(callback) {
assert(typeof callback === 'function', 'callback must be a function');
this.client({
return this.client({
path: constants.API_DATASET_DATASETS,

@@ -52,3 +49,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -87,6 +84,5 @@

assert(typeof options === 'object', 'options must be an object');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof options === 'object', 'options must be an object');
this.client({
return this.client({
path: constants.API_DATASET_DATASETS,

@@ -98,3 +94,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -125,6 +121,5 @@

Datasets.prototype.readDataset = function(dataset, callback) {
assert(typeof dataset === 'string', 'dataset must be a string');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof dataset === 'string', 'dataset must be a string');
this.client({
return this.client({
path: constants.API_DATASET_DATASET,

@@ -136,3 +131,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -167,8 +162,7 @@

Datasets.prototype.updateDataset = function(dataset, options, callback) {
assert(typeof dataset === 'string', 'dataset must be a string');
assert(typeof callback === 'function', 'callback must be a function');
assert(typeof options === 'object', 'options must be an object');
assert(!!options.name || !!options.description, 'options must include a name or a description');
invariant(typeof dataset === 'string', 'dataset must be a string');
invariant(typeof options === 'object', 'options must be an object');
invariant(!!options.name || !!options.description, 'options must include a name or a description');
this.client({
return this.client({
path: constants.API_DATASET_DATASET,

@@ -182,3 +176,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -201,6 +195,5 @@

Datasets.prototype.deleteDataset = function(dataset, callback) {
assert(typeof dataset === 'string', 'dataset must be a string');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof dataset === 'string', 'dataset must be a string');
this.client({
return this.client({
path: constants.API_DATASET_DATASET,

@@ -213,3 +206,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -259,5 +252,4 @@

assert(typeof dataset === 'string', 'dataset must be a string');
assert(typeof options === 'object', 'options must be a object');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof dataset === 'string', 'dataset must be a string');
invariant(typeof options === 'object', 'options must be a object');

@@ -270,3 +262,3 @@ var params = {

if (options.reverse) {
assert(typeof options.reverse === 'boolean', 'reverse option must be a boolean');
invariant(typeof options.reverse === 'boolean', 'reverse option must be a boolean');
params.reverse = options.reverse;

@@ -276,3 +268,3 @@ }

if (options.limit) {
assert(typeof options.limit === 'number', 'limit option must be a number');
invariant(typeof options.limit === 'number', 'limit option must be a number');
params.limit = options.limit;

@@ -282,11 +274,11 @@ }

if (options.start) {
assert(typeof options.start === 'string', 'start option must be a string');
invariant(typeof options.start === 'string', 'start option must be a string');
params.start = options.start;
}
this.client({
return this.client({
path: constants.API_DATASET_FEATURES,
params: params,
callback: callback
});
}).entity();
};

@@ -369,10 +361,8 @@

Datasets.prototype.insertFeature = function(feature, dataset, callback) {
assert(typeof dataset === 'string', 'dataset must be a string');
assert(typeof callback === 'function', 'callback must be a function');
assert(geojsonhint.hint(feature).length === 0, 'feature must be valid GeoJSON');
invariant(typeof dataset === 'string', 'dataset must be a string');
var id = feature.id || hat();
assert(typeof id === 'string', 'The GeoJSON feature\'s id must be a string');
invariant(typeof id === 'string', 'The GeoJSON feature\'s id must be a string');
this.client({
return this.client({
path: constants.API_DATASET_FEATURE,

@@ -387,3 +377,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -418,7 +408,6 @@

Datasets.prototype.readFeature = function(id, dataset, callback) {
assert(typeof id === 'string', 'id must be a string');
assert(typeof dataset === 'string', 'dataset must be a string');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof id === 'string', 'id must be a string');
invariant(typeof dataset === 'string', 'dataset must be a string');
this.client({
return this.client({
path: constants.API_DATASET_FEATURE,

@@ -431,3 +420,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -451,7 +440,6 @@

Datasets.prototype.deleteFeature = function(id, dataset, callback) {
assert(typeof id === 'string', 'id must be a string');
assert(typeof dataset === 'string', 'dataset must be a string');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof id === 'string', 'id must be a string');
invariant(typeof dataset === 'string', 'dataset must be a string');
this.client({
return this.client({
path: constants.API_DATASET_FEATURE,

@@ -465,3 +453,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -515,3 +503,3 @@

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

@@ -550,6 +538,5 @@ * // {

*/
Datasets.prototype.bulkFeatureUpdate = function(update, dataset, callback) {
assert(typeof update === 'object', 'update must be an object');
assert(typeof dataset === 'string', 'dataset must be a string');
assert(typeof callback === 'function', 'callback must be a function');
Datasets.prototype.batchFeatureUpdate = function(update, dataset, callback) {
invariant(typeof update === 'object', 'update must be an object');
invariant(typeof dataset === 'string', 'dataset must be a string');

@@ -559,7 +546,3 @@ var inserts = update.put || [];

assert(
geojsonhint.hint({type: 'FeatureCollection', features: inserts}).length === 0,
'update.put must be an array of valid GeoJSON features'
);
assert(
invariant(
inserts.every(function(feature) { return feature.id; }),

@@ -569,3 +552,3 @@ 'inserted GeoJSON features must include ids'

assert(
invariant(
deletes.every(function(id) { return typeof id === 'string'; }),

@@ -575,3 +558,3 @@ 'update.delete must be an array of strings'

this.client({
return this.client({
path: constants.API_DATASET_FEATURES,

@@ -585,3 +568,3 @@ params: {

callback: callback
});
}).entity();
};
'use strict';
var assert = require('assert'),
var invariant = require('../../vendor/invariant'),
formatPoints = require('../format_points'),

@@ -70,8 +70,9 @@ makeService = require('../make_service'),

options = {};
} else if (options === undefined) {
options = {};
}
// typecheck arguments
assert(Array.isArray(waypoints), 'waypoints must be an array');
assert(typeof options === 'object', 'options must be an object');
assert(typeof callback === 'function', 'callback must be a function');
invariant(Array.isArray(waypoints), 'waypoints must be an array');
invariant(typeof options === 'object', 'options must be an object');

@@ -87,3 +88,3 @@ var encodedWaypoints = formatPoints(waypoints);

if (options.profile) {
assert(typeof options.profile === 'string', 'profile option must be string');
invariant(typeof options.profile === 'string', 'profile option must be string');
profile = options.profile;

@@ -93,3 +94,3 @@ }

if (typeof options.alternatives !== 'undefined') {
assert(typeof options.alternatives === 'boolean', 'alternatives option must be boolean');
invariant(typeof options.alternatives === 'boolean', 'alternatives option must be boolean');
alternatives = options.alternatives;

@@ -99,3 +100,3 @@ }

if (typeof options.steps !== 'undefined') {
assert(typeof options.steps === 'boolean', 'steps option must be boolean');
invariant(typeof options.steps === 'boolean', 'steps option must be boolean');
steps = options.steps;

@@ -105,3 +106,3 @@ }

if (options.geometry) {
assert(typeof options.geometry === 'string', 'geometry option must be string');
invariant(typeof options.geometry === 'string', 'geometry option must be string');
geometry = options.geometry;

@@ -111,7 +112,7 @@ }

if (options.instructions) {
assert(typeof options.instructions === 'string', 'instructions option must be string');
invariant(typeof options.instructions === 'string', 'instructions option must be string');
instructions = options.instructions;
}
this.client({
return this.client({
path: constants.API_DIRECTIONS,

@@ -127,5 +128,5 @@ params: {

callback: callback
});
}).entity();
};
module.exports = MapboxDirections;
'use strict';
var assert = require('assert'),
var invariant = require('../../vendor/invariant'),
makeService = require('../make_service'),

@@ -70,3 +70,3 @@ constants = require('../constants');

// typecheck arguments
assert(Array.isArray(waypoints), 'waypoints must be an array');
invariant(Array.isArray(waypoints), 'waypoints must be an array');

@@ -76,7 +76,7 @@ var profile = 'driving';

if (options.profile) {
assert(typeof options.profile === 'string', 'profile option must be string');
invariant(typeof options.profile === 'string', 'profile option must be string');
profile = options.profile;
}
this.client({
return this.client({
path: constants.API_DISTANCE,

@@ -91,5 +91,5 @@ params: {

callback: callback
});
}).entity();
};
module.exports = MapboxDistance;
'use strict';
var assert = require('assert'),
var invariant = require('../../vendor/invariant'),
makeService = require('../make_service'),

@@ -19,5 +19,8 @@ constants = require('../constants');

* Search for a location with a string, using the
* [Mapbox Geocoding API](https://www.mapbox.com/developers/api/geocoding/).
* [Mapbox Geocoding API](https://www.mapbox.com/api-documentation/#geocoding).
*
* @param {string} query desired location
* The `query` parmeter can be an array of strings only if batch geocoding
* is used by specifying `mapbox.places-permanent` as the `dataset` option.
*
* @param {string|Array<string>} query desired location
* @param {Object} [options={}] additional options meant to tune

@@ -29,7 +32,13 @@ * the request

* higher priority.
* @param {Array} options.bbox a bounding box argument: this is
* a bounding box given as an array in the format [minX, minY, maxX, maxY].
* Search results will be limited to the bounding box.
* @param {string} options.types a comma seperated list of types that filter
* results to match those specified. See https://www.mapbox.com/developers/api/geocoding/#filter-type
* for available types.
* @param {string} options.country a comma seperated list of country codes to
* @param {string} options.country a comma separated list of country codes to
* limit results to specified country or countries.
* @param {boolean=true} options.autocomplete whether to include results that include
* the query only as a prefix. This is useful for UIs where users type
* values, but if you have complete addresses as input, you'll want to turn it off
* @param {string} [options.dataset=mapbox.places] the desired data to be

@@ -53,2 +62,8 @@ * geocoded against. The default, mapbox.places, does not permit unlimited

* });
* // using the bbox option to limit results to a portion of Washington, D.C.
* mapboxClient.geocodeForward('Starbucks', {
* bbox: [-77.083056,38.908611,-76.997778,38.959167]
* }, function(err, res) {
* // res is a GeoJSON document with geocoding matches
* });
*/

@@ -64,5 +79,11 @@ MapboxGeocoding.prototype.geocodeForward = function(query, options, callback) {

// typecheck arguments
assert(typeof query === 'string', 'query must be a string');
assert(typeof options === 'object', 'options must be an object');
assert(typeof callback === 'function', 'callback must be a function');
if (Array.isArray(query)) {
if (options.dataset !== 'mapbox.places-permanent') {
throw new Error('Batch geocoding is only available with the mapbox.places-permanent endpoint. See https://mapbox.com/api-documentation/#batch-requests for details')
} else {
query = query.join(';');
}
}
invariant(typeof query === 'string', 'query must be a string');
invariant(typeof options === 'object', 'options must be an object');

@@ -74,5 +95,6 @@ var queryOptions = {

var autocomplete = true;
var precision = FORWARD_GEOCODING_PROXIMITY_PRECISION;
if (options.precision) {
assert(typeof options.precision === 'number', 'precision option must be number');
invariant(typeof options.precision === 'number', 'precision option must be number');
precision = options.precision;

@@ -82,3 +104,3 @@ }

if (options.proximity) {
assert(typeof options.proximity.latitude === 'number' &&
invariant(typeof options.proximity.latitude === 'number' &&
typeof options.proximity.longitude === 'number',

@@ -89,4 +111,14 @@ 'proximity must be an object with numeric latitude & longitude properties');

if (options.bbox) {
invariant(typeof options.bbox[0] === 'number' &&
typeof options.bbox[1] === 'number' &&
typeof options.bbox[2] === 'number' &&
typeof options.bbox[3] === 'number' &&
options.bbox.length === 4,
'bbox must be an array with numeric values in the form [minX, minY, maxX, maxY]');
queryOptions.bbox = options.bbox[0] + "," + options.bbox[1] + "," + options.bbox[2] + "," + options.bbox[3];
}
if (options.dataset) {
assert(typeof options.dataset === 'string', 'dataset option must be string');
invariant(typeof options.dataset === 'string', 'dataset option must be string');
queryOptions.dataset = options.dataset;

@@ -96,3 +128,3 @@ }

if (options.country) {
assert(typeof options.country === 'string', 'country option must be string');
invariant(typeof options.country === 'string', 'country option must be string');
queryOptions.country = options.country;

@@ -102,11 +134,16 @@ }

if (options.types) {
assert(typeof options.types === 'string', 'types option must be string');
invariant(typeof options.types === 'string', 'types option must be string');
queryOptions.types = options.types;
}
this.client({
if (typeof options.autocomplete === 'boolean') {
invariant(typeof options.autocomplete === 'boolean', 'autocomplete must be a boolean');
queryOptions.autocomplete = options.autocomplete;
}
return this.client({
path: constants.API_GEOCODING_FORWARD,
params: queryOptions,
callback: callback
});
}).entity();
};

@@ -149,7 +186,6 @@

// typecheck arguments
assert(typeof location === 'object', 'location must be an object');
assert(typeof options === 'object', 'options must be an object');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof location === 'object', 'location must be an object');
invariant(typeof options === 'object', 'options must be an object');
assert(typeof location.latitude === 'number' &&
invariant(typeof location.latitude === 'number' &&
typeof location.longitude === 'number',

@@ -163,3 +199,3 @@ 'location must be an object with numeric latitude & longitude properties');

if (options.dataset) {
assert(typeof options.dataset === 'string', 'dataset option must be string');
invariant(typeof options.dataset === 'string', 'dataset option must be string');
queryOptions.dataset = options.dataset;

@@ -170,3 +206,3 @@ }

if (options.precision) {
assert(typeof options.precision === 'number', 'precision option must be number');
invariant(typeof options.precision === 'number', 'precision option must be number');
precision = options.precision;

@@ -176,3 +212,3 @@ }

if (options.types) {
assert(typeof options.types === 'string', 'types option must be string');
invariant(typeof options.types === 'string', 'types option must be string');
queryOptions.types = options.types;

@@ -184,9 +220,9 @@ }

this.client({
return this.client({
path: constants.API_GEOCODING_REVERSE,
params: queryOptions,
callback: callback
});
}).entity();
};
module.exports = MapboxGeocoding;
'use strict';
var assert = require('assert'),
geojsonhint = require('geojsonhint/object'),
var invariant = require('../../vendor/invariant'),
makeService = require('../make_service'),

@@ -77,5 +76,4 @@ constants = require('../constants');

// typecheck arguments
assert(geojsonhint.hint(trace).length === 0, 'trace must be valid GeoJSON');
assert(typeof options === 'object', 'options must be an object');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof trace === 'object', 'trace must be an object');
invariant(typeof options === 'object', 'options must be an object');

@@ -88,3 +86,3 @@ var profile = 'mapbox.driving',

if (options.gps_precision !== undefined) {
assert(typeof options.gps_precision === 'number', 'gps_precision must be a number');
invariant(typeof options.gps_precision === 'number', 'gps_precision must be a number');
gps_precision = options.gps_precision;

@@ -94,3 +92,3 @@ }

if (options.profile) {
assert(typeof options.profile === 'string', 'profile option must be string');
invariant(typeof options.profile === 'string', 'profile option must be string');
profile = options.profile;

@@ -100,7 +98,7 @@ }

if (options.geometry) {
assert(typeof options.geometry === 'string', 'geometry option must be string');
invariant(typeof options.geometry === 'string', 'geometry option must be string');
geometry = options.geometry;
}
this.client({
return this.client({
path: constants.API_MATCHING,

@@ -115,5 +113,5 @@ params: {

callback: callback
});
}).entity();
};
module.exports = MapboxMatching;
'use strict';
var assert = require('assert'),
xtend = require('xtend'),
var invariant = require('../../vendor/invariant'),
xtend = require('../../vendor/xtend').extend,
uriTemplate = require('rest/util/uriTemplate'),
encodeOverlay = require('../encode_overlay'),
assertLocation = require('../assert_location'),
invariantLocation = require('../invariant_location'),
makeService = require('../make_service'),

@@ -41,5 +41,5 @@ constants = require('../constants');

MapboxStatic.prototype.getStaticURL = function(mapid, width, height, position, options) {
assert.equal(typeof mapid, 'string', 'mapid option required and must be a string');
assert.equal(typeof width, 'number', 'width option required and must be a number');
assert.equal(typeof height, 'number', 'height option required and must be a number');
invariant(typeof mapid === 'string', 'mapid option required and must be a string');
invariant(typeof width === 'number', 'width option required and must be a number');
invariant(typeof height === 'number', 'height option required and must be a number');

@@ -56,3 +56,3 @@ var defaults = {

} else {
assertLocation(position);
invariantLocation(position);
xyz = position.longitude + ',' + position.latitude + ',' + position.zoom;

@@ -64,9 +64,9 @@ }

if (options) {
assert.equal(typeof options, 'object', 'options must be an object');
invariant(typeof options === 'object', 'options must be an object');
if (options.format) {
assert.equal(typeof options.format, 'string', 'format must be a string');
invariant(typeof options.format === 'string', 'format must be a string');
userOptions.format = options.format;
}
if (options.retina) {
assert.equal(typeof options.retina, 'boolean', 'retina must be a boolean');
invariant(typeof options.retina === 'boolean', 'retina must be a boolean');
userOptions.retina = options.retina;

@@ -87,3 +87,4 @@ }

xyz: xyz,
height: height
height: height,
access_token: this.accessToken
});

@@ -95,6 +96,5 @@

return this.endpoint + uriTemplate.expand(constants.API_STATIC, params) +
'?access_token=' + this.accessToken;
return this.endpoint + uriTemplate.expand(constants.API_STATIC, params);
};
module.exports = MapboxStatic;
'use strict';
var assert = require('assert'),
var invariant = require('../../vendor/invariant'),
formatPoints = require('../format_points'),

@@ -50,8 +50,7 @@ makeService = require('../make_service'),

// typecheck arguments
assert(typeof mapid === 'string', 'mapid must be a string');
assert(typeof layer === 'string', 'layer must be a string');
assert(Array.isArray(fields), 'fields must be an array of strings');
assert(Array.isArray(path) || typeof path === 'string', 'path must be an array of objects or a string');
assert(typeof options === 'object', 'options must be an object');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof mapid === 'string', 'mapid must be a string');
invariant(typeof layer === 'string', 'layer must be a string');
invariant(Array.isArray(fields), 'fields must be an array of strings');
invariant(Array.isArray(path) || typeof path === 'string', 'path must be an array of objects or a string');
invariant(typeof options === 'object', 'options must be an object');

@@ -62,3 +61,3 @@ var interpolate = true,

if (options.interpolate !== undefined) {
assert(typeof options.interpolate === 'boolean', 'interpolate must be a boolean');
invariant(typeof options.interpolate === 'boolean', 'interpolate must be a boolean');
interpolate = options.interpolate;

@@ -68,3 +67,3 @@ }

if (options.geojson !== undefined) {
assert(typeof options.geojson === 'boolean', 'geojson option must be boolean');
invariant(typeof options.geojson === 'boolean', 'geojson option must be boolean');
geojson = options.geojson;

@@ -88,13 +87,13 @@ }

if (options.zoom !== undefined) {
assert(typeof options.zoom === 'number', 'zoom must be a number');
invariant(typeof options.zoom === 'number', 'zoom must be a number');
surfaceOptions.z = options.zoom;
}
this.client({
return this.client({
path: constants.API_SURFACE,
params: surfaceOptions,
callback: callback
});
}).entity();
};
module.exports = MapboxSurface;
'use strict';
var assert = require('assert'),
var invariant = require('../../vendor/invariant'),
makeService = require('../make_service'),

@@ -19,6 +19,5 @@ constants = require('../constants');

Tilestats.prototype.createTilestats = function(tileset, layers, callback) {
assert(typeof tileset === 'string', 'tileset must be a string');
assert(typeof callback === 'function', 'callback must be a function');
assert(Array.isArray(layers), 'layers must be an array');
assert(layers.every(function(layer) {
invariant(typeof tileset === 'string', 'tileset must be a string');
invariant(Array.isArray(layers), 'layers must be an array');
invariant(layers.every(function(layer) {
return typeof layer === 'string';

@@ -30,3 +29,3 @@ }), 'layers must be an array of strings');

this.client({
return this.client({
path: constants.API_TILESTATS_STATISTICS,

@@ -40,3 +39,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -53,4 +52,3 @@

Tilestats.prototype.deleteTilestats = function(tileset, callback) {
assert(typeof tileset === 'string', 'tileset must be a string');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof tileset === 'string', 'tileset must be a string');

@@ -60,3 +58,3 @@ var owner = tileset.split('.')[0];

this.client({
return this.client({
path: constants.API_TILESTATS_STATISTICS,

@@ -69,3 +67,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -106,4 +104,3 @@

Tilestats.prototype.getTilestats = function(tileset, callback) {
assert(typeof tileset === 'string', 'tileset must be a string');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof tileset === 'string', 'tileset must be a string');

@@ -113,3 +110,3 @@ var owner = tileset.split('.')[0];

this.client({
return this.client({
path: constants.API_TILESTATS_STATISTICS,

@@ -121,3 +118,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -146,6 +143,5 @@

Tilestats.prototype.updateTilestatsLayer = function(tileset, layer, geometries, callback) {
assert(typeof tileset === 'string', 'tileset must be a string');
assert(typeof callback === 'function', 'callback must be a function');
assert(typeof layer === 'string', 'layer must be a string');
assert(typeof geometries === 'object', 'geometries must be an object');
invariant(typeof tileset === 'string', 'tileset must be a string');
invariant(typeof layer === 'string', 'layer must be a string');
invariant(typeof geometries === 'object', 'geometries must be an object');

@@ -155,3 +151,3 @@ var owner = tileset.split('.')[0];

this.client({
return this.client({
path: constants.API_TILESTATS_LAYER,

@@ -166,3 +162,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -187,7 +183,6 @@

Tilestats.prototype.updateTilestatsAttribute = function(tileset, layer, attribute, stats, callback) {
assert(typeof tileset === 'string', 'tileset must be a string');
assert(typeof callback === 'function', 'callback must be a function');
assert(typeof layer === 'string', 'layer must be a string');
assert(typeof attribute === 'string', 'attribute must be a string');
assert(typeof stats === 'object', 'stats must be an object');
invariant(typeof tileset === 'string', 'tileset must be a string');
invariant(typeof layer === 'string', 'layer must be a string');
invariant(typeof attribute === 'string', 'attribute must be a string');
invariant(typeof stats === 'object', 'stats must be an object');

@@ -197,3 +192,3 @@ var owner = tileset.split('.')[0];

this.client({
return this.client({
path: constants.API_TILESTATS_ATTRIBUTE,

@@ -209,3 +204,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -242,6 +237,5 @@

Tilestats.prototype.getTilestatsAttribute = function(tileset, layer, attribute, callback) {
assert(typeof tileset === 'string', 'tileset must be a string');
assert(typeof callback === 'function', 'callback must be a function');
assert(typeof layer === 'string', 'layer must be a string');
assert(typeof attribute === 'string', 'attribute must be a string');
invariant(typeof tileset === 'string', 'tileset must be a string');
invariant(typeof layer === 'string', 'layer must be a string');
invariant(typeof attribute === 'string', 'attribute must be a string');

@@ -251,3 +245,3 @@ var owner = tileset.split('.')[0];

this.client({
return this.client({
path: constants.API_TILESTATS_ATTRIBUTE,

@@ -261,3 +255,3 @@ params: {

callback: callback
});
}).entity();
};
'use strict';
var assert = require('assert'),
var invariant = require('../../vendor/invariant'),
makeService = require('../make_service'),

@@ -45,9 +45,7 @@ constants = require('../constants');

Uploads.prototype.listUploads = function(callback) {
assert(typeof callback === 'function', 'callback must be a function');
this.client({
return this.client({
path: constants.API_UPLOADS,
params: { owner: this.owner },
callback: callback
});
}).entity();
};

@@ -94,9 +92,7 @@

Uploads.prototype.createUploadCredentials = function(callback) {
assert(typeof callback === 'function', 'callback must be a function');
this.client({
return this.client({
path: constants.API_UPLOAD_CREDENTIALS,
params: { owner: this.owner },
callback: callback
});
}).entity();
};

@@ -147,6 +143,5 @@

Uploads.prototype.createUpload = function(options, callback) {
assert(typeof options === 'object', 'options must be an object');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof options === 'object', 'options must be an object');
this.client({
return this.client({
path: constants.API_UPLOADS,

@@ -156,3 +151,3 @@ params: { owner: this.owner },

callback: callback
});
}).entity();
};

@@ -185,6 +180,5 @@

Uploads.prototype.readUpload = function(upload, callback) {
assert(typeof upload === 'string', 'upload must be a string');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof upload === 'string', 'upload must be a string');
this.client({
return this.client({
path: constants.API_UPLOAD,

@@ -196,3 +190,3 @@ params: {

callback: callback
});
}).entity();
};

@@ -213,6 +207,5 @@

Uploads.prototype.deleteUpload = function(upload, callback) {
assert(typeof upload === 'string', 'upload must be a string');
assert(typeof callback === 'function', 'callback must be a function');
invariant(typeof upload === 'string', 'upload must be a string');
this.client({
return this.client({
method: 'delete',

@@ -225,3 +218,3 @@ path: constants.API_UPLOAD,

callback: callback
});
}).entity();
};
{
"name": "mapbox",
"version": "1.0.0-beta",
"version": "1.0.0-beta1",
"description": "interface to mapbox services",

@@ -18,3 +18,2 @@ "main": "lib/mapbox.js",

"browser": {
"atob": "./lib/atob.js",
"tap": "tape"

@@ -52,12 +51,8 @@ },

"tape": "^4.2.0",
"geojsonhint": "^1.1.0",
"uglifyjs": "^2.4.10"
},
"dependencies": {
"atob": "^1.1.2",
"geojsonhint": "^1.1.0",
"hat": "0.0.3",
"polyline": "^0.1.0",
"rest": "^1.3.1",
"xtend": "^4.0.0"
"rest": "^1.3.2"
}
}

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

var geojsonRandom = require('geojson-random');
var hat = require('hat');
var hat = require('../vendor/hat');

@@ -80,5 +80,2 @@ function randomFeature() {

assert.ok(client, 'created dataset client');
assert.throws(function() {
client.listDatasets();
}, 'no callback function');
assert.end();

@@ -113,5 +110,2 @@ });

}, 'dataset must be a string');
assert.throws(function() {
client.readDataset('help');
}, 'callback must be a function');
assert.end();

@@ -155,5 +149,2 @@ });

}, 'must update name or description');
assert.throws(function() {
client.updateDataset('help', {name: 'needs' });
}, 'callback must be a function');
assert.end();

@@ -191,10 +182,4 @@ });

assert.throws(function() {
client.insertFeature({}, '', function() {});
}, 'feature must be valid GeoJSON');
assert.throws(function() {
client.insertFeature(validFeature, [], function() {});
}, 'dataset must be a string');
assert.throws(function() {
client.insertFeature(validFeature, testDatasets[0]);
}, 'callback must be a function');
assert.end();

@@ -228,5 +213,2 @@ });

}, 'dataset must be a string');
assert.throws(function() {
client.readFeature('', '');
}, 'callback must be a function');
assert.end();

@@ -267,5 +249,2 @@ });

}, 'dataset must be a string');
assert.throws(function() {
client.deleteFeature('', '');
}, 'callback must be a function');
assert.end();

@@ -296,6 +275,6 @@ });

datasetClient.test('#bulkFeatureUpdate', function(bulkFeatureUpdate) {
datasetClient.test('#batchFeatureUpdate', function(batchFeatureUpdate) {
var featureIds = [];
bulkFeatureUpdate.test('typecheck', function(assert) {
batchFeatureUpdate.test('typecheck', function(assert) {
var validFeature = randomFeature();

@@ -305,25 +284,16 @@ var client = new MapboxClient(process.env.MapboxAccessToken);

assert.throws(function() {
client.bulkFeatureUpdate('', '', function() {});
client.batchFeatureUpdate('', '', function() {});
}, 'update must be an object');
assert.throws(function() {
client.bulkFeatureUpdate({}, {}, function() {});
client.batchFeatureUpdate({}, {}, function() {});
}, 'dataset must be a string');
assert.throws(function() {
client.bulkFeatureUpdate({}, '', '');
}, 'callback must be a function');
assert.throws(function() {
client.bulkFeatureUpdate({ put: validFeature }, '', function() {});
}, 'update.put must be an array of valid GeoJSON');
assert.throws(function() {
client.bulkFeatureUpdate({ delete: [validFeature] }, '', function() {});
client.batchFeatureUpdate({ delete: [validFeature] }, '', function() {});
}, 'update.delete must be an array of strings');
assert.throws(function() {
client.bulkFeatureUpdate([], [''], '');
}, 'callback must be a function');
assert.throws(function() {
client.bulkFeatureUpdate([validFeature], [''], '', function() {});
client.batchFeatureUpdate([validFeature], [''], '', function() {});
}, 'inserted features must include ids');
validFeature.id = 'hi';
assert.throws(function() {
client.bulkFeatureUpdate([validFeature], [{}], '', function() {});
client.batchFeatureUpdate([validFeature], [{}], '', function() {});
}, 'deletes must be an array of strings');

@@ -333,3 +303,3 @@ assert.end();

bulkFeatureUpdate.test('insert some', function(assert) {
batchFeatureUpdate.test('insert some', function(assert) {
var client = new MapboxClient(process.env.MapboxAccessToken);

@@ -342,3 +312,3 @@ assert.ok(client, 'created dataset client');

});
client.bulkFeatureUpdate({ put: features }, testDatasets[0], function(err, response) {
client.batchFeatureUpdate({ put: features }, testDatasets[0], function(err, response) {
assert.ifError(err, 'success');

@@ -350,3 +320,3 @@ assert.equal(response.put.length, 3, 'returned three features');

bulkFeatureUpdate.test('insert & delete some', function(assert) {
batchFeatureUpdate.test('insert & delete some', function(assert) {
var client = new MapboxClient(process.env.MapboxAccessToken);

@@ -360,3 +330,3 @@ assert.ok(client, 'created dataset client');

var deletes = [featureIds.shift(), featureIds.shift()];
client.bulkFeatureUpdate({ put: features, delete: deletes }, testDatasets[0], function(err, response) {
client.batchFeatureUpdate({ put: features, delete: deletes }, testDatasets[0], function(err, response) {
assert.ifError(err, 'success');

@@ -369,6 +339,6 @@ assert.equal(response.put.length, 1, 'returned one insert');

bulkFeatureUpdate.test('delete everything left', function(assert) {
batchFeatureUpdate.test('delete everything left', function(assert) {
var client = new MapboxClient(process.env.MapboxAccessToken);
assert.ok(client, 'created dataset client');
client.bulkFeatureUpdate({ delete: featureIds }, testDatasets[0], function(err, response) {
client.batchFeatureUpdate({ delete: featureIds }, testDatasets[0], function(err, response) {
assert.ifError(err, 'success');

@@ -380,3 +350,3 @@ assert.equal(response.delete.length, 2, 'returned two deletes');

bulkFeatureUpdate.test('make sure it is all gone', function(assert) {
batchFeatureUpdate.test('make sure it is all gone', function(assert) {
var client = new MapboxClient(process.env.MapboxAccessToken);

@@ -391,3 +361,3 @@ assert.ok(client, 'created dataset client');

bulkFeatureUpdate.end();
batchFeatureUpdate.end();
});

@@ -403,3 +373,3 @@

});
client.bulkFeatureUpdate({ put: features }, testDatasets[1], function(err, response) {
client.batchFeatureUpdate({ put: features }, testDatasets[1], function(err, response) {
assert.ifError(err, 'success');

@@ -421,5 +391,2 @@ assert.equal(response.put.length, 3, 'returned three features');

assert.throws(function() {
client.listFeatures('');
}, 'callback must be a function');
assert.throws(function() {
client.listFeatures([], {

@@ -503,5 +470,2 @@ reverse: ''

}, 'dataset must be a string');
assert.throws(function() {
client.deleteDataset('help');
}, 'callback must be a function');
assert.end();

@@ -508,0 +472,0 @@ });

@@ -42,2 +42,16 @@ /* eslint no-shadow: 0 */

t.test('promise interface', function(t) {
var client = new MapboxClient(process.env.MapboxAccessToken);
t.ok(client);
client.getDirections([
{ latitude: 33.6875431, longitude: -95.4431142 },
{ latitude: 33.6875431, longitude: -95.4831142 }
]).then(function(results) {
t.deepEqual(geojsonhint.hint(results.origin), [], 'origin is valid');
t.end();
}, function(err) {
t.ifError(err);
});
});
t.test('assert options', function(t) {

@@ -56,2 +70,3 @@ var client = new MapboxClient(process.env.MapboxAccessToken);

opts.callback();
return { entity: function() {} };
}};

@@ -58,0 +73,0 @@

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

test('encodeGeoJSON', function(t) {
t.throws(function() {
encodeOverlay.encodeGeoJSON({ type: 'invalid' });
});
t.equal(encodeOverlay.encodeGeoJSON({

@@ -13,0 +10,0 @@ type: 'Point',

@@ -37,2 +37,24 @@ /* eslint no-shadow: 0 */

t.test('input with linebreak', function(t) {
var client = new MapboxClient(process.env.MapboxAccessToken);
t.ok(client);
client.geocodeForward('100 6th St\nSan Francisco', function(err, results) {
t.ifError(err);
t.deepEqual(geojsonhint.hint(results), [], 'results are valid');
t.end();
});
});
t.test('autocomplete=false', function(t) {
var client = new MapboxClient(process.env.MapboxAccessToken);
t.ok(client);
client.geocodeForward('New York', {
autocomplete: false
}, function(err, results) {
t.ifError(err);
t.deepEqual(geojsonhint.hint(results), [], 'results are valid');
t.end();
});
});
t.test('dataset option', function(t) {

@@ -51,2 +73,14 @@ var client = new MapboxClient(process.env.MapboxAccessToken);

t.test('dataset option', function(t) {
var client = new MapboxClient(process.env.MapboxAccessToken);
t.ok(client);
client.geocodeForward(
'Chester, New Jersey', { dataset: 'mapbox.places' })
.then(function(results) {
t.deepEqual(geojsonhint.hint(results), [], 'results are valid');
t.equal(geojsonhint.hint(results.features[0]).length, 0, 'at least one valid result');
t.end();
});
});
t.test('options.country', function(t) {

@@ -60,2 +94,3 @@ var client = new MapboxClient(process.env.MapboxAccessToken);

opts.callback();
return { entity: function() {} };
}};

@@ -79,2 +114,3 @@

opts.callback();
return { entity: function() {} };
}};

@@ -90,2 +126,42 @@

t.test('options.dataset', function(t) {
var client = new MapboxClient(process.env.MapboxAccessToken);
t.ok(client);
client.geocodeForward('Paris;Lyon;Nice;Nantes', {
dataset: 'mapbox.places-permanent'
}, function(err, results) {
t.ifError(err);
t.ok(Array.isArray(results), 'results is an array of results');
results.forEach(function(result, i) {
t.deepEqual(geojsonhint.hint(result), [], 'result ' + i + ' is valid');
});
t.end();
});
});
t.test('options.dataset with array input', function(t) {
var client = new MapboxClient(process.env.MapboxAccessToken);
t.ok(client);
client.geocodeForward(['Paris', 'Lyon', 'Nice', 'Nantes'], {
dataset: 'mapbox.places-permanent'
}, function(err, results) {
t.ifError(err);
t.ok(Array.isArray(results), 'results is an array of results');
results.forEach(function(result, i) {
t.deepEqual(geojsonhint.hint(result), [], 'result ' + i + ' is valid');
});
t.end();
});
});
t.test('array input without permanent will throw', function(t) {
var client = new MapboxClient(process.env.MapboxAccessToken);
t.throws(function() {
client.geocodeForward(['Paris', 'Lyon', 'Nice', 'Nantes'],
function(err, results) {
});
});
t.end();
});
t.test('options.proximity', function(t) {

@@ -112,2 +188,3 @@ var client = new MapboxClient(process.env.MapboxAccessToken);

opts.callback();
return { entity: function() {} };
}};

@@ -133,2 +210,3 @@

opts.callback();
return { entity: function() {} };
}};

@@ -146,2 +224,21 @@

t.test('options.bbox', function(t) {
var client = new MapboxClient(process.env.MapboxAccessToken);
t.ok(client);
var tester = { client: function(opts) {
var params = opts.params;
t.equals(params.bbox, '-98,32,-96,34', 'bbox option is set');
opts.callback();
return { entity: function() {} };
}};
client.geocodeForward.apply(tester, ['Paris', {
bbox: [-98, 32, -96, 34]
}, function(err) {
t.ifError(err);
t.end();
}]);
});
t.end();

@@ -187,2 +284,3 @@ });

opts.callback();
return { entity: function() {} };
}};

@@ -222,2 +320,3 @@

opts.callback();
return { entity: function() {} };
}};

@@ -245,2 +344,3 @@

opts.callback();
return { entity: function() {} };
}};

@@ -247,0 +347,0 @@

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

var test = require('tap').test;
var MapboxClient = require('../');
var getUser = require('../lib/get_user');

@@ -24,7 +25,11 @@

assert.equal(getUser(token), 'worbly', 'success');
token = 'sk.eyJ1Ijoid29yYmx5IiwiYSI6ImQwNTg3OGU2MWI5NTI5MjIyNmI1YzNhNWE4ZGFlMmFiIn0===.-47f43O4Cz5-vEd0gXzJ3w';
assert.equal(getUser(token), 'worbly', 'success');
assert.end();
});
t.test('from client static method', function(assert) {
var token = 'sk.eyJ1Ijoid29yYmx5IiwiYSI6ImQwNTg3OGU2MWI5NTI5MjIyNmI1YzNhNWE4ZGFlMmFiIn0=.-47f43O4Cz5-vEd0gXzJ3w';
assert.equal(MapboxClient.getUser(token), 'worbly', 'success');
assert.end();
});
t.test('bogus token', function(assert) {

@@ -31,0 +36,0 @@ var token = 'sk.eyJ1Ijoid29yYmx5IiwiYSI6ImQwNTg3OGU2MWI5NTI5MjIyNmI1YzNhNWE4ZGFlMmFiI12.-47f43O4Cz5-vEd0gXzJ3w';

@@ -34,2 +34,6 @@ /* eslint no-shadow: 0 */

t.equal(removeToken(client.getStaticURL('foo', 10, 10, 'auto', {
retina: true
})), 'https://api.mapbox.com/v4/foo/auto/10x10@2x.png', 'auto');
t.equal(removeToken(client.getStaticURL('foo', 10, 10, {

@@ -36,0 +40,0 @@ longitude: 1, latitude: 2, zoom: 3

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

// path = require('path'),
polyline = require('polyline'),
polyline = require('../vendor/polyline'),
geojsonhint = require('geojsonhint'),

@@ -10,0 +10,0 @@ MapboxClient = require('../lib/services/surface');

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

var MapboxClient = require('../lib/services/tilestats');
var hat = require('hat');
var hat = require('../vendor/hat');

@@ -20,5 +20,2 @@ test('TilestatsClient', function(tilestatsClient) {

assert.throws(function() {
client.createTilestats('yes', ['ham']);
}, 'callback must be a function');
assert.throws(function() {
client.createTilestats('yes', 'ham', function() {});

@@ -54,2 +51,23 @@ }, 'layers must be an array');

createTilestats.test('creates - promise style', function(assert) {
var client = new MapboxClient(process.env.MapboxAccessToken);
client.createTilestats(tilesetid, ['layer']).then(function(result) {
assert.deepEqual(result, {
account: client.owner,
tilesetid: tilesetid,
layers: [
{
account: client.owner,
tilesetid: tilesetid,
layer: 'layer',
geometry: 'UNKNOWN',
count: 0,
attributes: []
}
]
}, 'expected result');
assert.end();
});
});
createTilestats.test('creates when user specified by tilesetid', function(assert) {

@@ -89,5 +107,2 @@ var client = new MapboxClient(process.env.MapboxAccessToken);

assert.throws(function() {
client.updateTilestatsLayer('yes', 'ham', {});
}, 'callback must be a function');
assert.throws(function() {
client.updateTilestatsLayer('yes', null, {}, function() {});

@@ -147,5 +162,2 @@ }, 'layer must be a string');

assert.throws(function() {
client.updateTilestatsAttribute('yes', 'ham', 'eggs', {});
}, 'callback must be a function');
assert.throws(function() {
client.updateTilestatsAttribute('yes', null, 'eggs', {}, function() {});

@@ -212,5 +224,2 @@ }, 'layer must be a string');

assert.throws(function() {
client.getTilestatsAttribute('yes', 'ham', 'eggs');
}, 'callback must be a function');
assert.throws(function() {
client.getTilestatsAttribute('yes', null, 'eggs', function() {});

@@ -271,5 +280,2 @@ }, 'layer must be a string');

}, 'tileset must be a string');
assert.throws(function() {
client.getTilestats('yes');
}, 'callback must be a function');
assert.end();

@@ -347,5 +353,2 @@ });

}, 'tileset must be a string');
assert.throws(function() {
client.deleteTilestats('yes');
}, 'callback must be a function');
assert.end();

@@ -352,0 +355,0 @@ });

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

var AWS = require('aws-sdk');
var hat = require('hat');
var hat = require('../vendor/hat');
var path = require('path');

@@ -27,8 +27,2 @@ var fs = require('fs');

assert.ok(client, 'created upload client');
assert.throws(function() {
client.createUploadCredentials(100, function() {});
}, 'throws owner must be a string error');
assert.throws(function() {
client.createUploadCredentials();
}, 'throw no callback function error');
assert.end();

@@ -77,5 +71,2 @@ });

}, 'throws option not an object error');
assert.throws(function() {
client.createUpload();
}, 'throws no callback function error');
assert.end();

@@ -127,5 +118,2 @@ });

}, 'throws owner must be a string error');
assert.throws(function() {
client.readUpload();
}, 'throws no callback function error');
assert.end();

@@ -135,2 +123,3 @@ });

readUpload.test('valid request', function(assert) {
assert.plan(2);
var client = new MapboxClient(process.env.MapboxAccessToken);

@@ -142,8 +131,7 @@ assert.ok(client, 'created upload client');

client.readUpload(upload.id, function(err, upload) {
assert.ifError(err, 'success');
if (attempts > 4) throw new Error('Upload did not complete in time');
// we are waiting for mapbox to process the upload
if (!upload.complete) return setTimeout(poll, Math.pow(2, attempts++) * 1000);
assert.ifError(err, 'success');
completedUpload = upload;
assert.end();
});

@@ -170,8 +158,2 @@ }

assert.ok(client, 'created upload client');
assert.throws(function() {
client.listUploads(100, function() {});
}, 'throws owner must be a string error');
assert.throws(function() {
client.listUploads();
}, 'throws no callback function error');
assert.end();

@@ -199,5 +181,2 @@ });

}, 'throws owner must be a string error');
assert.throws(function() {
client.deleteUpload();
}, 'throws no callback function error');
assert.end();

@@ -204,0 +183,0 @@ });

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