ola-map-sdk 1.1.5 → 2.0.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.
Files changed (52) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +380 -137
  3. package/dist/chunk-22747AE4.js +978 -0
  4. package/dist/chunk-22747AE4.js.map +1 -0
  5. package/dist/chunk-5YVHNDSA.cjs +282 -0
  6. package/dist/chunk-5YVHNDSA.cjs.map +1 -0
  7. package/dist/chunk-6J7XUGWD.cjs +443 -0
  8. package/dist/chunk-6J7XUGWD.cjs.map +1 -0
  9. package/dist/chunk-7LV3RPED.js +440 -0
  10. package/dist/chunk-7LV3RPED.js.map +1 -0
  11. package/dist/chunk-D5T5ZDIQ.js +268 -0
  12. package/dist/chunk-D5T5ZDIQ.js.map +1 -0
  13. package/dist/chunk-SJJRTEQG.js +94 -0
  14. package/dist/chunk-SJJRTEQG.js.map +1 -0
  15. package/dist/chunk-WLUKC7YU.cjs +991 -0
  16. package/dist/chunk-WLUKC7YU.cjs.map +1 -0
  17. package/dist/chunk-XRJXKY7C.cjs +100 -0
  18. package/dist/chunk-XRJXKY7C.cjs.map +1 -0
  19. package/dist/client-Cd22y5wG.d.cts +782 -0
  20. package/dist/client-DsBMyuG9.d.ts +782 -0
  21. package/dist/common-Bt8xNzhK.d.cts +115 -0
  22. package/dist/common-Bt8xNzhK.d.ts +115 -0
  23. package/dist/index.cjs +115 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +88 -0
  26. package/dist/index.d.ts +88 -0
  27. package/dist/index.js +12 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/maplibre/index.cjs +29 -0
  30. package/dist/maplibre/index.cjs.map +1 -0
  31. package/dist/maplibre/index.d.cts +63 -0
  32. package/dist/maplibre/index.d.ts +63 -0
  33. package/dist/maplibre/index.js +4 -0
  34. package/dist/maplibre/index.js.map +1 -0
  35. package/dist/next/index.cjs +173 -0
  36. package/dist/next/index.cjs.map +1 -0
  37. package/dist/next/index.d.cts +65 -0
  38. package/dist/next/index.d.ts +65 -0
  39. package/dist/next/index.js +169 -0
  40. package/dist/next/index.js.map +1 -0
  41. package/dist/react/index.cjs +257 -0
  42. package/dist/react/index.cjs.map +1 -0
  43. package/dist/react/index.d.cts +77 -0
  44. package/dist/react/index.d.ts +77 -0
  45. package/dist/react/index.js +251 -0
  46. package/dist/react/index.js.map +1 -0
  47. package/package.json +126 -11
  48. package/src/client.js +0 -37
  49. package/src/endpoints/places.js +0 -38
  50. package/src/endpoints/routing.js +0 -39
  51. package/src/endpoints/tiles.js +0 -55
  52. package/src/index.js +0 -4
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Kunal Kongkan Kashyap
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Kunal Kongkan Kashyap
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,137 +1,380 @@
1
- # Ola Map SDK
2
- Ola Map SDK is a Node.js package that provides an easy-to-use interface for interacting with the Ola Maps API. This SDK allows you to perform various operations like geocoding, reverse geocoding, fetching map tiles, and getting routing directions.
3
-
4
- ## Installation
5
- Install the package using npm:
6
-
7
- ```bash
8
- npm install ola-map-sdk
9
- ```
10
-
11
- ## Usage
12
- First, you need to require the SDK and create an instance of the OlaMapsClient class with your API key.
13
-
14
- ```javascript
15
- const OlaMapsClient = require('ola-map-sdk');
16
-
17
- const apiKey = 'YOUR_API_KEY';
18
- const client = new OlaMapsClient(apiKey);
19
- ```
20
-
21
- ### Places API
22
- API for accessing geolocation services such as places autocomplete, reverse geocode.
23
-
24
- - **Autocomplete** - Provides Autocomplete suggestions for a given substring satisfying the given criteria.
25
-
26
- ```javascript
27
- try {
28
- const result = await client.places.autocomplete('Gauhati University');
29
- console.log('Autocomplete result:', result);
30
- } catch (error) {
31
- console.error('Error during autocomplete:', error);
32
- }
33
- ```
34
-
35
- - **Geocode** - Returns the geocoded address based on the provided parameters.
36
-
37
- ```javascript
38
- try {
39
- const result = await client.places.geocode('Taj Mahal, Mumbai');
40
- console.log('Geocode result:', result);
41
- } catch (error) {
42
- console.error('Error during geocoding:', error);
43
- }
44
- ```
45
-
46
- - **Reverse Geocode** - Provides information of a place based on the location provided satisfying the given criteria.
47
-
48
- ```javascript
49
- try {
50
- const result = await client.places.reverseGeocode(26.115103, 91.703239);
51
- console.log('Reverse Geocode result:', result);
52
- } catch (error) {
53
- console.error('Error during reverse geocoding:', error);
54
- }
55
- ```
56
-
57
- ### Direction API
58
-
59
- - **Get Directions** - Provides routable path between two or more points. Accepts coordinates in lat,long format.
60
-
61
- ```javascript
62
- try {
63
- const result = await client.routing.getDirections(
64
- { lat: 12.993103152916301, lon: 77.54332622119354 },
65
- { lat: 12.972006793201695, lon: 77.5800850011884 },
66
- {
67
- alternatives: false,
68
- steps: true,
69
- overview: 'full',
70
- language: 'en',
71
- traffic_metadata: false
72
- }
73
- );
74
- console.log('Directions result:', result);
75
- } catch (error) {
76
- console.error('Error fetching directions:', error);
77
- }
78
- ```
79
-
80
-
81
- ### Tiles API
82
- API for accessing geolocation services such as places autocomplete, reverse geocode, turn by turn directions, map tiles in vector or image format.
83
-
84
- - **Get Data TileJSON** - Get array of data's TileJSONs.
85
-
86
- ```javascript
87
- try {
88
- const result = await client.tiles.getDataTileJSON('planet');
89
- console.log('Data TileJSON result:', result);
90
- } catch (error) {
91
- console.error('Error fetching Data TileJSON:', error);
92
- }
93
- ```
94
-
95
- - **Get PBF File** - Returns the PBF file for data.
96
-
97
- ```javascript
98
- try {
99
- const result = await client.tiles.getPBFFile('planet', 14, 110, 1010);
100
- console.log('PBF File result:', result);
101
- } catch (error) {
102
- console.error('Error fetching PBF file:', error);
103
- }
104
- ```
105
-
106
- - **Get Styles** - Returns the styles for the map.
107
-
108
- ```javascript
109
- try {
110
- const result = await client.tiles.getStyles();
111
- console.log('Styles result:', result);
112
- } catch (error) {
113
- console.error('Error fetching Styles:', error);
114
- }
115
- ```
116
-
117
- - **Get Style Detail** - Returns the style detail for the map.
118
-
119
- ```javascript
120
- try {
121
- const result = await client.tiles.getStyleDetail('default-light-standard');
122
- console.log('Style Detail result:', result);
123
- } catch (error) {
124
- console.error('Error fetching Style Detail:', error);
125
- }
126
- ```
127
-
128
- - **Get Font Glyphs** - Returns the font glyphs for the map.
129
-
130
- ```javascript
131
- try {
132
- const result = await client.tiles.getFontGlyphs('Noto Sans Bold', 0, 255);
133
- console.log('Font Glyphs result:', result);
134
- } catch (error) {
135
- console.error('Error fetching font glyphs:', error);
136
- }
137
- ```
1
+ # ola-map-sdk
2
+
3
+ > Lightweight, zero-dependency, TypeScript-first SDK for **Ola Maps** — built for Node.js 18+, Browsers, Next.js (App Router & Edge), React, Vite, Cloudflare Workers, Bun, and Deno.
4
+
5
+ ## Why v2.0?
6
+
7
+ - **Zero runtime dependencies** — uses native Web APIs (`fetch`, `URLSearchParams`, `FormData`, `Blob`, `AbortController`, Web Crypto). No `axios`, `uuid`, or `form-data`.
8
+ - **Complete Ola Maps API coverage** — Places, Geocoding, Routing, Roads, Geofencing, Elevation, Tiles (Vector, Raster, Static, 3D), **Street View**, and **OAuth 2.0 (`client_credentials`)**.
9
+ - **Fast & lightweight** — concurrent in-flight `GET` deduplication, optional LRU+TTL caching, single-flight OAuth token caching & proactive refresh, and tree-shakeable ESM + CJS builds.
10
+ - **Production-ready transport** — configurable timeouts, per-request `AbortSignal`, exponential backoff retries with jitter & `Retry-After`, per-request `X-Request-Id` / `X-Correlation-Id`, typed error hierarchy, and `onRequest` / `onResponse` observability hooks.
11
+ - **Secure by default** — strict `*.olamaps.io` host validation in MapLibre `transformRequest`, automatic secret redaction in errors/hooks, and a drop-in SSRF-safe proxy handler (`ola-map-sdk/next`).
12
+ - **Modular subpath exports** — `ola-map-sdk/maplibre`, `ola-map-sdk/next`, and `ola-map-sdk/react` (pay zero bundle cost for adapters you don't import).
13
+ - **Smooth v1 upgrade** — `new OlaMapsClient('YOUR_API_KEY')` remains supported alongside the v2 config object.
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install ola-map-sdk
21
+ ```
22
+
23
+ > **Requirements:** Node.js 18+ (or any modern browser / Edge runtime with Web `fetch`). Optional peer dependencies (`maplibre-gl`, `next`, `react`) are only needed if you use their respective subpath exports.
24
+
25
+ ---
26
+
27
+ ## Quick Start
28
+
29
+ ```ts
30
+ import OlaMapsClient from 'ola-map-sdk';
31
+ // or: import { OlaMapsClient } from 'ola-map-sdk';
32
+
33
+ // v1 shorthand (still supported)
34
+ const client = new OlaMapsClient('YOUR_API_KEY');
35
+
36
+ // v2 config object
37
+ const clientV2 = new OlaMapsClient({
38
+ apiKey: process.env.OLA_MAPS_API_KEY!,
39
+ timeoutMs: 10_000,
40
+ retries: { maxRetries: 2, baseDelayMs: 300 },
41
+ cache: { ttlMs: 30_000, maxEntries: 200 },
42
+ });
43
+
44
+ // Autocomplete places
45
+ const places = await clientV2.places.autocomplete('Koramangala, Bengaluru');
46
+
47
+ // Directions — accepts { lat, lng }, { lat, lon }, [lng, lat], or "lat,lng"
48
+ const route = await clientV2.routing.getDirections(
49
+ { lat: 12.993103, lng: 77.543326 },
50
+ { lat: 12.972006, lng: 77.580085 },
51
+ { mode: 'driving', traffic_metadata: true },
52
+ );
53
+ ```
54
+
55
+ ---
56
+
57
+ ## Configuration Options
58
+
59
+ | Option | Type | Default | Description |
60
+ |---|---|---|---|
61
+ | `apiKey` | `string` | — | Ola Maps API key (attached via `api_key` query param). |
62
+ | `clientId` / `clientSecret` | `string` | — | OAuth 2.0 `client_credentials` (server-side only). |
63
+ | `scope` | `string` | `'openid'` | OAuth 2.0 scope. |
64
+ | `tokenUrl` | `string` | `'https://api.olamaps.io/auth/v1/token'` | OAuth 2.0 token endpoint. |
65
+ | `tokenRefreshBufferMs` | `number` | `60000` | Proactively refresh OAuth token before expiry. |
66
+ | `accessToken` | `string \| (() => string \| Promise<string>)` | — | Static or async Bearer token provider. |
67
+ | `baseUrl` | `string` | `'https://api.olamaps.io'` | Override for Proxy Mode (e.g. `'/api/ola-maps'`). |
68
+ | `fetch` | `FetchLike` | `globalThis.fetch` | Custom `fetch` (Next.js cache options, proxies, mocks). |
69
+ | `timeoutMs` | `number` | `15000` | Default per-request timeout in ms. |
70
+ | `retries` | `RetryConfig \| false` | `{ maxRetries: 2 }` | Exponential backoff + jitter for `408`/`429`/`5xx` and network errors. |
71
+ | `cache` | `CacheConfig \| false` | `false` | Optional in-memory LRU+TTL cache for `GET` requests. |
72
+ | `dedupe` | `boolean` | `true` | Deduplicate concurrent identical in-flight `GET` requests. |
73
+ | `defaultHeaders` | `Record<string, string>` | `{}` | Extra headers merged onto every request. |
74
+ | `onRequest` / `onResponse` | `Function` | — | Observability hooks (URLs are automatically redacted). |
75
+
76
+ ---
77
+
78
+ ## Authentication Modes
79
+
80
+ ### 1. API Key
81
+
82
+ ```ts
83
+ const client = new OlaMapsClient({ apiKey: process.env.OLA_MAPS_API_KEY! });
84
+ ```
85
+
86
+ ### 2. OAuth 2.0 (`client_credentials`, server-side)
87
+
88
+ Exchanges credentials at `POST https://api.olamaps.io/auth/v1/token`, deduplicates concurrent token fetches, refreshes proactively before expiry, and automatically retries once on `401`.
89
+
90
+ ```ts
91
+ const client = new OlaMapsClient({
92
+ clientId: process.env.OLA_CLIENT_ID!,
93
+ clientSecret: process.env.OLA_CLIENT_SECRET!,
94
+ });
95
+
96
+ const token = await client.getAccessToken();
97
+ ```
98
+
99
+ ### 3. Pre-issued Bearer Token
100
+
101
+ ```ts
102
+ const client = new OlaMapsClient({
103
+ accessToken: async () => fetchMyCachedToken(),
104
+ });
105
+ ```
106
+
107
+ ### 4. Proxy Mode (recommended for React & Next.js browsers)
108
+
109
+ Keep secrets strictly on your server by pointing the browser client at your own proxy route:
110
+
111
+ ```ts
112
+ const client = new OlaMapsClient({
113
+ baseUrl: '/api/ola-maps',
114
+ });
115
+ ```
116
+
117
+ ---
118
+
119
+ ## Subpath Exports
120
+
121
+ ### Next.js App Router Proxy (`ola-map-sdk/next`)
122
+
123
+ Drop-in catch-all route handler (`app/api/ola-maps/[...path]/route.ts`) that injects server credentials, strips client-supplied keys, blocks path traversal / SSRF outside Ola Maps prefixes, supports optional `authorize(request)`, and streams JSON + binary tiles cleanly:
124
+
125
+ ```ts
126
+ // app/api/ola-maps/[...path]/route.ts
127
+ import { createOlaMapsProxyHandler } from 'ola-map-sdk/next';
128
+
129
+ export const { GET, POST, PUT, DELETE } = createOlaMapsProxyHandler({
130
+ apiKey: process.env.OLA_MAPS_API_KEY!,
131
+ // Or use server-side OAuth 2.0:
132
+ // clientId: process.env.OLA_CLIENT_ID!,
133
+ // clientSecret: process.env.OLA_CLIENT_SECRET!,
134
+ cacheControl: 'public, s-maxage=60, stale-while-revalidate=300',
135
+ });
136
+ ```
137
+
138
+ In Server Components, pass Next.js's extended `fetch` for built-in caching/revalidation:
139
+
140
+ ```ts
141
+ const client = new OlaMapsClient({
142
+ apiKey: process.env.OLA_MAPS_API_KEY!,
143
+ fetch: (url, init) => fetch(url, { ...init, next: { revalidate: 300 } }),
144
+ });
145
+ ```
146
+
147
+ ### React Hooks (`ola-map-sdk/react`)
148
+
149
+ Includes `<OlaMapsProvider>`, `useOlaMapsClient`, `useOlaAutocomplete` (debounced + automatic `AbortController` cancellation on keystrokes/unmount), `useOlaDirections`, and `useOlaReverseGeocode`.
150
+
151
+ ```tsx
152
+ 'use client';
153
+
154
+ import { useState } from 'react';
155
+ import { OlaMapsProvider, useOlaAutocomplete } from 'ola-map-sdk/react';
156
+
157
+ function SearchBox() {
158
+ const [query, setQuery] = useState('');
159
+ const { predictions, loading, error } = useOlaAutocomplete(query, {
160
+ debounceMs: 250,
161
+ minLength: 2,
162
+ });
163
+
164
+ return (
165
+ <div>
166
+ <input
167
+ value={query}
168
+ onChange={(e) => setQuery(e.target.value)}
169
+ placeholder="Search places..."
170
+ />
171
+ {loading && <p>Searching...</p>}
172
+ {error && <p>{error.message}</p>}
173
+ <ul>
174
+ {predictions.map((p) => (
175
+ <li key={p.place_id}>{p.description}</li>
176
+ ))}
177
+ </ul>
178
+ </div>
179
+ );
180
+ }
181
+
182
+ export default function App() {
183
+ return (
184
+ <OlaMapsProvider config={{ baseUrl: '/api/ola-maps' }}>
185
+ <SearchBox />
186
+ </OlaMapsProvider>
187
+ );
188
+ }
189
+ ```
190
+
191
+ ### MapLibre GL Integration (`ola-map-sdk/maplibre`)
192
+
193
+ `getTransformRequest` parses every URL with `new URL()` and **only** attaches credentials or rewrites `app.olamaps.io` → `api.olamaps.io` for verified `*.olamaps.io` hosts—preventing credential leaks to third-party overlay/sprite/font domains.
194
+
195
+ ```ts
196
+ import maplibregl from 'maplibre-gl';
197
+ import 'maplibre-gl/dist/maplibre-gl.css';
198
+ import { getMapOptions } from 'ola-map-sdk/maplibre';
199
+
200
+ // Proxy mode (recommended — no API key in browser)
201
+ const map = new maplibregl.Map(
202
+ getMapOptions(
203
+ { proxyBaseUrl: '/api/ola-maps' },
204
+ {
205
+ container: 'map',
206
+ style: 'default-light-standard',
207
+ center: [77.61, 12.93],
208
+ zoom: 14,
209
+ },
210
+ ),
211
+ );
212
+ ```
213
+
214
+ Convenience helpers (`client.getStyleURL()`, `client.getTransformRequest()`, `client.getMapOptions()`) are also available directly on `OlaMapsClient`.
215
+
216
+ #### Built-in Map Styles (`OLA_MAP_STYLES`)
217
+
218
+ | Category | Styles |
219
+ |---|---|
220
+ | **Default Light** | `default-light-lite`, `default-light-standard`, `default-ultra-light-standard`, `default-light-full` |
221
+ | **Default Dark & Satellite** | `default-dark-lite`, `default-dark-standard`, `default-dark-full`, `default-dark-standard-satellite` |
222
+ | **Eclipse** | `eclipse-light-lite`, `eclipse-light-standard`, `eclipse-light-full`, `eclipse-dark-lite`, `eclipse-dark-standard`, `eclipse-dark-full` |
223
+ | **Bolt / Vintage / Earth** | `bolt-light`, `bolt-dark`, `vintage-light`, `vintage-dark`, `default-earth-lite`, `default-earth-standard`, `default-earth-full` |
224
+ | **OSM** | `positron`, `osm-bright`, `osm-basic`, `dark-matter`, `fiord-color`, `silver-osm` |
225
+
226
+ ---
227
+
228
+ ## API Reference
229
+
230
+ Every endpoint method accepts flexible coordinates (`{ lat, lng }`, `{ lat, lon }`, `[lng, lat]`, or `"lat,lng"`) and an optional trailing `RequestOptions` argument (`{ signal, timeoutMs, requestId, correlationId, headers, retries, skipCache }`).
231
+
232
+ ### Places & Geocoding (`client.places`)
233
+
234
+ ```ts
235
+ await client.places.autocomplete('Bengaluru', { location: { lat: 12.93, lng: 77.61 }, radius: 5000 });
236
+ await client.places.geocode('Taj Mahal, Agra', { language: 'en' });
237
+ await client.places.reverseGeocode(12.931, 77.616); // also accepts numeric strings or { lat, lng }
238
+ await client.places.placeDetails('ola-platform:5000039498427');
239
+ await client.places.placeDetailsAdvanced('ola-platform:5000039498427');
240
+ await client.places.nearbySearch({ lat: 12.93, lng: 77.61 }, { layers: 'venue', types: 'cafe', limit: 25 }); // limit <= 50
241
+ await client.places.nearbySearchAdvanced('12.93,77.61', { layers: 'venue', rankBy: 'distance' });
242
+ await client.places.textSearch('Cafes in Koramangala');
243
+ await client.places.addressValidation('7, Lok Kalyan Marg, New Delhi');
244
+ await client.places.photo('photo_reference_id');
245
+ ```
246
+
247
+ ### Routing (`client.routing`)
248
+
249
+ ```ts
250
+ await client.routing.getDirections({ lat: 12.993, lng: 77.543 }, { lat: 12.972, lng: 77.58 });
251
+ await client.routing.getDirectionsBasic([77.543, 12.993], [77.58, 12.972]);
252
+ await client.routing.getDistanceMatrix([{ lat: 12.993, lng: 77.543 }], [{ lat: 12.935, lng: 77.615 }]);
253
+ await client.routing.getDistanceMatrixBasic('12.993,77.543', '12.935,77.615');
254
+ await client.routing.routeOptimizer('12.993,77.543|12.972,77.58|12.935,77.615'); // max 25 locations
255
+ await client.routing.fleetPlanner({ packages: [], vehicles: [] }, 'optimal'); // Web FormData + Blob
256
+ ```
257
+
258
+ ### Roads (`client.roads`)
259
+
260
+ ```ts
261
+ await client.roads.snapToRoad('12.999,77.673|12.992,77.658', true); // max 50 points
262
+ await client.roads.nearestRoads('12.999,77.673|12.992,77.658', 'DRIVING', 500); // max 100 points
263
+ await client.roads.speedLimits('13.063,77.593|13.064,77.594', 'snaptoroad'); // max 50 points
264
+ ```
265
+
266
+ ### Street View (`client.streetView`)
267
+
268
+ ```ts
269
+ await client.streetView.getCoverage({ xMin: 77.611, yMin: 12.932, xMax: 77.615, yMax: 12.935 });
270
+ const { imageId } = await client.streetView.getImageId(12.934698, 77.613462, { radius: 50 });
271
+ const metadata = await client.streetView.getMetadata(imageId);
272
+ ```
273
+
274
+ ### Geofencing (`client.geofencing`)
275
+
276
+ ```ts
277
+ await client.geofencing.create({
278
+ name: 'Warehouse',
279
+ type: 'circle',
280
+ coordinates: [[12.931, 77.615]],
281
+ radius: 100,
282
+ status: 'active',
283
+ projectId: 'my-project',
284
+ });
285
+ await client.geofencing.getById('fence-id');
286
+ await client.geofencing.update('fence-id', { name: 'Updated' });
287
+ await client.geofencing.deleteById('fence-id');
288
+ await client.geofencing.list('my-project', 1, 10);
289
+ await client.geofencing.checkStatus('fence-id', { lat: 12.93, lng: 77.61 });
290
+ ```
291
+
292
+ ### Elevation (`client.elevation`)
293
+
294
+ ```ts
295
+ await client.elevation.getElevation(12.93126, 77.61638);
296
+ await client.elevation.getMultiElevation(['12.93126,77.61638', { lat: 12.89731, lng: 77.65136 }]); // max 25
297
+ ```
298
+
299
+ ### Tiles & Static Maps (`client.tiles`)
300
+
301
+ ```ts
302
+ await client.tiles.getStyles();
303
+ await client.tiles.getStyleDetail('default-light-standard');
304
+ await client.tiles.getDataTileJSON('planet');
305
+ await client.tiles.getPBFFile('planet', 14, 110, 1010); // ArrayBuffer
306
+ await client.tiles.getRasterTile('default-light-standard', 14, 11722, 7613, 'png'); // ArrayBuffer
307
+ await client.tiles.getFontGlyphs('Noto Sans Bold', 0, 255); // ArrayBuffer
308
+ await client.tiles.get3DTileset();
309
+
310
+ // Static maps (width/height 1–2048; array markers serialize as marker=a&marker=b)
311
+ await client.tiles.getStaticMapByCenter('default-light-standard', 77.61, 12.93, 15, 800, 600, 'png', {
312
+ marker: ['77.61,12.93|red', '77.62,12.94|blue'],
313
+ });
314
+ await client.tiles.getStaticMapByBBox(
315
+ 'default-light-standard',
316
+ { minx: 77.5, miny: 12.9, maxx: 77.7, maxy: 13.0 },
317
+ 800,
318
+ 600,
319
+ 'png',
320
+ );
321
+ await client.tiles.getStaticMapAuto('default-light-standard', 800, 600, 'png', {
322
+ marker: '77.61,12.93|red',
323
+ });
324
+ ```
325
+
326
+ ---
327
+
328
+ ## Error Handling
329
+
330
+ All API, validation, timeout, and network failures throw typed subclasses of `OlaMapsError` with credentials automatically redacted (and zero `console.error` side effects):
331
+
332
+ ```ts
333
+ import {
334
+ OlaMapsError,
335
+ OlaAuthError,
336
+ OlaRateLimitError,
337
+ OlaValidationError,
338
+ OlaTimeoutError,
339
+ OlaNetworkError,
340
+ } from 'ola-map-sdk';
341
+
342
+ try {
343
+ await client.places.autocomplete('Bengaluru');
344
+ } catch (err) {
345
+ if (err instanceof OlaRateLimitError) {
346
+ console.log('Retry after (ms):', err.retryAfter);
347
+ } else if (err instanceof OlaAuthError) {
348
+ console.log('Auth failed:', err.status, err.requestId);
349
+ } else if (err instanceof OlaMapsError) {
350
+ console.log(err.code, err.status, err.url); // api_key is always REDACTED
351
+ }
352
+ }
353
+ ```
354
+
355
+ ---
356
+
357
+ ## Migrating from v1.x to v2.0
358
+
359
+ - **Node 18+ required** (native Web `fetch` & `FormData`; zero runtime dependencies).
360
+ - `new OlaMapsClient('YOUR_API_KEY')` still works out of the box.
361
+ - In CommonJS, prefer `const { OlaMapsClient } = require('ola-map-sdk')` (or `require('ola-map-sdk').default`).
362
+ - `fleetPlanner` no longer reads local filesystem paths directly (so it works in browsers & Edge runtimes); pass a plain object, JSON string, `Blob`, `Uint8Array`, or `ArrayBuffer` (e.g. `await fs.readFile('input.json')` on Node).
363
+ - `getStaticMapAuto` now validates that at least one `marker` or `path` is provided.
364
+ - Errors are now typed `OlaMapsError` subclasses and never log to `console.error`.
365
+
366
+ ---
367
+
368
+ ## Development
369
+
370
+ ```bash
371
+ npm install
372
+ npm run check # typecheck + biome lint + vitest + tsup build + publint + attw
373
+ npm run test:coverage # run tests with v8 coverage report
374
+ ```
375
+
376
+ ---
377
+
378
+ ## License
379
+
380
+ MIT © Kunal Kongkan Kashyap