ola-map-sdk 1.3.0 → 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 (55) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +380 -215
  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 +111 -11
  48. package/src/client.js +0 -95
  49. package/src/endpoints/elevation.js +0 -58
  50. package/src/endpoints/geofencing.js +0 -118
  51. package/src/endpoints/places.js +0 -106
  52. package/src/endpoints/roads.js +0 -57
  53. package/src/endpoints/routing.js +0 -160
  54. package/src/endpoints/tiles.js +0 -115
  55. package/src/index.js +0 -5
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,215 +1,380 @@
1
- # Ola Map SDK
2
-
3
- Complete Ola Maps API client for **Node.js**. Covers all endpoints — Places, Routing, Roads, Geofencing, Elevation, and Tiles.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install ola-map-sdk
9
- ```
10
-
11
- ## Quick Start
12
-
13
- ```javascript
14
- const OlaMapsClient = require('ola-map-sdk');
15
- // or: import OlaMapsClient from 'ola-map-sdk';
16
-
17
- const client = new OlaMapsClient('YOUR_API_KEY');
18
-
19
- // Search for places
20
- const results = await client.places.autocomplete('Koramangala, Bangalore');
21
-
22
- // Get directions
23
- const route = await client.routing.getDirections(
24
- { lat: 12.993103, lon: 77.543326 },
25
- { lat: 12.972006, lon: 77.580085 }
26
- );
27
- ```
28
-
29
- ---
30
-
31
- ## API Reference
32
-
33
- ### Places
34
-
35
- ```javascript
36
- // Autocomplete
37
- const results = await client.places.autocomplete('Bangalore', {
38
- location: '12.93,77.61', radius: 5000, language: 'en'
39
- });
40
-
41
- // Geocode & Reverse Geocode
42
- const geo = await client.places.geocode('Taj Mahal, Mumbai');
43
- const reverse = await client.places.reverseGeocode(26.115103, 91.703239);
44
-
45
- // Place Details
46
- const details = await client.places.placeDetails('ola-platform:5000039498427');
47
- const advDetails = await client.places.placeDetailsAdvanced('ola-platform:5000039498427');
48
-
49
- // Nearby Search
50
- const nearby = await client.places.nearbySearch('12.93,77.61', { types: 'restaurant', radius: 1000 });
51
- const nearbyAdv = await client.places.nearbySearchAdvanced('12.93,77.61', { types: 'cafe' });
52
-
53
- // Text Search
54
- const text = await client.places.textSearch('Cafes in Koramangala');
55
-
56
- // Address Validation
57
- const validation = await client.places.addressValidation('7, Lok Kalyan Marg, New Delhi');
58
-
59
- // Place Photo
60
- const photo = await client.places.photo('photo_reference_id');
61
- ```
62
-
63
- ### Routing
64
-
65
- ```javascript
66
- // Directions (with options)
67
- const directions = await client.routing.getDirections(
68
- { lat: 12.993103, lon: 77.543326 },
69
- { lat: 12.972006, lon: 77.580085 },
70
- { mode: 'driving', steps: true, overview: 'full', traffic_metadata: true }
71
- );
72
-
73
- // Directions Basic (no traffic)
74
- const basic = await client.routing.getDirectionsBasic(
75
- { lat: 12.993103, lon: 77.543326 },
76
- { lat: 12.972006, lon: 77.580085 }
77
- );
78
-
79
- // Distance Matrix
80
- const matrix = await client.routing.getDistanceMatrix(
81
- '12.993,77.543|12.972,77.580', '12.935,77.615', { mode: 'driving' }
82
- );
83
-
84
- // Distance Matrix Basic
85
- const matrixBasic = await client.routing.getDistanceMatrixBasic(
86
- '12.993,77.543', '12.935,77.615'
87
- );
88
-
89
- // Route Optimizer
90
- const optimized = await client.routing.routeOptimizer(
91
- '12.993,77.543|12.972,77.580|12.935,77.615',
92
- { source: 'first', destination: 'last' }
93
- );
94
-
95
- // Fleet Planner
96
- const fleet = await client.routing.fleetPlanner(
97
- { packages: [...], vehicles: [...] }, 'optimal'
98
- );
99
- ```
100
-
101
- ### Roads
102
-
103
- ```javascript
104
- const snapped = await client.roads.snapToRoad('12.999,77.673|12.992,77.658', true);
105
- const nearest = await client.roads.nearestRoads('12.999,77.673|12.992,77.658', 'DRIVING', 500);
106
- const speeds = await client.roads.speedLimits('13.063,77.593|13.063,77.593');
107
- ```
108
-
109
- ### Geofencing
110
-
111
- ```javascript
112
- // Create
113
- const fence = await client.geofencing.create({
114
- name: 'Warehouse', type: 'circle', coordinates: [[12.931, 77.615]],
115
- radius: 100, status: 'active', projectId: 'my-project'
116
- });
117
-
118
- // Read, Update, Delete
119
- const get = await client.geofencing.getById('fence-id');
120
- const update = await client.geofencing.update('fence-id', { name: 'Updated' });
121
- const del = await client.geofencing.deleteById('fence-id');
122
-
123
- // List & Status Check
124
- const list = await client.geofencing.list('my-project', 1, 10);
125
- const status = await client.geofencing.checkStatus('fence-id', '12.93,77.61');
126
- ```
127
-
128
- ### Elevation
129
-
130
- ```javascript
131
- const elev = await client.elevation.getElevation(12.93126, 77.61638);
132
- const multi = await client.elevation.getMultiElevation(['12.93126,77.61638', '12.89731,77.65136']);
133
- ```
134
-
135
- ### Tiles
136
-
137
- ```javascript
138
- const styles = await client.tiles.getStyles();
139
- const styleDetail = await client.tiles.getStyleDetail('default-light-standard');
140
- const tileJSON = await client.tiles.getDataTileJSON('planet');
141
- const pbf = await client.tiles.getPBFFile('planet', 14, 110, 1010);
142
- const glyphs = await client.tiles.getFontGlyphs('Noto Sans Bold', 0, 255);
143
-
144
- // Static map images
145
- const img = await client.tiles.getStaticMapByCenter(
146
- 'default-light-standard', 77.61, 12.93, 15, 800, 600, 'png',
147
- { marker: '77.61,12.93|red' }
148
- );
149
- const bbox = await client.tiles.getStaticMapByBBox(
150
- 'default-light-standard',
151
- { minx: 77.5, miny: 12.9, maxx: 77.7, maxy: 13.0 }, 800, 600, 'png'
152
- );
153
- const auto = await client.tiles.getStaticMapAuto('default-light-standard', 800, 600, 'png');
154
- const tileset3d = await client.tiles.get3DTileset();
155
- ```
156
-
157
- ---
158
-
159
- ## Map Display (with MapLibre GL)
160
-
161
- The SDK includes helper methods to simplify MapLibre GL integration. Install `maplibre-gl` alongside:
162
-
163
- ```bash
164
- npm install maplibre-gl
165
- ```
166
-
167
- ### Using `getMapOptions()` (recommended)
168
-
169
- ```javascript
170
- import maplibregl from 'maplibre-gl';
171
- import 'maplibre-gl/dist/maplibre-gl.css';
172
- import OlaMapsClient from 'ola-map-sdk';
173
-
174
- const client = new OlaMapsClient('YOUR_API_KEY');
175
-
176
- // One-liner — handles style URL + API key injection automatically
177
- const map = new maplibregl.Map(client.getMapOptions({
178
- container: 'map',
179
- style: 'default-light-standard',
180
- center: [77.61, 12.93],
181
- zoom: 14,
182
- }));
183
- ```
184
-
185
- ### Individual helpers
186
-
187
- ```javascript
188
- // Get the full style URL
189
- client.getStyleURL('default-dark-standard');
190
- // → "https://api.olamaps.io/tiles/vector/v1/styles/default-dark-standard/style.json"
191
-
192
- // Get a pre-configured transformRequest function
193
- const transformRequest = client.getTransformRequest();
194
-
195
- // Switch styles at runtime
196
- map.setStyle(client.getStyleURL('eclipse-light-standard'));
197
- ```
198
-
199
- ### Available map styles
200
-
201
- | Category | Styles |
202
- |---|---|
203
- | **Default Light** | `default-light-lite`, `default-light-standard`, `default-ultra-light-standard`, `default-light-full` + 11 language variants |
204
- | **Default Dark** | `default-dark-lite`, `default-dark-standard`, `default-dark-full`, `default-dark-standard-satellite` + language variants |
205
- | **Eclipse** | `eclipse-light-lite`, `eclipse-light-standard`, `eclipse-light-full`, `eclipse-dark-lite`, `eclipse-dark-standard`, `eclipse-dark-full` |
206
- | **Bolt** | `bolt-light`, `bolt-dark` |
207
- | **Vintage** | `vintage-light`, `vintage-dark` |
208
- | **Earth** | `default-earth-lite`, `default-earth-standard`, `default-earth-full` |
209
- | **OSM** | `positron`, `osm-bright`, `osm-basic`, `dark-matter`, `fiord-color`, `silver-osm` |
210
-
211
- ---
212
-
213
- ## License
214
-
215
- MIT © Kunal Kongkan Kashyap
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