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.1 to 0.6.2

.npmignore

614

API.md

@@ -10,2 +10,3 @@ ## `MapboxClient`

* `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.

@@ -23,2 +24,280 @@

| `Error` | if accessToken is not provided |
## `bulkFeatureUpdate`
Perform a batch of inserts, updates, and deletes to a dataset in a single combined request.
This request requires an access token with the datasets:write scope.
There are a number of limits to consider when making this request:
- you can send a total of 100 changes (sum of puts + deletes) in a single request
- any single feature cannot be larger than 500 KB
- the dataset must not exceed 2000 total features
- the dataset must not exceed a total of 5 MB
### Parameters
* `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
* `callback` **`Function`** called with (err, results)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
var inserts = [
{
"type": "Feature",
"properties": {
"name": "Null Island"
},
"geometry": {
"type": "Point",
"coordinates": [0, 0]
}
},
{
"type": "Feature",
"properties": {
"name": "Offshore from Null Island"
},
"geometry": {
"type": "Point",
"coordinates": [0.01, 0.01]
}
}
];
var deletes =[
'feature-id-1',
'feature-id-2'
];
mapboxClient.bulkFeatureUpdate({ put: inserts, delete: deletes }, dataset, function(err, results) {
console.log(results);
// {
// "put": [
// {
// "id": {feature-id},
// "type": "Feature",
// "properties": {
// "name": "Null Island"
// },
// "geometry": {
// "type": "Point",
// "coordinates": [0, 0]
// }
// },
// {
// "id": {feature-id},
// "type": "Feature",
// "properties": {
// "name": "Offshore from Null Island"
// },
// "geometry": {
// "type": "Point",
// "coordinates": [0.01, 0.01]
// }
// }
// ],
// "delete": [
// "feature-id-1",
// "feature-id-2"
// ]
// }
});
```
Returns nothing, calls callback
## `createDataset`
To create a new dataset. Valid properties include title and description (not required).
This request requires an access token with the datasets:write scope.
### Parameters
* `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)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.createDataset({ name: 'foo', description: 'bar' }, function(err, dataset) {
console.log(dataset);
// {
// "owner": {account},
// "id": {dataset id},
// "name": "foo",
// "description": "description",
// "created": {timestamp},
// "modified": {timestamp}
// }
});
```
Returns nothing, calls callback
## `createUpload`
Create an new upload with a file previously staged on Amazon S3.
This request requires an access token with the uploads:write scope.
### Parameters
* `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)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
// Response from a call to createUploadCredentials
var credentials = {
"accessKeyId": "{accessKeyId}",
"bucket": "somebucket",
"key": "hij456",
"secretAccessKey": "{secretAccessKey}",
"sessionToken": "{sessionToken}",
"url": "{s3 url}"
};
mapboxClient.createUpload({
tileset: [accountid, 'mytileset'].join('.'),
url: credentials.url
}, function(err, upload) {
console.log(upload);
// {
// "complete": false,
// "tileset": "example.markers",
// "error": null,
// "id": "hij456",
// "modified": "2014-11-21T19:41:10.000Z",
// "created": "2014-11-21T19:41:10.000Z",
// "owner": "example",
// "progress": 0
// }
});
```
Returns nothing, calls callback
## `createUploadCredentials`
Retrieve credentials that allow a new file to be staged on Amazon S3
while an upload is processed. All uploads must be staged using these
credentials before being uploaded to Mapbox.
This request requires an access token with the uploads:write scope.
### Parameters
* `callback` **`Function`** called with (err, credentials)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.createUploadCredentials(function(err, credentials) {
console.log(credentials);
// {
// "accessKeyId": "{accessKeyId}",
// "bucket": "somebucket",
// "key": "hij456",
// "secretAccessKey": "{secretAccessKey}",
// "sessionToken": "{sessionToken}",
// "url": "{s3 url}"
// }
// Use aws-sdk to stage the file on Amazon S3
var AWS = require('aws-sdk');
var s3 = new AWS.S3({
accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.secretAccessKey,
sessionToken: credentials.sessionToken,
region: 'us-east-1'
});
s3.putObject({
Bucket: credentials.bucket,
Key: credentials.key,
Body: fs.createReadStream('/path/to/file.mbtiles')
}, function(err, resp) {
});
});
```
Returns nothing, calls callback
## `deleteDataset`
To delete a particular dataset.
This request requires an access token with the datasets:write scope.
### Parameters
* `dataset` **`string`** the id for an existing dataset
* `callback` **`Function`** called with (err)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.deleteDataset('dataset-id', function(err) {
if (!err) console.log('deleted!');
});
```
Returns nothing, calls callback
## `deleteFeature`
Delete an existing feature from a dataset.
This request requires an access token with the datasets:write scope.
### Parameters
* `id` **`string`** the `id` of the feature to read
* `dataset` **`string`** the id for an existing dataset
* `callback` **`Function`** called with (err)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.deleteFeature('feature-id', 'dataset-id', function(err, feature) {
if (!err) console.log('deleted!');
});
```
Returns nothing, calls callback
## `deleteUpload`
Delete a completed upload. In-progress uploads cannot be deleted.
This request requires an access token with the uploads:delete scope.
### Parameters
* `callback` **`Function`** called with (err)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.deleteUpload('hij456', function(err) {
});
```
Returns nothing, calls callback
## `geocodeForward`

@@ -128,2 +407,206 @@

## `insertFeature`
Insert a feature into a dataset. This can be a new feature, or overwrite an existing one.
If overwriting an existing feature, make sure that the feature's `id` property correctly identifies
the feature you wish to overwrite.
For new features, specifying an `id` is optional. If you do not specify an `id`, one will be assigned
and returned as part of the response.
This request requires an access token with the datasets:write scope.
There are a number of limits to consider when making this request:
- a single feature cannot be larger than 500 KB
- the dataset must not exceed 2000 total features
- the dataset must not exceed a total of 5 MB
### Parameters
* `feature` **`object`** the feature to insert. Must be a valid GeoJSON feature per http://geojson.org/geojson-spec.html#feature-objects
* `dataset` **`string`** the id for an existing dataset
* `callback` **`Function`** called with (err, feature)
### Examples
```js
// Insert a brand new feature without an id
var mapboxClient = new MapboxClient('ACCESSTOKEN');
var feature = {
"type": "Feature",
"properties": {
"name": "Null Island"
},
"geometry": {
"type": "Point",
"coordinates": [0, 0]
}
};
mapboxClient.insertFeature(feature, 'dataset-id', function(err, feature) {
console.log(feature);
// {
// "id": {feature id},
// "type": "Feature",
// "properties": {
// "name": "Null Island"
// },
// "geometry": {
// "type": "Point",
// "coordinates": [0, 0]
// }
// }
});
```
```js
// Insert a brand new feature with an id, or overwrite an existing feature at that id
var mapboxClient = new MapboxClient('ACCESSTOKEN');
var feature = {
"id": "feature-id",
"type": "Feature",
"properties": {
"name": "Null Island"
},
"geometry": {
"type": "Point",
"coordinates": [0, 0]
}
};
mapboxClient.insertFeature(feature, 'dataset-id', function(err, feature) {
console.log(feature);
// {
// "id": "feature-id",
// "type": "Feature",
// "properties": {
// "name": "Null Island"
// },
// "geometry": {
// "type": "Point",
// "coordinates": [0, 0]
// }
// }
});
```
Returns nothing, calls callback
## `listDatasets`
To retrieve a listing of datasets for a particular account.
This request requires an access token with the datasets:read scope.
### Parameters
* `callback` **`Function`** called with (err, datasets)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.listDatasets(function(err, datasets) {
console.log(datasets);
// [
// {
// "owner": {account},
// "id": {dataset id},
// "name": {dataset name},
// "description": {dataset description},
// "created": {timestamp},
// "modified": {timestamp}
// },
// {
// "owner": {account},
// "id": {dataset id},
// "name": {dataset name},
// "description": {dataset description},
// "created": {timestamp},
// "modified": {timestamp}
// }
// ]
});
```
Returns nothing, calls callback
## `listFeatures`
Retrive a list of the features in a particular dataset. The response body will be a GeoJSON FeatureCollection.
This request requires an access token with the datasets:read scope.
### Parameters
* `dataset` **`string`** the id for an existing dataset
* `callback` **`Function`** called with (err, collection)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.listFeatures('dataset-id', function(err, collection) {
console.log(collection);
{
"type": "FeatureCollection",
"features": [
{
"id": {feature id},
"type": "Feature",
"properties": {feature properties}
"geometry": {feature geometry}
},
{
"id": {feature id},
"type": "Feature",
"properties": {feature properties}
"geometry": {feature geometry}
}
]
}
});
```
Returns nothing, calls callback
## `listUploads`
Retrieve a listing of uploads for a particular account.
This request requires an access token with the uploads:list scope.
### Parameters
* `callback` **`Function`** called with (err, uploads)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.listUploads(function(err, uploads) {
console.log(uploads);
// [
// {
// "complete": true,
// "tileset": "example.mbtiles",
// "error": null,
// "id": "abc123",
// "modified": "2014-11-21T19:41:10.000Z",
// "created": "2014-11-21T19:41:10.000Z",
// "owner": "example",
// "progress": 1
// },
// {
// "complete": false,
// "tileset": "example.foo",
// "error": null,
// "id": "xyz789",
// "modified": "2014-11-21T19:41:10.000Z",
// "created": "2014-11-21T19:41:10.000Z",
// "owner": "example",
// "progress": 0
// }
// ]
});
```
Returns nothing, calls callback
## `matching`

@@ -178,2 +661,99 @@

## `readDataset`
To retrieve information about a particular dataset.
This request requires an access token with the datasets:read scope.
### Parameters
* `dataset` **`string`** the id for an existing dataset
* `callback` **`Function`** called with (err, dataset)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.readDataset('dataset-id', function(err, dataset) {
console.log(dataset);
// {
// "owner": {account},
// "id": "dataset-id",
// "name": {dataset name},
// "description": {dataset description},
// "created": {timestamp},
// "modified": {timestamp}
// }
});
```
Returns nothing, calls callback
## `readFeature`
Read an existing feature from a dataset.
This request requires an access token with the datasets:read scope.
### Parameters
* `id` **`string`** the `id` of the feature to read
* `dataset` **`string`** the id for an existing dataset
* `callback` **`Function`** called with (err, feature)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.readFeature('feature-id', 'dataset-id', function(err, feature) {
console.log(feature);
// {
// "id": "feature-id",
// "type": "Feature",
// "properties": {
// "name": "Null Island"
// },
// "geometry": {
// "type": "Point",
// "coordinates": [0, 0]
// }
// }
});
```
Returns nothing, calls callback
## `readUpload`
Retrieve state of an upload.
This request requires an access token with the uploads:read scope.
### Parameters
* `upload` **`String`** id of the upload to read
* `callback` **`Function`** called with (err, upload)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
mapboxClient.readUpload('hij456', function(err, upload) {
console.log(upload);
// {
// "complete": true,
// "tileset": "example.markers",
// "error": null,
// "id": "hij456",
// "modified": "2014-11-21T19:41:10.000Z",
// "created": "2014-11-21T19:41:10.000Z",
// "owner": "example",
// "progress": 1
// }
});
```
Returns nothing, calls callback
## `surface`

@@ -209,1 +789,35 @@

## `updateDataset`
To make updates to a particular dataset's properties.
This request requires an access token with the datasets:write scope.
### Parameters
* `dataset` **`string`** the id for an existing dataset
* `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)
### Examples
```js
var mapboxClient = new MapboxClient('ACCESSTOKEN');
var options = { name: 'foo' };
mapboxClient.updateDataset('dataset-id', options, function(err, dataset) {
console.log(dataset);
// {
// "owner": {account},
// "id": "dataset-id",
// "name": "foo",
// "description": {dataset description},
// "created": {timestamp},
// "modified": {timestamp}
// }
});
```
Returns nothing, calls callback

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

## 0.6.2
- Added support for [Upload API](https://www.mapbox.com/developers/api/uploads/)
- Added support for Datasets API (in preview)
## 0.6.1

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

9

lib/client.js

@@ -8,3 +8,5 @@ 'use strict';

var MapboxDirections = require('./services/directions');
var MapboxUploads = require('./services/uploads');
var MapboxMatching = require('./services/matching');
var MapboxDatasets = require('./services/datasets');

@@ -22,2 +24,5 @@ /**

* 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

@@ -32,4 +37,6 @@ * var client = new MapboxClient('ACCESSTOKEN');

MapboxDirections.prototype,
MapboxMatching.prototype);
MapboxMatching.prototype,
MapboxDatasets.prototype,
MapboxUploads.prototype);
module.exports = MapboxClient;

@@ -8,2 +8,9 @@ var compile = require('es6-template-strings/compile');

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}');

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

var constants = require('./constants');
var getUser = require('./get_user');

@@ -13,3 +14,3 @@ function makeService(name) {

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

@@ -25,3 +26,11 @@ this.accessToken = accessToken;

}
if (options.account) {
invariant(typeof options.account === 'string', 'account must be a string');
this.owner = options.account;
}
}
this.owner = this.owner || getUser(accessToken);
invariant(!!this.owner, 'could not determine account from provided accessToken');
}

@@ -28,0 +37,0 @@

{
"name": "mapbox",
"version": "0.6.1",
"version": "0.6.2",
"description": "interface to mapbox services",

@@ -31,6 +31,9 @@ "main": "lib/client.js",

"devDependencies": {
"aws-sdk": "^2.1.41",
"browserify": "^11.0.0",
"documentation": "^2.1.0-alpha2",
"eslint": "^0.24.1",
"geojson-random": "^0.2.2",
"geojsonhint": "^1.1.0",
"hat": "0.0.3",
"polyline": "^0.1.0",

@@ -43,2 +46,3 @@ "tap": "^1.3.1",

"geojsonhint": "^1.0.1",
"hat": "0.0.3",
"invariant": "^2.1.0",

@@ -45,0 +49,0 @@ "superagent": "^1.2.0",

@@ -24,2 +24,4 @@ # mapbox-sdk-js

* Interpolates values along lines. Useful for elevation traces.
* [Upload API](https://www.mapbox.com/developers/api/uploads/)
* Upload data to be processed and hosted by Mapbox.

@@ -26,0 +28,0 @@ ## Installation

12

test/test.js

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

var deadToken = 'pk.eyJ1Ijoid29yYmx5IiwiYSI6ImQzMjFkZWRkN2IzNzc5M2MzZDgyNTIzZTRhM2E5MDE3In0.IIrNhFTaOiW-Ykw_J-yQbg';
test('MapboxClient', function(t) {

@@ -28,5 +30,5 @@ t.throws(function() {

}, /accessToken required to instantiate MapboxClient/);
var client = new MapboxClient('token');
var client = new MapboxClient(deadToken);
t.ok(client);
t.equal(client.accessToken, 'token');
t.equal(client.accessToken, deadToken);
t.end();

@@ -37,12 +39,12 @@ });

t.throws(function() {
var client = new MapboxClient('foo', 1);
var client = new MapboxClient(deadToken, 1);
t.notOk(client);
}, /options/);
t.throws(function() {
var client = new MapboxClient('foo', { endpoint: 1 });
var client = new MapboxClient(deadToken, { endpoint: 1 });
t.notOk(client);
}, /endpoint/);
var customClient = new MapboxClient('foo', { endpoint: 'foo.bar' });
var customClient = new MapboxClient(deadToken, { endpoint: 'foo.bar' });
t.equal(customClient.endpoint, 'foo.bar', 'receives an endpoint from options');
t.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