Skip to content

Commit

Permalink
Merge pull request #493 from mapbox/geocoding-sessionid
Browse files Browse the repository at this point in the history
Add session_token to Geocoding services
  • Loading branch information
mpothier authored Sep 13, 2024
2 parents 41c7da5 + 0e19cc9 commit 12f5a42
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.16.1

- **Add:** Add `session_token` as optional parameter in the geocoding services

## 0.16.0

- **Add:** Add `depart_at` as optional parameter in the isochrone service
Expand Down
4 changes: 4 additions & 0 deletions docs/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,7 @@ See the [public documentation][241].
* `config.routing` **[boolean][209]** Specify whether to request additional metadata about the recommended navigation destination. Only applicable for address features. (optional, default `false`)
* `config.fuzzyMatch` **[boolean][209]** Specify whether the Geocoding API should attempt approximate, as well as exact, matching. (optional, default `true`)
* `config.worldview` **[String][208]** Filter results to geographic features whose characteristics are defined differently by audiences belonging to various regional, cultural, or political groups. (optional, default `"us"`)
* `config.session_token` **[String][208]?** A unique session identifier generated by the client.

#### Examples

Expand Down Expand Up @@ -1758,6 +1759,7 @@ See the [public documentation][245].
* `config.reverseMode` **(`"distance"` | `"score"`)** Set the factors that are used to sort nearby results. (optional, default `'distance'`)
* `config.routing` **[boolean][209]** Specify whether to request additional metadata about the recommended navigation destination. Only applicable for address features. (optional, default `false`)
* `config.worldview` **[String][208]** Filter results to geographic features whose characteristics are defined differently by audiences belonging to various regional, cultural, or political groups. (optional, default `"us"`)
* `config.session_token` **[String][208]?** A unique session identifier generated by the client.

#### Examples

Expand Down Expand Up @@ -2380,6 +2382,7 @@ See the [public documentation][264].
* `config.autocomplete` **[boolean][209]** Return autocomplete results or not. (optional, default `true`)
* `config.permanent` **[boolean][209]** Specify whether you intend to store the results of the query (true) or not (false, default). Temporary results are not allowed to be cached, while Permanent results are allowed to be cached and stored indefinitely. (optional, default `false`)
* `config.worldview` **[String][208]** Filter results to geographic features whose characteristics are defined differently by audiences belonging to various regional, cultural, or political groups. (optional, default `"us"`)
* `config.session_token` **[String][208]?** A unique session identifier generated by the client.

#### Examples

Expand Down Expand Up @@ -2463,6 +2466,7 @@ See the [public documentation][265].
[ISO 639-1 language code][244] and optionally one or more IETF subtags for country or script.
* `config.permanent` **[boolean][209]** Specify whether you intend to store the results of the query (true) or not (false, default). Temporary results are not allowed to be cached, while Permanent results are allowed to be cached and stored indefinitely. (optional, default `false`)
* `config.worldview` **[String][208]** Filter results to geographic features whose characteristics are defined differently by audiences belonging to various regional, cultural, or political groups. (optional, default `"us"`)
* `config.session_token` **[String][208]?** A unique session identifier generated by the client.

#### Examples

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mapbox/mapbox-sdk",
"version": "0.16.0",
"version": "0.16.1",
"description": "JS SDK for accessing Mapbox APIs",
"main": "index.js",
"files": [
Expand Down
12 changes: 9 additions & 3 deletions services/__tests__/geocoding-v6.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('forwardGeocode', () => {
language: 'de',
worldview: 'us',
permanent: true,
session_token: 'abc123',

// structured input parameters will be ignored in normal mode
address_line1: '12 main',
Expand All @@ -60,7 +61,8 @@ describe('forwardGeocode', () => {
limit: 3,
language: 'de',
worldview: 'us',
permanent: 'true'
permanent: 'true',
session_token: 'abc123'
}
});
});
Expand All @@ -76,6 +78,7 @@ describe('forwardGeocode', () => {
limit: 3,
language: 'de',
worldview: 'us',
session_token: 'abc123',

// structured input parameters will be picked
address_line1: '12 main',
Expand All @@ -99,6 +102,7 @@ describe('forwardGeocode', () => {
limit: 3,
language: 'de',
worldview: 'us',
session_token: 'abc123',

address_line1: '12 main',
address_number: '12',
Expand Down Expand Up @@ -140,7 +144,8 @@ describe('reverseGeocode', () => {
limit: 3,
language: 'de',
worldview: 'us',
permanent: true
permanent: true,
session_token: 'abc123'
});
expect(tu.requestConfig(geocoding)).toEqual({
method: 'GET',
Expand All @@ -153,7 +158,8 @@ describe('reverseGeocode', () => {
limit: 3,
language: 'de',
worldview: 'us',
permanent: 'true'
permanent: 'true',
session_token: 'abc123'
}
});
});
Expand Down
12 changes: 8 additions & 4 deletions services/__tests__/geocoding.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ describe('forwardGeocode', () => {
language: ['de', 'bs'],
routing: true,
fuzzyMatch: true,
worldview: 'us'
worldview: 'us',
session_token: 'abc123'
});
expect(tu.requestConfig(geocoding)).toEqual({
method: 'GET',
Expand All @@ -56,7 +57,8 @@ describe('forwardGeocode', () => {
language: ['de', 'bs'],
routing: 'true',
fuzzyMatch: 'true',
worldview: 'us'
worldview: 'us',
session_token: 'abc123'
}
});
});
Expand Down Expand Up @@ -89,7 +91,8 @@ describe('reverseGeocode', () => {
language: ['de', 'bs'],
reverseMode: 'distance',
routing: true,
worldview: 'us'
worldview: 'us',
session_token: 'abc123'
});
expect(tu.requestConfig(geocoding)).toEqual({
method: 'GET',
Expand All @@ -106,7 +109,8 @@ describe('reverseGeocode', () => {
language: ['de', 'bs'],
reverseMode: 'distance',
routing: 'true',
worldview: 'us'
worldview: 'us',
session_token: 'abc123'
}
});
});
Expand Down
12 changes: 9 additions & 3 deletions services/geocoding-v6.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var featureTypes = [
* @param {boolean} [config.autocomplete=true] - Return autocomplete results or not.
* @param {boolean} [config.permanent=false] - Specify whether you intend to store the results of the query (true) or not (false, default). Temporary results are not allowed to be cached, while Permanent results are allowed to be cached and stored indefinitely.
* @param {String} [config.worldview="us"] - Filter results to geographic features whose characteristics are defined differently by audiences belonging to various regional, cultural, or political groups.
* @param {String} [config.session_token] - A unique session identifier generated by the client.
* @return {MapiRequest}
*
* @example
Expand Down Expand Up @@ -129,6 +130,7 @@ GeocodingV6.forwardGeocode = function(config) {
worldview: v.string,
autocomplete: v.boolean,
permanent: v.boolean,
session_token: v.string,

// structured input fields
address_line1: v.string,
Expand Down Expand Up @@ -168,7 +170,8 @@ GeocodingV6.forwardGeocode = function(config) {
'limit',
'worldview',
'autocomplete',
'permanent'
'permanent',
'session_token'
])
)
);
Expand Down Expand Up @@ -198,6 +201,7 @@ GeocodingV6.forwardGeocode = function(config) {
* [ISO 639-1 language code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) and optionally one or more IETF subtags for country or script.
* @param {boolean} [config.permanent=false] - Specify whether you intend to store the results of the query (true) or not (false, default). Temporary results are not allowed to be cached, while Permanent results are allowed to be cached and stored indefinitely.
* @param {String} [config.worldview="us"] - Filter results to geographic features whose characteristics are defined differently by audiences belonging to various regional, cultural, or political groups.
* @param {String} [config.session_token] - A unique session identifier generated by the client.
* @return {MapiRequest}
*
* @example
Expand All @@ -220,7 +224,8 @@ GeocodingV6.reverseGeocode = function(config) {
limit: v.number,
language: v.string,
worldview: v.string,
permanent: v.boolean
permanent: v.boolean,
session_token: v.string
})(config);

var query = stringifyBooleans(
Expand All @@ -233,7 +238,8 @@ GeocodingV6.reverseGeocode = function(config) {
'limit',
'language',
'worldview',
'permanent'
'permanent',
'session_token'
])
)
);
Expand Down
14 changes: 10 additions & 4 deletions services/geocoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var featureTypes = [
* @param {boolean} [config.routing=false] - Specify whether to request additional metadata about the recommended navigation destination. Only applicable for address features.
* @param {boolean} [config.fuzzyMatch=true] - Specify whether the Geocoding API should attempt approximate, as well as exact, matching.
* @param {String} [config.worldview="us"] - Filter results to geographic features whose characteristics are defined differently by audiences belonging to various regional, cultural, or political groups.
* @param {String} [config.session_token] - A unique session identifier generated by the client.
* @return {MapiRequest}
*
* @example
Expand Down Expand Up @@ -104,7 +105,8 @@ Geocoding.forwardGeocode = function(config) {
language: v.arrayOf(v.string),
routing: v.boolean,
fuzzyMatch: v.boolean,
worldview: v.string
worldview: v.string,
session_token: v.string
})(config);

config.mode = config.mode || 'mapbox.places';
Expand All @@ -121,7 +123,8 @@ Geocoding.forwardGeocode = function(config) {
'language',
'routing',
'fuzzyMatch',
'worldview'
'worldview',
'session_token'
])
)
);
Expand Down Expand Up @@ -153,6 +156,7 @@ Geocoding.forwardGeocode = function(config) {
* @param {'distance'|'score'} [config.reverseMode='distance'] - Set the factors that are used to sort nearby results.
* @param {boolean} [config.routing=false] - Specify whether to request additional metadata about the recommended navigation destination. Only applicable for address features.
* @param {String} [config.worldview="us"] - Filter results to geographic features whose characteristics are defined differently by audiences belonging to various regional, cultural, or political groups.
* @param {String} [config.session_token] - A unique session identifier generated by the client.
* @return {MapiRequest}
*
* @example
Expand All @@ -176,7 +180,8 @@ Geocoding.reverseGeocode = function(config) {
language: v.arrayOf(v.string),
reverseMode: v.oneOf('distance', 'score'),
routing: v.boolean,
worldview: v.string
worldview: v.string,
session_token: v.string
})(config);

config.mode = config.mode || 'mapbox.places';
Expand All @@ -192,7 +197,8 @@ Geocoding.reverseGeocode = function(config) {
'language',
'reverseMode',
'routing',
'worldview'
'worldview',
'session_token'
])
)
);
Expand Down

0 comments on commit 12f5a42

Please sign in to comment.