mapricot 0.7.0 → 0.9.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
@@ -17,7 +17,7 @@ import { Mapricot } from "mapricot";
17
17
 
18
18
  const client = new Mapricot({ apiKey: process.env.MAPRICOT_KEY });
19
19
 
20
- const { results } = await client.search("128 SW 3rd Ave, Portland", { limit: 1 });
20
+ const { results } = await client.geocoding.search("128 SW 3rd Ave, Portland", { limit: 1 });
21
21
  console.log(results[0].label, results[0].lat, results[0].lon);
22
22
  ```
23
23
 
@@ -25,25 +25,25 @@ 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
- Each method 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/api-reference/).
29
29
 
30
30
  | Method | Endpoint |
31
31
  | --- | --- |
32
- | `client.search(q, { focus, country, limit, lang })` | [`GET /geocoding/v1/search`](https://mapricot.com/docs/geocoding/#find-an-address) |
33
- | `client.autocomplete(q, { focus, country, limit, lang })` | [`GET /geocoding/v1/autocomplete`](https://mapricot.com/docs/geocoding/#suggest-as-people-type) |
34
- | `client.reverse(lat, lon, { limit, lang })` | [`GET /geocoding/v1/reverse`](https://mapricot.com/docs/geocoding/#find-the-address-at-a-point) |
35
- | `client.nearby(lat, lon, { category, radius, limit, lang })` | [`GET /places/v1/nearby`](https://mapricot.com/docs/places/#list-places-around-a-point) |
36
- | `client.place(id, { lang })` | [`GET /places/v1/{id}`](https://mapricot.com/docs/places/#look-up-a-saved-place) |
37
- | `client.route(waypoints, { mode, geometries })` | [`POST /routing/v1/route`](https://mapricot.com/docs/routing/#get-a-route) |
38
- | `client.isochrone(location, minutes, { mode })` | [`POST /routing/v1/isochrone`](https://mapricot.com/docs/routing/#get-an-isochrone) |
39
- | `client.ip(address)` | [`GET /ip-geolocation/v1/{ip}`](https://mapricot.com/docs/ip-geolocation/#look-up-an-address) |
32
+ | `client.geocoding.search(q, { focus, country, limit, lang })` | [`GET /geocoding/v1/search`](https://mapricot.com/docs/geocoding/#find-an-address) |
33
+ | `client.geocoding.autocomplete(q, { focus, country, limit, lang })` | [`GET /geocoding/v1/autocomplete`](https://mapricot.com/docs/geocoding/#suggest-as-people-type) |
34
+ | `client.geocoding.reverse(lat, lon, { limit, lang })` | [`GET /geocoding/v1/reverse`](https://mapricot.com/docs/geocoding/#find-the-address-at-a-point) |
35
+ | `client.places.nearby(lat, lon, { category, radius, limit, lang })` | [`GET /places/v1/nearby`](https://mapricot.com/docs/places/#list-places-around-a-point) |
36
+ | `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.isochrone(location, minutes, { mode })` | [`POST /routing/v1/isochrone`](https://mapricot.com/docs/routing/#get-an-isochrone) |
39
+ | `client.ipGeolocation.lookup(ip)` | [`GET /ip-geolocation/v1/{ip}`](https://mapricot.com/docs/ip-geolocation/#look-up-an-address) |
40
40
  | `client.account()` | `GET /account`, which checks a key and is never billed |
41
41
 
42
42
  `focus` and each waypoint are `{ lat, lon }`. `country` and `category` take an array or a comma-separated string.
43
43
 
44
44
  ```js
45
- const nearby = await client.nearby(45.52, -122.68, { category: ["food:coffee_shop"], radius: 1000 });
46
- const { routes } = await client.route([{ lat: 45.5189, lon: -122.6793 }, { lat: 45.5214, lon: -122.6828 }], { mode: "walk" });
45
+ const nearby = await client.places.nearby(45.52, -122.68, { category: ["food:coffee_shop"], radius: 1000 });
46
+ const { routes } = await client.routing.route([{ lat: 45.5189, lon: -122.6793 }, { lat: 45.5214, lon: -122.6828 }], { mode: "walk" });
47
47
  console.log(routes[0].durationSeconds);
48
48
  ```
49
49
 
@@ -51,7 +51,7 @@ To cancel a request, such as an autocomplete request for text that has since cha
51
51
 
52
52
  ```js
53
53
  const controller = new AbortController();
54
- const request = client.autocomplete("1005 W Burn", { signal: controller.signal });
54
+ const request = client.geocoding.autocomplete("1005 W Burn", { signal: controller.signal });
55
55
  controller.abort();
56
56
  ```
57
57
 
@@ -60,10 +60,12 @@ A route's path comes as an encoded `polyline` with five decimal places, which po
60
60
  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
61
 
62
62
  ```js
63
- const area = await client.isochrone({ lat: 45.5189, lon: -122.6793 }, [5, 10], { mode: "walk" });
63
+ const area = await client.routing.isochrone({ lat: 45.5189, lon: -122.6793 }, [5, 10], { mode: "walk" });
64
64
  map.addSource("reach", { type: "geojson", data: area });
65
65
  ```
66
66
 
67
+ 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"`.
68
+
67
69
  If your app shows results, show the credits in each response's `attribution`.
68
70
 
69
71
  ## Errors and retries
@@ -74,7 +76,7 @@ An error response throws `MapricotError`, with the HTTP `status`, the API's erro
74
76
  import { MapricotError } from "mapricot";
75
77
 
76
78
  try {
77
- await client.search("");
79
+ await client.geocoding.search("");
78
80
  } catch (error) {
79
81
  if (!(error instanceof MapricotError)) throw error;
80
82
  console.log(error.status, error.code, error.message); // 400 invalid_request The service rejected the request.
package/dist/index.d.ts CHANGED
@@ -36,6 +36,17 @@ export interface PlaceResult {
36
36
  export interface Leg {
37
37
  distanceMeters: number;
38
38
  durationSeconds: number;
39
+ /** Turn-by-turn directions, in order, when the route was asked for with `steps: true`. The last step is the arrival. */
40
+ steps?: Step[];
41
+ }
42
+ /** One maneuver, and the stretch from it to the next. */
43
+ export interface Step {
44
+ instruction: string;
45
+ distanceMeters: number;
46
+ durationSeconds: number;
47
+ /** Where the maneuver is, on the route's path. */
48
+ lat: number;
49
+ lon: number;
39
50
  }
40
51
  export interface Route {
41
52
  distanceMeters: number;
@@ -137,29 +148,39 @@ export declare class MapricotError extends Error {
137
148
  export declare class Mapricot {
138
149
  #private;
139
150
  constructor(options: ClientOptions);
140
- /** Find addresses and places matching free text. */
141
- search(q: string, { signal, ...options }?: SearchOptions): Promise<Places>;
142
- /** Suggest addresses and places as someone types. */
143
- autocomplete(q: string, { signal, ...options }?: SearchOptions): Promise<Places>;
144
- /** Find the address nearest a coordinate, or the area around it. */
145
- reverse(lat: number, lon: number, { signal, ...options }?: ReverseOptions): Promise<Places>;
146
- /** List places around a coordinate, optionally by category. */
147
- nearby(lat: number, lon: number, { signal, ...options }?: NearbyOptions): Promise<Places>;
148
- /** Look up one place by its Mapricot ID. */
149
- place(id: string, { signal, ...options }?: RequestOptions & {
150
- lang?: string;
151
- }): Promise<PlaceResult>;
152
- /** Find a route through 2 to 20 waypoints. */
153
- route(waypoints: Point[], { signal, ...options }?: RequestOptions & {
154
- mode?: "drive" | "walk" | "bicycle";
155
- geometries?: "polyline" | "polyline6" | "geojson";
156
- }): Promise<Routes>;
157
- /** The areas reachable from a location within 1 to 4 times, each 1 to 60 minutes. */
158
- isochrone(location: Point, minutes: number[], { signal, ...options }?: RequestOptions & {
159
- mode?: "drive" | "walk" | "bicycle";
160
- }): Promise<Isochrones>;
161
- /** Approximate location of a public IP address. */
162
- ip(address: string, { signal }?: RequestOptions): Promise<IpLocation>;
151
+ readonly geocoding: {
152
+ /** Find addresses and places matching free text. */
153
+ search: (q: string, { signal, ...options }?: SearchOptions) => Promise<Places>;
154
+ /** Suggest addresses and places as someone types. */
155
+ autocomplete: (q: string, { signal, ...options }?: SearchOptions) => Promise<Places>;
156
+ /** Find the address nearest a coordinate, or the area around it. */
157
+ reverse: (lat: number, lon: number, { signal, ...options }?: ReverseOptions) => Promise<Places>;
158
+ };
159
+ readonly places: {
160
+ /** List places around a coordinate, optionally by category. */
161
+ nearby: (lat: number, lon: number, { signal, ...options }?: NearbyOptions) => Promise<Places>;
162
+ /** Look up one place by its Mapricot ID. */
163
+ get: (id: string, { signal, ...options }?: RequestOptions & {
164
+ lang?: string;
165
+ }) => Promise<PlaceResult>;
166
+ };
167
+ readonly routing: {
168
+ /** Find a route through 2 to 20 waypoints. */
169
+ route: (waypoints: Point[], { signal, ...options }?: RequestOptions & {
170
+ mode?: "drive" | "walk" | "bicycle";
171
+ geometries?: "polyline" | "polyline6" | "geojson";
172
+ steps?: boolean;
173
+ lang?: string;
174
+ }) => Promise<Routes>;
175
+ /** The areas reachable from a location within 1 to 4 times, each 1 to 60 minutes. */
176
+ isochrone: (location: Point, minutes: number[], { signal, ...options }?: RequestOptions & {
177
+ mode?: "drive" | "walk" | "bicycle";
178
+ }) => Promise<Isochrones>;
179
+ };
180
+ readonly ipGeolocation: {
181
+ /** Approximate location of a public IP address. */
182
+ lookup: (ip: string, { signal }?: RequestOptions) => Promise<IpLocation>;
183
+ };
163
184
  /** The key's account. Not billed, so it checks a key for free. */
164
185
  account({ signal }?: RequestOptions): Promise<Account>;
165
186
  }
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
1
6
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
7
  if (kind === "m") throw new TypeError("Private method is not writable");
3
8
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
11
  };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
12
  var _Mapricot_instances, _Mapricot_apiKey, _Mapricot_baseUrl, _Mapricot_timeout, _Mapricot_maxRetries, _Mapricot_request;
13
13
  export class MapricotError extends Error {
14
14
  constructor(status, code, message, requestId) {
@@ -27,6 +27,30 @@ export class Mapricot {
27
27
  _Mapricot_baseUrl.set(this, void 0);
28
28
  _Mapricot_timeout.set(this, void 0);
29
29
  _Mapricot_maxRetries.set(this, void 0);
30
+ this.geocoding = {
31
+ /** Find addresses and places matching free text. */
32
+ search: (q, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/geocoding/v1/search", { q, ...options }, signal),
33
+ /** Suggest addresses and places as someone types. */
34
+ autocomplete: (q, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/geocoding/v1/autocomplete", { q, ...options }, signal),
35
+ /** Find the address nearest a coordinate, or the area around it. */
36
+ reverse: (lat, lon, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/geocoding/v1/reverse", { lat, lon, ...options }, signal),
37
+ };
38
+ this.places = {
39
+ /** List places around a coordinate, optionally by category. */
40
+ nearby: (lat, lon, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/places/v1/nearby", { lat, lon, ...options }, signal),
41
+ /** Look up one place by its Mapricot ID. */
42
+ get: (id, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", `/places/v1/${encodeURIComponent(id)}`, options, signal),
43
+ };
44
+ this.routing = {
45
+ /** Find a route through 2 to 20 waypoints. */
46
+ route: (waypoints, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "POST", "/routing/v1/route", {}, signal, { waypoints, ...options }),
47
+ /** The areas reachable from a location within 1 to 4 times, each 1 to 60 minutes. */
48
+ isochrone: (location, minutes, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "POST", "/routing/v1/isochrone", {}, signal, { location, minutes, ...options }),
49
+ };
50
+ this.ipGeolocation = {
51
+ /** Approximate location of a public IP address. */
52
+ lookup: (ip, { signal } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", `/ip-geolocation/v1/${encodeURIComponent(ip)}`, {}, signal),
53
+ };
30
54
  if (!(options === null || options === void 0 ? void 0 : options.apiKey))
31
55
  throw new Error("Pass apiKey, a Mapricot key.");
32
56
  __classPrivateFieldSet(this, _Mapricot_apiKey, options.apiKey, "f");
@@ -34,38 +58,6 @@ export class Mapricot {
34
58
  __classPrivateFieldSet(this, _Mapricot_timeout, (_b = options.timeout) !== null && _b !== void 0 ? _b : 30000, "f");
35
59
  __classPrivateFieldSet(this, _Mapricot_maxRetries, (_c = options.maxRetries) !== null && _c !== void 0 ? _c : 2, "f");
36
60
  }
37
- /** Find addresses and places matching free text. */
38
- search(q, { signal, ...options } = {}) {
39
- return __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/geocoding/v1/search", { q, ...options }, signal);
40
- }
41
- /** Suggest addresses and places as someone types. */
42
- autocomplete(q, { signal, ...options } = {}) {
43
- return __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/geocoding/v1/autocomplete", { q, ...options }, signal);
44
- }
45
- /** Find the address nearest a coordinate, or the area around it. */
46
- reverse(lat, lon, { signal, ...options } = {}) {
47
- return __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/geocoding/v1/reverse", { lat, lon, ...options }, signal);
48
- }
49
- /** List places around a coordinate, optionally by category. */
50
- nearby(lat, lon, { signal, ...options } = {}) {
51
- return __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/places/v1/nearby", { lat, lon, ...options }, signal);
52
- }
53
- /** Look up one place by its Mapricot ID. */
54
- place(id, { signal, ...options } = {}) {
55
- return __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", `/places/v1/${encodeURIComponent(id)}`, options, signal);
56
- }
57
- /** Find a route through 2 to 20 waypoints. */
58
- route(waypoints, { signal, ...options } = {}) {
59
- return __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "POST", "/routing/v1/route", {}, signal, { waypoints, ...options });
60
- }
61
- /** The areas reachable from a location within 1 to 4 times, each 1 to 60 minutes. */
62
- isochrone(location, minutes, { signal, ...options } = {}) {
63
- return __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "POST", "/routing/v1/isochrone", {}, signal, { location, minutes, ...options });
64
- }
65
- /** Approximate location of a public IP address. */
66
- ip(address, { signal } = {}) {
67
- return __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", `/ip-geolocation/v1/${encodeURIComponent(address)}`, {}, signal);
68
- }
69
61
  /** The key's account. Not billed, so it checks a key for free. */
70
62
  account({ signal } = {}) {
71
63
  return __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/account", {}, signal);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapricot",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Official client for the Mapricot API: geocoding, places, routing, and IP geolocation.",
5
5
  "keywords": [
6
6
  "geocoding",