mapricot 0.1.0 → 0.2.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
@@ -10,22 +10,18 @@ It uses the built-in `fetch`, so it has no dependencies and runs in Node.js 20 a
10
10
 
11
11
  ## Quick start
12
12
 
13
- Create a server key in the [dashboard](https://app.mapricot.com/) and set it as `MAPRICOT_KEY`:
14
-
15
- ```sh
16
- export MAPRICOT_KEY="mapricot_sk_…"
17
- ```
13
+ Create a server key in the [dashboard](https://app.mapricot.com/) and pass it to the client. Keep it out of your source code, for example by reading it from an environment variable as here.
18
14
 
19
15
  ```js
20
16
  import { Mapricot } from "mapricot";
21
17
 
22
- const client = new Mapricot();
18
+ const client = new Mapricot({ apiKey: process.env.MAPRICOT_KEY });
23
19
 
24
20
  const { results } = await client.search("128 SW 3rd Ave, Portland", { limit: 1 });
25
21
  console.log(results[0].label, results[0].lat, results[0].lon);
26
22
  ```
27
23
 
28
- Pass the key yourself with `new Mapricot({ apiKey: "mapricot_sk_…" })`. In a web page, use a browser key, which works only from the origins you allow, and keep server keys on your server.
24
+ In a web page, use a browser key, which works only from the origins you allow, and keep server keys on your server.
29
25
 
30
26
  ## Methods
31
27
 
@@ -50,7 +46,7 @@ const { routes } = await client.route([{ lat: 45.5189, lon: -122.6793 }, { lat:
50
46
  console.log(routes[0].durationSeconds);
51
47
  ```
52
48
 
53
- A route's `polyline` is encoded with six decimal places. Decode it with precision 6, as [decoding a route polyline](https://mapricot.com/docs/polyline/) shows.
49
+ A route's `polyline` is encoded with six decimal places. Decode it with precision 6, as [decoding a route polyline](https://mapricot.com/guides/polyline-decoder/) shows.
54
50
 
55
51
  If your app shows results, show the credits in each response's `attribution`.
56
52
 
package/dist/index.d.ts CHANGED
@@ -90,8 +90,7 @@ export interface NearbyOptions {
90
90
  lang?: string;
91
91
  }
92
92
  export interface ClientOptions {
93
- /** Defaults to the MAPRICOT_KEY environment variable. */
94
- apiKey?: string;
93
+ apiKey: string;
95
94
  baseUrl?: string;
96
95
  /** Milliseconds per attempt. */
97
96
  timeout?: number;
@@ -106,7 +105,7 @@ export declare class MapricotError extends Error {
106
105
  }
107
106
  export declare class Mapricot {
108
107
  #private;
109
- constructor(options?: ClientOptions);
108
+ constructor(options: ClientOptions);
110
109
  /** Find addresses and places matching free text. */
111
110
  search(q: string, options?: SearchOptions): Promise<Places>;
112
111
  /** Suggest addresses and places as someone types. */
package/dist/index.js CHANGED
@@ -15,11 +15,10 @@ export class Mapricot {
15
15
  #baseUrl;
16
16
  #timeout;
17
17
  #maxRetries;
18
- constructor(options = {}) {
19
- const apiKey = options.apiKey ?? globalThis.process?.env?.MAPRICOT_KEY;
20
- if (!apiKey)
21
- throw new Error("Pass apiKey or set MAPRICOT_KEY.");
22
- this.#apiKey = apiKey;
18
+ constructor(options) {
19
+ if (!options?.apiKey)
20
+ throw new Error("Pass apiKey, a Mapricot key.");
21
+ this.#apiKey = options.apiKey;
23
22
  this.#baseUrl = options.baseUrl ?? "https://api.mapricot.com";
24
23
  this.#timeout = options.timeout ?? 30_000;
25
24
  this.#maxRetries = options.maxRetries ?? 2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapricot",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Official client for the Mapricot API: geocoding, places, routing, and IP geolocation.",
5
5
  "keywords": [
6
6
  "geocoding",
@@ -12,10 +12,9 @@
12
12
  "homepage": "https://mapricot.com/docs/node/",
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "git+https://github.com/mapricothq/mapricot.git",
16
- "directory": "sdks/js"
15
+ "url": "git+https://github.com/mapricothq/mapricot-js.git"
17
16
  },
18
- "bugs": "https://github.com/mapricothq/mapricot/issues",
17
+ "bugs": "https://github.com/mapricothq/mapricot-js/issues",
19
18
  "license": "MIT",
20
19
  "type": "module",
21
20
  "exports": "./dist/index.js",