mapricot 0.14.0 → 0.15.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
@@ -29,7 +29,7 @@ Methods are grouped by product, the same way as the API's paths. Each returns th
29
29
 
30
30
  | Method | Endpoint |
31
31
  | --- | --- |
32
- | `client.geocoding.search(q, { focus, country, limit, lang })` | [`GET /geocoding/v1/search`](https://mapricot.com/docs/geocoding/#find-an-address) |
32
+ | `client.geocoding.search(q or { address, locality, county, region, postalCode }, { focus, country, limit, lang })` | [`GET /geocoding/v1/search`](https://mapricot.com/docs/geocoding/#find-an-address) |
33
33
  | `client.geocoding.searchBatch(queries)` | [`POST /geocoding/v1/search/batch`](https://mapricot.com/docs/geocoding/#search-a-list-of-addresses) |
34
34
  | `client.geocoding.autocomplete(q, { focus, country, limit, lang })` | [`GET /geocoding/v1/autocomplete`](https://mapricot.com/docs/geocoding/#suggest-as-people-type) |
35
35
  | `client.geocoding.reverse(lat, lon, { limit, lang })` | [`GET /geocoding/v1/reverse`](https://mapricot.com/docs/geocoding/#find-the-address-at-a-point) |
@@ -49,7 +49,13 @@ const { routes } = await client.routing.route([{ lat: 45.5189, lon: -122.6793 },
49
49
  console.log(routes[0].durationSeconds);
50
50
  ```
51
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.
52
+ When you already have an address in parts, such as a spreadsheet's columns, pass them in place of the text. Search ignores a blank part:
53
+
54
+ ```js
55
+ const { results } = await client.geocoding.search({ address: "10 Downing Street", locality: "London", postalCode: "SW1A 2AA" }, { country: "GB" });
56
+ ```
57
+
58
+ `searchBatch` runs up to 100 searches in one request. Each query is an object of `search`'s parameters, with `q` or the address parts, 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
59
 
54
60
  ```js
55
61
  const { responses } = await client.geocoding.searchBatch([{ q: "128 SW 3rd Ave, Portland", limit: 1 }, { q: "10 Downing Street, London", limit: 1 }]);
package/dist/index.d.ts CHANGED
@@ -35,9 +35,20 @@ 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;
38
+ /** An address in parts, such as a spreadsheet's columns, which search takes in place of free text. */
39
+ export interface AddressParts {
40
+ /** The street line: house number, street, and any unit or building. */
41
+ address?: string;
42
+ /** The town or city. */
43
+ locality?: string;
44
+ county?: string;
45
+ /** The state, province, or region. */
46
+ region?: string;
47
+ postalCode?: string;
48
+ }
49
+ /** One search in a batch, with the same parameters as `geocoding.search`: `q`, or an address in parts. */
50
+ export interface SearchQuery extends AddressParts {
51
+ q?: string;
41
52
  focus?: Point;
42
53
  country?: string | string[];
43
54
  limit?: number;
@@ -180,8 +191,8 @@ export declare class Mapricot {
180
191
  #private;
181
192
  constructor(options: ClientOptions);
182
193
  readonly geocoding: {
183
- /** Find addresses and places matching free text. */
184
- search: (q: string, { signal, ...options }?: SearchOptions) => Promise<Places>;
194
+ /** Find addresses and places matching free text, or an address given in parts. */
195
+ search: (query: string | AddressParts, { signal, ...options }?: SearchOptions) => Promise<Places>;
185
196
  /** Run up to 100 searches in one request. Each completed search is billed as one request. */
186
197
  searchBatch: (queries: SearchQuery[], { signal }?: RequestOptions) => Promise<SearchBatch>;
187
198
  /** Suggest addresses and places as someone types. */
package/dist/index.js CHANGED
@@ -28,8 +28,8 @@ export class Mapricot {
28
28
  _Mapricot_timeout.set(this, void 0);
29
29
  _Mapricot_maxRetries.set(this, void 0);
30
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),
31
+ /** Find addresses and places matching free text, or an address given in parts. */
32
+ search: (query, { signal, ...options } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "GET", "/geocoding/v1/search", { ...(typeof query === "string" ? { q: query } : query), ...options }, signal),
33
33
  /** Run up to 100 searches in one request. Each completed search is billed as one request. */
34
34
  searchBatch: (queries, { signal } = {}) => __classPrivateFieldGet(this, _Mapricot_instances, "m", _Mapricot_request).call(this, "POST", "/geocoding/v1/search/batch", {}, signal, {
35
35
  queries: queries.map((query) => Object.fromEntries(Object.entries(query).map(([name, value]) => [name, format(value)]))),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapricot",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Official client for the Mapricot API: geocoding, places, routing, and IP geolocation.",
5
5
  "keywords": [
6
6
  "geocoding",