mapricot 0.1.1 → 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 +4 -8
- package/dist/index.d.ts +2 -3
- package/dist/index.js +4 -5
- package/package.json +1 -1
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
|
|
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
|
-
|
|
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/
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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;
|