mapricot 0.11.0 → 0.13.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
@@ -25,18 +25,19 @@ In a web page, use a browser key, which works only from the origins you allow, a
25
25
 
26
26
  ## Methods
27
27
 
28
- Methods are grouped by product, the same way as the API's paths. Each returns the API's JSON, typed, with the same field names as the [API reference](https://mapricot.com/api-reference/).
28
+ Methods are grouped by product, the same way as the API's paths. Each returns the API's JSON, typed, with the same field names as the [API reference](https://mapricot.com/docs/api-reference/).
29
29
 
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
- | `client.routing.route(waypoints, { mode, geometries, steps, lang })` | [`POST /routing/v1/route`](https://mapricot.com/docs/routing/#get-a-route) |
38
- | `client.routing.optimize(waypoints, { mode, geometries, steps, lang })` | [`POST /routing/v1/optimize`](https://mapricot.com/docs/routing/#optimize-the-order-of-stops) |
39
- | `client.routing.isochrone(location, minutes, { mode })` | [`POST /routing/v1/isochrone`](https://mapricot.com/docs/routing/#get-an-isochrone) |
38
+ | `client.routing.route(waypoints, { mode, geometries, steps, lang, costing })` | [`POST /routing/v1/route`](https://mapricot.com/docs/routing/#get-a-route) |
39
+ | `client.routing.optimize(waypoints, { mode, geometries, steps, lang, costing })` | [`POST /routing/v1/optimize`](https://mapricot.com/docs/routing/#optimize-the-order-of-stops) |
40
+ | `client.routing.isochrone(location, minutes, { mode, costing })` | [`POST /routing/v1/isochrone`](https://mapricot.com/docs/routing/#get-an-isochrone) |
40
41
  | `client.ipGeolocation.lookup(ip)` | [`GET /ip-geolocation/v1/{ip}`](https://mapricot.com/docs/ip-geolocation/#look-up-an-address) |
41
42
  | `client.account()` | `GET /account`, which checks a key and is never billed |
42
43
 
@@ -48,6 +49,13 @@ const { routes } = await client.routing.route([{ lat: 45.5189, lon: -122.6793 },
48
49
  console.log(routes[0].durationSeconds);
49
50
  ```
50
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
+
51
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`:
52
60
 
53
61
  ```js
@@ -69,6 +77,8 @@ map.addSource("reach", { type: "geojson", data: area });
69
77
 
70
78
  Pass `steps: true` and each leg's `steps` has its turn-by-turn directions: an `instruction`, its distance and time, and its `lat` and `lon`. They're in English unless you pass `lang`, such as `lang: "fr"`.
71
79
 
80
+ `costing` changes how a route, optimized route, or isochrone picks its roads, with Valhalla's [costing options](https://mapricot.com/docs/routing/#costing-options) for the mode, such as `{ useTolls: 0, useHighways: 0 }` to drive avoiding tolls and highways where it can.
81
+
72
82
  If your app shows results, show the credits in each response's `attribution`.
73
83
 
74
84
  ## Errors and retries
@@ -86,11 +96,11 @@ try {
86
96
  }
87
97
  ```
88
98
 
89
- The client retries `503` responses and `429 concurrency_exceeded`, up to twice, waiting longer each time. Errors aren't billed. Set `maxRetries` and `timeout` (milliseconds) in the constructor's options to change this. The [API reference](https://mapricot.com/api-reference/#errors) lists every status.
99
+ The client retries `503` responses and `429 concurrency_exceeded`, up to twice, waiting longer each time. Errors aren't billed. Set `maxRetries` and `timeout` (milliseconds) in the constructor's options to change this. The [API reference](https://mapricot.com/docs/api-reference/#errors) lists every status.
90
100
 
91
101
  ## Links
92
102
 
93
103
  - [Mapricot](https://mapricot.com/)
94
104
  - [Node.js docs](https://mapricot.com/docs/node/)
95
- - [API reference](https://mapricot.com/api-reference/)
105
+ - [API reference](https://mapricot.com/docs/api-reference/)
96
106
  - [Pricing](https://mapricot.com/pricing/)
package/dist/index.d.ts CHANGED
@@ -35,10 +35,33 @@ 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[];
41
62
  }
63
+ /** Valhalla's costing options for the mode, named in camelCase, such as `{ useTolls: 0 }`. See https://mapricot.com/docs/routing/#costing-options. */
64
+ export type Costing = Record<string, number | boolean | string>;
42
65
  export interface Leg {
43
66
  distanceMeters: number;
44
67
  durationSeconds: number;
@@ -159,6 +182,8 @@ export declare class Mapricot {
159
182
  readonly geocoding: {
160
183
  /** Find addresses and places matching free text. */
161
184
  search: (q: string, { signal, ...options }?: SearchOptions) => Promise<Places>;
185
+ /** Run up to 100 searches in one request. Each completed search is billed as one request. */
186
+ searchBatch: (queries: SearchQuery[], { signal }?: RequestOptions) => Promise<SearchBatch>;
162
187
  /** Suggest addresses and places as someone types. */
163
188
  autocomplete: (q: string, { signal, ...options }?: SearchOptions) => Promise<Places>;
164
189
  /** Find the address nearest a coordinate, or the area around it. */
@@ -179,6 +204,7 @@ export declare class Mapricot {
179
204
  geometries?: "polyline" | "polyline6" | "geojson";
180
205
  steps?: boolean;
181
206
  lang?: string;
207
+ costing?: Costing;
182
208
  }) => Promise<Routes>;
183
209
  /** Find a fast route through 2 to 20 waypoints, keeping the first and last in place and reordering the rest. */
184
210
  optimize: (waypoints: Point[], { signal, ...options }?: RequestOptions & {
@@ -186,10 +212,12 @@ export declare class Mapricot {
186
212
  geometries?: "polyline" | "polyline6" | "geojson";
187
213
  steps?: boolean;
188
214
  lang?: string;
215
+ costing?: Costing;
189
216
  }) => Promise<Routes>;
190
217
  /** The areas reachable from a location within 1 to 4 times, each 1 to 60 minutes. */
191
218
  isochrone: (location: Point, minutes: number[], { signal, ...options }?: RequestOptions & {
192
219
  mode?: "drive" | "walk" | "bicycle";
220
+ costing?: Costing;
193
221
  }) => Promise<Isochrones>;
194
222
  };
195
223
  readonly ipGeolocation: {
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. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapricot",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "Official client for the Mapricot API: geocoding, places, routing, and IP geolocation.",
5
5
  "keywords": [
6
6
  "geocoding",