mapricot 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -30,11 +30,13 @@ Methods are grouped by product, the same way as the API's paths. Each returns th
30
30
  | Method | Endpoint |
31
31
  | --- | --- |
32
32
  | `client.geocoding.search(q, { focus, country, limit, lang })` | [`GET /geocoding/v1/search`](https://mapricot.com/docs/geocoding/#find-an-address) |
33
+ | `client.geocoding.searchBatch(queries)` | [`POST /geocoding/v1/search/batch`](https://mapricot.com/docs/geocoding/#search-a-list-of-addresses) |
33
34
  | `client.geocoding.autocomplete(q, { focus, country, limit, lang })` | [`GET /geocoding/v1/autocomplete`](https://mapricot.com/docs/geocoding/#suggest-as-people-type) |
34
35
  | `client.geocoding.reverse(lat, lon, { limit, lang })` | [`GET /geocoding/v1/reverse`](https://mapricot.com/docs/geocoding/#find-the-address-at-a-point) |
35
36
  | `client.places.nearby(lat, lon, { category, radius, limit, lang })` | [`GET /places/v1/nearby`](https://mapricot.com/docs/places/#list-places-around-a-point) |
36
37
  | `client.places.get(id, { lang })` | [`GET /places/v1/{id}`](https://mapricot.com/docs/places/#look-up-a-saved-place) |
37
38
  | `client.routing.route(waypoints, { mode, geometries, steps, lang })` | [`POST /routing/v1/route`](https://mapricot.com/docs/routing/#get-a-route) |
39
+ | `client.routing.optimize(waypoints, { mode, geometries, steps, lang })` | [`POST /routing/v1/optimize`](https://mapricot.com/docs/routing/#optimize-the-order-of-stops) |
38
40
  | `client.routing.isochrone(location, minutes, { mode })` | [`POST /routing/v1/isochrone`](https://mapricot.com/docs/routing/#get-an-isochrone) |
39
41
  | `client.ipGeolocation.lookup(ip)` | [`GET /ip-geolocation/v1/{ip}`](https://mapricot.com/docs/ip-geolocation/#look-up-an-address) |
40
42
  | `client.account()` | `GET /account`, which checks a key and is never billed |
@@ -47,6 +49,13 @@ const { routes } = await client.routing.route([{ lat: 45.5189, lon: -122.6793 },
47
49
  console.log(routes[0].durationSeconds);
48
50
  ```
49
51
 
52
+ `searchBatch` runs up to 100 searches in one request. Each query is an object of `search`'s parameters, and `responses` answers them in the same order, each with `results` and `attribution`, or an `error` with the `code` and `message` that search would get, without rejecting. Each completed search is billed as one request; errors aren't.
53
+
54
+ ```js
55
+ const { responses } = await client.geocoding.searchBatch([{ q: "128 SW 3rd Ave, Portland", limit: 1 }, { q: "10 Downing Street, London", limit: 1 }]);
56
+ for (const response of responses) console.log(response.error?.message ?? response.results[0].label);
57
+ ```
58
+
50
59
  To cancel a request, such as an autocomplete request for text that has since changed, pass an `AbortSignal` as `signal` to any method. The request then rejects with an `AbortError`:
51
60
 
52
61
  ```js
@@ -57,6 +66,8 @@ controller.abort();
57
66
 
58
67
  A route's path comes as an encoded `polyline` with five decimal places, which polyline decoders assume. Pass `geometries: "geojson"` to get it as a GeoJSON `LineString` in `geometry` instead, which maps draw without decoding, or `geometries: "polyline6"` for six decimal places.
59
68
 
69
+ `routing.optimize` takes the same options as `routing.route` and returns the route that visits the waypoints in a fast order, keeping the first and last in place. It adds `waypointOrder`: the indexes of your waypoints in visiting order, which `legs` follow. Every pair of waypoints must be within 400 km of each other for `drive`, or 200 km for `walk` and `bicycle`.
70
+
60
71
  An isochrone is a GeoJSON `FeatureCollection` with one polygon per time, largest first, so a map that draws them in order shows the smaller ones on top:
61
72
 
62
73
  ```js
package/dist/index.d.ts CHANGED
@@ -35,6 +35,27 @@ export interface Places {
35
35
  results: Place[];
36
36
  attribution: Attribution[];
37
37
  }
38
+ /** One search in a batch, with the same parameters as `geocoding.search`. */
39
+ export interface SearchQuery {
40
+ q: string;
41
+ focus?: Point;
42
+ country?: string | string[];
43
+ limit?: number;
44
+ lang?: string;
45
+ }
46
+ /** One search's answer in a batch: results and attribution, or the error the search would get on its own, unbilled. */
47
+ export interface SearchResponse {
48
+ results?: Place[];
49
+ attribution?: Attribution[];
50
+ error?: {
51
+ code: string;
52
+ message: string;
53
+ };
54
+ }
55
+ export interface SearchBatch {
56
+ /** One per query, in the queries' order. */
57
+ responses: SearchResponse[];
58
+ }
38
59
  export interface PlaceResult {
39
60
  result: Place;
40
61
  attribution: Attribution[];
@@ -55,6 +76,8 @@ export interface Step {
55
76
  lon: number;
56
77
  }
57
78
  export interface Route {
79
+ /** From `routing.optimize` only: the indexes of the waypoints you sent, in the order the route visits them. */
80
+ waypointOrder?: number[];
58
81
  distanceMeters: number;
59
82
  durationSeconds: number;
60
83
  /** Encoded polyline, with five decimal places unless `geometries` was `polyline6`. Absent for `geojson`. */
@@ -157,6 +180,8 @@ export declare class Mapricot {
157
180
  readonly geocoding: {
158
181
  /** Find addresses and places matching free text. */
159
182
  search: (q: string, { signal, ...options }?: SearchOptions) => Promise<Places>;
183
+ /** Run up to 100 searches in one request. Each completed search is billed as one request. */
184
+ searchBatch: (queries: SearchQuery[], { signal }?: RequestOptions) => Promise<SearchBatch>;
160
185
  /** Suggest addresses and places as someone types. */
161
186
  autocomplete: (q: string, { signal, ...options }?: SearchOptions) => Promise<Places>;
162
187
  /** Find the address nearest a coordinate, or the area around it. */
@@ -178,6 +203,13 @@ export declare class Mapricot {
178
203
  steps?: boolean;
179
204
  lang?: string;
180
205
  }) => Promise<Routes>;
206
+ /** Find a fast route through 2 to 20 waypoints, keeping the first and last in place and reordering the rest. */
207
+ optimize: (waypoints: Point[], { signal, ...options }?: RequestOptions & {
208
+ mode?: "drive" | "walk" | "bicycle";
209
+ geometries?: "polyline" | "polyline6" | "geojson";
210
+ steps?: boolean;
211
+ lang?: string;
212
+ }) => Promise<Routes>;
181
213
  /** The areas reachable from a location within 1 to 4 times, each 1 to 60 minutes. */
182
214
  isochrone: (location: Point, minutes: number[], { signal, ...options }?: RequestOptions & {
183
215
  mode?: "drive" | "walk" | "bicycle";
package/dist/index.js CHANGED
@@ -30,6 +30,10 @@ export class Mapricot {
30
30
  this.geocoding = {
31
31
  /** Find addresses and places matching free text. */
32
32
  search: (q, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/geocoding/v1/search", { q, ...options }, signal),
33
+ /** Run up to 100 searches in one request. Each completed search is billed as one request. */
34
+ searchBatch: (queries, { signal } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "POST", "/geocoding/v1/search/batch", {}, signal, {
35
+ queries: queries.map((query) => Object.fromEntries(Object.entries(query).map(([name, value]) => [name, format(value)]))),
36
+ }),
33
37
  /** Suggest addresses and places as someone types. */
34
38
  autocomplete: (q, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/geocoding/v1/autocomplete", { q, ...options }, signal),
35
39
  /** Find the address nearest a coordinate, or the area around it. */
@@ -44,6 +48,8 @@ export class Mapricot {
44
48
  this.routing = {
45
49
  /** Find a route through 2 to 20 waypoints. */
46
50
  route: (waypoints, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "POST", "/routing/v1/route", {}, signal, { waypoints, ...options }),
51
+ /** Find a fast route through 2 to 20 waypoints, keeping the first and last in place and reordering the rest. */
52
+ optimize: (waypoints, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "POST", "/routing/v1/optimize", {}, signal, { waypoints, ...options }),
47
53
  /** The areas reachable from a location within 1 to 4 times, each 1 to 60 minutes. */
48
54
  isochrone: (location, minutes, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "POST", "/routing/v1/isochrone", {}, signal, { location, minutes, ...options }),
49
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapricot",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "Official client for the Mapricot API: geocoding, places, routing, and IP geolocation.",
5
5
  "keywords": [
6
6
  "geocoding",