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
@@ -0,0 +1,251 @@
1
+ 'use client';
2
+ import { OlaMapsClient } from '../chunk-22747AE4.js';
3
+ import '../chunk-SJJRTEQG.js';
4
+ import '../chunk-7LV3RPED.js';
5
+ import '../chunk-D5T5ZDIQ.js';
6
+ import { createContext, useMemo, createElement, useContext, useRef, useState, useCallback, useEffect } from 'react';
7
+
8
+ var OlaMapsContext = createContext(null);
9
+ function OlaMapsProvider({ client, config, children }) {
10
+ const resolvedClient = useMemo(() => {
11
+ if (client) return client;
12
+ if (!config) {
13
+ throw new Error("OlaMapsProvider requires either a `client` or `config` prop.");
14
+ }
15
+ return new OlaMapsClient(config);
16
+ }, [client, config]);
17
+ return createElement(OlaMapsContext.Provider, { value: resolvedClient }, children);
18
+ }
19
+ function useOlaMapsClient() {
20
+ const client = useContext(OlaMapsContext);
21
+ if (!client) {
22
+ throw new Error("useOlaMapsClient must be used within an <OlaMapsProvider>.");
23
+ }
24
+ return client;
25
+ }
26
+ function isAbortError(error) {
27
+ return error instanceof Error && error.name === "AbortError";
28
+ }
29
+ function useOlaAutocomplete(input, options = {}) {
30
+ const contextClient = useContext(OlaMapsContext);
31
+ const activeClient = options.client ?? contextClient;
32
+ if (!activeClient) {
33
+ throw new Error("useOlaAutocomplete requires <OlaMapsProvider> or options.client.");
34
+ }
35
+ const {
36
+ debounceMs = 250,
37
+ minLength = 2,
38
+ enabled = true,
39
+ location,
40
+ radius,
41
+ strictbounds,
42
+ language,
43
+ types
44
+ } = options;
45
+ const locationKey = typeof location === "string" ? location : JSON.stringify(location ?? null);
46
+ const locationRef = useRef(location);
47
+ locationRef.current = location;
48
+ const [data, setData] = useState(null);
49
+ const [loading, setLoading] = useState(false);
50
+ const [error, setError] = useState(null);
51
+ const [reloadTick, setReloadTick] = useState(0);
52
+ const refetch = useCallback(() => {
53
+ setReloadTick((n) => n + 1);
54
+ }, []);
55
+ useEffect(() => {
56
+ const trimmed = input.trim();
57
+ if (!enabled || trimmed.length < minLength) {
58
+ setData(null);
59
+ setError(null);
60
+ setLoading(false);
61
+ return;
62
+ }
63
+ const controller = new AbortController();
64
+ setLoading(true);
65
+ setError(null);
66
+ const timer = setTimeout(() => {
67
+ activeClient.places.autocomplete(
68
+ trimmed,
69
+ { location: locationRef.current, radius, strictbounds, language, types },
70
+ { signal: controller.signal }
71
+ ).then((res) => {
72
+ if (!controller.signal.aborted) {
73
+ setData(res);
74
+ setError(null);
75
+ setLoading(false);
76
+ }
77
+ }).catch((err) => {
78
+ if (controller.signal.aborted || isAbortError(err)) return;
79
+ setError(err instanceof Error ? err : new Error(String(err)));
80
+ setLoading(false);
81
+ });
82
+ }, debounceMs);
83
+ return () => {
84
+ clearTimeout(timer);
85
+ controller.abort();
86
+ };
87
+ }, [
88
+ activeClient,
89
+ input,
90
+ enabled,
91
+ minLength,
92
+ debounceMs,
93
+ locationKey,
94
+ radius,
95
+ strictbounds,
96
+ language,
97
+ types,
98
+ reloadTick
99
+ ]);
100
+ return {
101
+ predictions: data?.predictions ?? [],
102
+ data,
103
+ loading,
104
+ error,
105
+ refetch
106
+ };
107
+ }
108
+ function useOlaDirections(origin, destination, options = {}) {
109
+ const contextClient = useContext(OlaMapsContext);
110
+ const activeClient = options.client ?? contextClient;
111
+ if (!activeClient) {
112
+ throw new Error("useOlaDirections requires <OlaMapsProvider> or options.client.");
113
+ }
114
+ const {
115
+ enabled = true,
116
+ alternatives,
117
+ steps,
118
+ overview,
119
+ language,
120
+ traffic_metadata,
121
+ waypoints,
122
+ mode,
123
+ route_preference
124
+ } = options;
125
+ const originKey = origin == null ? "" : JSON.stringify(origin);
126
+ const destKey = destination == null ? "" : JSON.stringify(destination);
127
+ const waypointsKey = waypoints == null ? "" : JSON.stringify(waypoints);
128
+ const originRef = useRef(origin);
129
+ const destRef = useRef(destination);
130
+ const waypointsRef = useRef(waypoints);
131
+ originRef.current = origin;
132
+ destRef.current = destination;
133
+ waypointsRef.current = waypoints;
134
+ const [data, setData] = useState(null);
135
+ const [loading, setLoading] = useState(false);
136
+ const [error, setError] = useState(null);
137
+ const [reloadTick, setReloadTick] = useState(0);
138
+ const refetch = useCallback(() => {
139
+ setReloadTick((n) => n + 1);
140
+ }, []);
141
+ useEffect(() => {
142
+ if (!enabled || !originKey || !destKey || originRef.current == null || destRef.current == null) {
143
+ setLoading(false);
144
+ return;
145
+ }
146
+ const controller = new AbortController();
147
+ setLoading(true);
148
+ setError(null);
149
+ activeClient.routing.getDirections(
150
+ originRef.current,
151
+ destRef.current,
152
+ {
153
+ alternatives,
154
+ steps,
155
+ overview,
156
+ language,
157
+ traffic_metadata,
158
+ waypoints: waypointsRef.current,
159
+ mode,
160
+ route_preference
161
+ },
162
+ { signal: controller.signal }
163
+ ).then((res) => {
164
+ if (!controller.signal.aborted) {
165
+ setData(res);
166
+ setError(null);
167
+ setLoading(false);
168
+ }
169
+ }).catch((err) => {
170
+ if (controller.signal.aborted || isAbortError(err)) return;
171
+ setError(err instanceof Error ? err : new Error(String(err)));
172
+ setLoading(false);
173
+ });
174
+ return () => {
175
+ controller.abort();
176
+ };
177
+ }, [
178
+ activeClient,
179
+ enabled,
180
+ originKey,
181
+ destKey,
182
+ alternatives,
183
+ steps,
184
+ overview,
185
+ language,
186
+ traffic_metadata,
187
+ waypointsKey,
188
+ mode,
189
+ route_preference,
190
+ reloadTick
191
+ ]);
192
+ return {
193
+ routes: data?.routes ?? [],
194
+ data,
195
+ loading,
196
+ error,
197
+ refetch
198
+ };
199
+ }
200
+ function useOlaReverseGeocode(coordinate, options = {}) {
201
+ const contextClient = useContext(OlaMapsContext);
202
+ const activeClient = options.client ?? contextClient;
203
+ if (!activeClient) {
204
+ throw new Error("useOlaReverseGeocode requires <OlaMapsProvider> or options.client.");
205
+ }
206
+ const { enabled = true, language } = options;
207
+ const coordKey = coordinate == null ? "" : JSON.stringify(coordinate);
208
+ const coordRef = useRef(coordinate);
209
+ coordRef.current = coordinate;
210
+ const [data, setData] = useState(null);
211
+ const [loading, setLoading] = useState(false);
212
+ const [error, setError] = useState(null);
213
+ const [reloadTick, setReloadTick] = useState(0);
214
+ const refetch = useCallback(() => {
215
+ setReloadTick((n) => n + 1);
216
+ }, []);
217
+ useEffect(() => {
218
+ if (!enabled || !coordKey || coordRef.current == null) {
219
+ setLoading(false);
220
+ return;
221
+ }
222
+ const controller = new AbortController();
223
+ setLoading(true);
224
+ setError(null);
225
+ activeClient.places.reverseGeocode(coordRef.current, { language }, { signal: controller.signal }).then((res) => {
226
+ if (!controller.signal.aborted) {
227
+ setData(res);
228
+ setError(null);
229
+ setLoading(false);
230
+ }
231
+ }).catch((err) => {
232
+ if (controller.signal.aborted || isAbortError(err)) return;
233
+ setError(err instanceof Error ? err : new Error(String(err)));
234
+ setLoading(false);
235
+ });
236
+ return () => {
237
+ controller.abort();
238
+ };
239
+ }, [activeClient, enabled, coordKey, language, reloadTick]);
240
+ return {
241
+ results: data?.results ?? [],
242
+ data,
243
+ loading,
244
+ error,
245
+ refetch
246
+ };
247
+ }
248
+
249
+ export { OlaMapsProvider, useOlaAutocomplete, useOlaDirections, useOlaMapsClient, useOlaReverseGeocode };
250
+ //# sourceMappingURL=index.js.map
251
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../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C,CAAC,CAAA;AAC5D,MAAA,UAAA,CAAW,KAAK,CAAA;AAAA,IAClB,CAAC,CAAA;AAEH,IAAA,OAAO,MAAM;AACX,MAAA,UAAA,CAAW,KAAA,EAAM;AAAA,IACnB,CAAA;AAAA,EACF,GAAG,CAAC,YAAA,EAAc,SAAS,QAAA,EAAU,QAAA,EAAU,UAAU,CAAC,CAAA;AAE1D,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,IAAA,EAAM,OAAA,IAAW,EAAC;AAAA,IAC3B,IAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import {\n type ReactNode,\n createContext,\n createElement,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { OlaMapsClient } from '../client.js';\nimport type { CoordinateInput, OlaMapsClientInput } from '../types/common.js';\nimport type {\n AutocompleteOptions,\n AutocompletePrediction,\n AutocompleteResponse,\n GeocodeResult,\n ReverseGeocodeOptions,\n ReverseGeocodeResponse,\n} from '../types/places.js';\nimport type { DirectionsOptions, DirectionsResponse, Route } from '../types/routing.js';\n\nconst OlaMapsContext = createContext<OlaMapsClient | null>(null);\n\nexport interface OlaMapsProviderProps {\n /** Pass a pre-instantiated `OlaMapsClient` OR `config` to create one automatically. */\n client?: OlaMapsClient;\n /** Client configuration (e.g. `{ baseUrl: '/api/ola-maps' }` or API key string). */\n config?: OlaMapsClientInput;\n children: ReactNode;\n}\n\n/**\n * Provide a shared `OlaMapsClient` instance to descendant React components and hooks.\n */\nexport function OlaMapsProvider({ client, config, children }: OlaMapsProviderProps) {\n const resolvedClient = useMemo(() => {\n if (client) return client;\n if (!config) {\n throw new Error('OlaMapsProvider requires either a `client` or `config` prop.');\n }\n return new OlaMapsClient(config);\n }, [client, config]);\n\n return createElement(OlaMapsContext.Provider, { value: resolvedClient }, children);\n}\n\n/**\n * Access the nearest `OlaMapsClient` provided by `<OlaMapsProvider>`.\n */\nexport function useOlaMapsClient(): OlaMapsClient {\n const client = useContext(OlaMapsContext);\n if (!client) {\n throw new Error('useOlaMapsClient must be used within an <OlaMapsProvider>.');\n }\n return client;\n}\n\nfunction isAbortError(error: unknown): boolean {\n return error instanceof Error && error.name === 'AbortError';\n}\n\nexport interface UseOlaAutocompleteOptions extends AutocompleteOptions {\n /** Debounce delay in milliseconds before firing a search request (default: 250). */\n debounceMs?: number;\n /** Minimum input length before querying Ola Maps (default: 2). */\n minLength?: number;\n /** Disable automatic querying when false (default: true). */\n enabled?: boolean;\n /** Optional explicit client override (defaults to context client). */\n client?: OlaMapsClient;\n}\n\nexport interface UseOlaAutocompleteResult {\n predictions: AutocompletePrediction[];\n data: AutocompleteResponse | null;\n loading: boolean;\n error: Error | null;\n refetch: () => void;\n}\n\n/**\n * Debounced Places Autocomplete hook with automatic `AbortController` cancellation\n * on every keystroke and component unmount.\n */\nexport function useOlaAutocomplete(\n input: string,\n options: UseOlaAutocompleteOptions = {},\n): UseOlaAutocompleteResult {\n const contextClient = useContext(OlaMapsContext);\n const activeClient = options.client ?? contextClient;\n if (!activeClient) {\n throw new Error('useOlaAutocomplete requires <OlaMapsProvider> or options.client.');\n }\n\n const {\n debounceMs = 250,\n minLength = 2,\n enabled = true,\n location,\n radius,\n strictbounds,\n language,\n types,\n } = options;\n\n const locationKey = typeof location === 'string' ? location : JSON.stringify(location ?? null);\n const locationRef = useRef(location);\n locationRef.current = location;\n\n const [data, setData] = useState<AutocompleteResponse | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [reloadTick, setReloadTick] = useState(0);\n\n const refetch = useCallback(() => {\n setReloadTick((n) => n + 1);\n }, []);\n\n useEffect(() => {\n void locationKey;\n void reloadTick;\n\n const trimmed = input.trim();\n if (!enabled || trimmed.length < minLength) {\n setData(null);\n setError(null);\n setLoading(false);\n return;\n }\n\n const controller = new AbortController();\n setLoading(true);\n setError(null);\n\n const timer = setTimeout(() => {\n activeClient.places\n .autocomplete(\n trimmed,\n { location: locationRef.current, radius, strictbounds, language, types },\n { signal: controller.signal },\n )\n .then((res) => {\n if (!controller.signal.aborted) {\n setData(res);\n setError(null);\n setLoading(false);\n }\n })\n .catch((err: unknown) => {\n if (controller.signal.aborted || isAbortError(err)) return;\n setError(err instanceof Error ? err : new Error(String(err)));\n setLoading(false);\n });\n }, debounceMs);\n\n return () => {\n clearTimeout(timer);\n controller.abort();\n };\n }, [\n activeClient,\n input,\n enabled,\n minLength,\n debounceMs,\n locationKey,\n radius,\n strictbounds,\n language,\n types,\n reloadTick,\n ]);\n\n return {\n predictions: data?.predictions ?? [],\n data,\n loading,\n error,\n refetch,\n };\n}\n\nexport interface UseOlaDirectionsOptions extends DirectionsOptions {\n /** Disable automatic querying when false (default: true). */\n enabled?: boolean;\n /** Optional explicit client override (defaults to context client). */\n client?: OlaMapsClient;\n}\n\nexport interface UseOlaDirectionsResult {\n routes: Route[];\n data: DirectionsResponse | null;\n loading: boolean;\n error: Error | null;\n refetch: () => void;\n}\n\n/**\n * Fetch turn-by-turn directions reactively with automatic `AbortController` cancellation.\n */\nexport function useOlaDirections(\n origin: CoordinateInput | null | undefined,\n destination: CoordinateInput | null | undefined,\n options: UseOlaDirectionsOptions = {},\n): UseOlaDirectionsResult {\n const contextClient = useContext(OlaMapsContext);\n const activeClient = options.client ?? contextClient;\n if (!activeClient) {\n throw new Error('useOlaDirections requires <OlaMapsProvider> or options.client.');\n }\n\n const {\n enabled = true,\n alternatives,\n steps,\n overview,\n language,\n traffic_metadata,\n waypoints,\n mode,\n route_preference,\n } = options;\n\n const originKey = origin == null ? '' : JSON.stringify(origin);\n const destKey = destination == null ? '' : JSON.stringify(destination);\n const waypointsKey = waypoints == null ? '' : JSON.stringify(waypoints);\n\n const originRef = useRef(origin);\n const destRef = useRef(destination);\n const waypointsRef = useRef(waypoints);\n originRef.current = origin;\n destRef.current = destination;\n waypointsRef.current = waypoints;\n\n const [data, setData] = useState<DirectionsResponse | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [reloadTick, setReloadTick] = useState(0);\n\n const refetch = useCallback(() => {\n setReloadTick((n) => n + 1);\n }, []);\n\n useEffect(() => {\n void reloadTick;\n\n if (\n !enabled ||\n !originKey ||\n !destKey ||\n originRef.current == null ||\n destRef.current == null\n ) {\n setLoading(false);\n return;\n }\n\n const controller = new AbortController();\n setLoading(true);\n setError(null);\n\n void waypointsKey;\n\n activeClient.routing\n .getDirections(\n originRef.current,\n destRef.current,\n {\n alternatives,\n steps,\n overview,\n language,\n traffic_metadata,\n waypoints: waypointsRef.current,\n mode,\n route_preference,\n },\n { signal: controller.signal },\n )\n .then((res) => {\n if (!controller.signal.aborted) {\n setData(res);\n setError(null);\n setLoading(false);\n }\n })\n .catch((err: unknown) => {\n if (controller.signal.aborted || isAbortError(err)) return;\n setError(err instanceof Error ? err : new Error(String(err)));\n setLoading(false);\n });\n\n return () => {\n controller.abort();\n };\n }, [\n activeClient,\n enabled,\n originKey,\n destKey,\n alternatives,\n steps,\n overview,\n language,\n traffic_metadata,\n waypointsKey,\n mode,\n route_preference,\n reloadTick,\n ]);\n\n return {\n routes: data?.routes ?? [],\n data,\n loading,\n error,\n refetch,\n };\n}\n\nexport interface UseOlaReverseGeocodeOptions extends ReverseGeocodeOptions {\n enabled?: boolean;\n client?: OlaMapsClient;\n}\n\nexport interface UseOlaReverseGeocodeResult {\n results: GeocodeResult[];\n data: ReverseGeocodeResponse | null;\n loading: boolean;\n error: Error | null;\n refetch: () => void;\n}\n\n/**\n * Reverse-geocode a coordinate reactively with automatic `AbortController` cancellation.\n */\nexport function useOlaReverseGeocode(\n coordinate: Exclude<CoordinateInput, string> | null | undefined,\n options: UseOlaReverseGeocodeOptions = {},\n): UseOlaReverseGeocodeResult {\n const contextClient = useContext(OlaMapsContext);\n const activeClient = options.client ?? contextClient;\n if (!activeClient) {\n throw new Error('useOlaReverseGeocode requires <OlaMapsProvider> or options.client.');\n }\n\n const { enabled = true, language } = options;\n const coordKey = coordinate == null ? '' : JSON.stringify(coordinate);\n const coordRef = useRef(coordinate);\n coordRef.current = coordinate;\n\n const [data, setData] = useState<ReverseGeocodeResponse | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n const [reloadTick, setReloadTick] = useState(0);\n\n const refetch = useCallback(() => {\n setReloadTick((n) => n + 1);\n }, []);\n\n useEffect(() => {\n void reloadTick;\n\n if (!enabled || !coordKey || coordRef.current == null) {\n setLoading(false);\n return;\n }\n\n const controller = new AbortController();\n setLoading(true);\n setError(null);\n\n activeClient.places\n .reverseGeocode(coordRef.current, { language }, { signal: controller.signal })\n .then((res) => {\n if (!controller.signal.aborted) {\n setData(res);\n setError(null);\n setLoading(false);\n }\n })\n .catch((err: unknown) => {\n if (controller.signal.aborted || isAbortError(err)) return;\n setError(err instanceof Error ? err : new Error(String(err)));\n setLoading(false);\n });\n\n return () => {\n controller.abort();\n };\n }, [activeClient, enabled, coordKey, language, reloadTick]);\n\n return {\n results: data?.results ?? [],\n data,\n loading,\n error,\n refetch,\n };\n}\n"]}
package/package.json CHANGED
@@ -1,34 +1,134 @@
1
1
  {
2
2
  "name": "ola-map-sdk",
3
- "version": "1.3.0",
4
- "description": "Complete Ola Maps API SDK for Node.js — Places, Routing, Roads, Geofencing, Elevation, Tiles",
5
- "main": "src/index.js",
3
+ "version": "2.0.0",
4
+ "description": "Lightweight, zero-dependency TypeScript SDK for Ola Maps — Places, Routing, Roads, Geofencing, Elevation, Tiles, Street View, OAuth 2.0, MapLibre, Next.js & React",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "engines": {
8
+ "node": ">=18.0.0"
9
+ },
10
+ "main": "./dist/index.cjs",
11
+ "module": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "import": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ },
19
+ "require": {
20
+ "types": "./dist/index.d.cts",
21
+ "default": "./dist/index.cjs"
22
+ }
23
+ },
24
+ "./maplibre": {
25
+ "import": {
26
+ "types": "./dist/maplibre/index.d.ts",
27
+ "default": "./dist/maplibre/index.js"
28
+ },
29
+ "require": {
30
+ "types": "./dist/maplibre/index.d.cts",
31
+ "default": "./dist/maplibre/index.cjs"
32
+ }
33
+ },
34
+ "./next": {
35
+ "import": {
36
+ "types": "./dist/next/index.d.ts",
37
+ "default": "./dist/next/index.js"
38
+ },
39
+ "require": {
40
+ "types": "./dist/next/index.d.cts",
41
+ "default": "./dist/next/index.cjs"
42
+ }
43
+ },
44
+ "./react": {
45
+ "import": {
46
+ "types": "./dist/react/index.d.ts",
47
+ "default": "./dist/react/index.js"
48
+ },
49
+ "require": {
50
+ "types": "./dist/react/index.d.cts",
51
+ "default": "./dist/react/index.cjs"
52
+ }
53
+ }
54
+ },
55
+ "files": [
56
+ "dist",
57
+ "README.md",
58
+ "LICENSE"
59
+ ],
60
+ "scripts": {
61
+ "build": "tsup",
62
+ "dev": "tsup --watch",
63
+ "typecheck": "tsc --noEmit",
64
+ "lint": "biome check src tests",
65
+ "lint:fix": "biome check --write src tests",
66
+ "test": "vitest run",
67
+ "test:watch": "vitest",
68
+ "test:coverage": "vitest run --coverage",
69
+ "check:pkg": "publint --strict && attw --pack --profile node16",
70
+ "check": "npm run typecheck && npm run lint && npm run test && npm run build && npm run check:pkg",
71
+ "prepublishOnly": "npm run check"
72
+ },
6
73
  "keywords": [
7
74
  "ola",
8
75
  "maps",
9
76
  "sdk",
10
- "ola map",
11
- "maps api",
12
- "ola maps sdk",
77
+ "ola-map-sdk",
78
+ "ola maps",
13
79
  "ola maps api",
80
+ "ola maps sdk",
81
+ "typescript",
82
+ "zero-dependency",
14
83
  "maplibre",
84
+ "nextjs",
85
+ "react",
15
86
  "geocoding",
16
87
  "routing",
17
88
  "geofencing",
18
89
  "elevation",
90
+ "streetview",
19
91
  "places api",
20
92
  "distance matrix",
21
- "snap to road"
93
+ "snap to road",
94
+ "oauth2"
22
95
  ],
23
96
  "author": "Kunal Kongkan Kashyap",
24
97
  "license": "MIT",
25
- "dependencies": {
26
- "axios": "^1.7.2",
27
- "uuid": "^10.0.0"
98
+ "peerDependencies": {
99
+ "maplibre-gl": ">=3.0.0",
100
+ "next": ">=13.0.0",
101
+ "react": ">=18.0.0"
102
+ },
103
+ "peerDependenciesMeta": {
104
+ "maplibre-gl": {
105
+ "optional": true
106
+ },
107
+ "next": {
108
+ "optional": true
109
+ },
110
+ "react": {
111
+ "optional": true
112
+ }
113
+ },
114
+ "devDependencies": {
115
+ "@arethetypeswrong/cli": "^0.18.2",
116
+ "@biomejs/biome": "^1.9.4",
117
+ "@testing-library/react": "^16.3.0",
118
+ "@types/node": "^22.15.0",
119
+ "@types/react": "^19.1.0",
120
+ "@vitest/coverage-v8": "^3.1.4",
121
+ "happy-dom": "^17.4.6",
122
+ "publint": "^0.3.12",
123
+ "react": "^19.1.0",
124
+ "react-dom": "^19.1.0",
125
+ "tsup": "^8.5.0",
126
+ "typescript": "^5.8.3",
127
+ "vitest": "^3.1.4"
28
128
  },
29
129
  "repository": {
30
130
  "type": "git",
31
- "url": "https://github.com/kunalkcube/ola-map-sdk"
131
+ "url": "git+https://github.com/kunalkcube/ola-map-sdk.git"
32
132
  },
33
133
  "bugs": {
34
134
  "url": "https://github.com/kunalkcube/ola-map-sdk/issues"
package/src/client.js DELETED
@@ -1,95 +0,0 @@
1
- const axios = require('axios');
2
- const { v4: uuidv4 } = require('uuid');
3
- const Places = require('./endpoints/places');
4
- const Tiles = require('./endpoints/tiles');
5
- const Routing = require('./endpoints/routing');
6
- const Roads = require('./endpoints/roads');
7
- const Geofencing = require('./endpoints/geofencing');
8
- const Elevation = require('./endpoints/elevation');
9
-
10
- class OlaMapsClient {
11
- constructor(apiKey) {
12
- if (!apiKey) {
13
- throw new Error('API key is required.');
14
- }
15
-
16
- this.apiKey = apiKey;
17
- this.client = this.createAxiosClient();
18
-
19
- this.initializeEndpoints();
20
- }
21
-
22
- createAxiosClient() {
23
- return axios.create({
24
- baseURL: 'https://api.olamaps.io',
25
- headers: {
26
- 'Accept': 'application/json',
27
- 'X-Request-Id': uuidv4(),
28
- 'X-Correlation-Id': uuidv4(),
29
- },
30
- });
31
- }
32
-
33
- initializeEndpoints() {
34
- this.places = new Places(this.client, this.apiKey);
35
- this.tiles = new Tiles(this.client, this.apiKey);
36
- this.routing = new Routing(this.client, this.apiKey);
37
- this.roads = new Roads(this.client, this.apiKey);
38
- this.geofencing = new Geofencing(this.client, this.apiKey);
39
- this.elevation = new Elevation(this.client, this.apiKey);
40
- }
41
-
42
- // ── Map Helpers ──────────────────────────────────
43
-
44
- /**
45
- * Get the full style URL for use with MapLibre GL.
46
- * @param {string} [styleName='default-light-standard']
47
- * @returns {string}
48
- */
49
- getStyleURL(styleName = 'default-light-standard') {
50
- return `https://api.olamaps.io/tiles/vector/v1/styles/${styleName}/style.json`;
51
- }
52
-
53
- /**
54
- * Get a transformRequest function pre-configured with your API key.
55
- * Pass this directly to MapLibre GL's map options.
56
- * @returns {Function}
57
- */
58
- getTransformRequest() {
59
- const apiKey = this.apiKey;
60
- return (url, resourceType) => {
61
- url = url.replace('app.olamaps.io', 'api.olamaps.io');
62
- const separator = url.includes('?') ? '&' : '?';
63
- return { url: `${url}${separator}api_key=${apiKey}`, resourceType };
64
- };
65
- }
66
-
67
- /**
68
- * Get a complete options object for new maplibregl.Map().
69
- * Just pass the result directly:
70
- * const map = new maplibregl.Map(client.getMapOptions({ container: 'map' }));
71
- *
72
- * @param {Object} options
73
- * @param {string|HTMLElement} options.container - DOM element or element ID
74
- * @param {[number, number]} [options.center=[77.61, 12.93]] - [lng, lat]
75
- * @param {number} [options.zoom=14] - Zoom level
76
- * @param {string} [options.style='default-light-standard'] - Ola Maps style name
77
- * @returns {Object} Ready-to-use MapLibre GL map options
78
- */
79
- getMapOptions(options = {}) {
80
- return {
81
- container: options.container,
82
- style: this.getStyleURL(options.style || 'default-light-standard'),
83
- center: options.center || [77.61, 12.93],
84
- zoom: options.zoom ?? 14,
85
- transformRequest: this.getTransformRequest(),
86
- ...options,
87
- // Override style again in case user passed style as string name
88
- ...(typeof options.style === 'string' && !options.style.startsWith('http')
89
- ? { style: this.getStyleURL(options.style) }
90
- : {}),
91
- };
92
- }
93
- }
94
-
95
- module.exports = OlaMapsClient;
@@ -1,58 +0,0 @@
1
- class Elevation {
2
- constructor(client, apiKey) {
3
- this.client = client;
4
- this.apiKey = apiKey;
5
- }
6
-
7
- /**
8
- * Get elevation for a single location.
9
- * @param {number} lat - Latitude
10
- * @param {number} lng - Longitude
11
- */
12
- async getElevation(lat, lng) {
13
- if (typeof lat !== 'number' || typeof lng !== 'number') {
14
- throw new TypeError('Latitude and longitude must be numbers');
15
- }
16
- try {
17
- const { data } = await this.client.get('/places/v1/elevation', {
18
- params: { location: `${lat},${lng}`, api_key: this.apiKey },
19
- headers: { 'Accept': 'application/json' },
20
- });
21
- return data;
22
- } catch (error) {
23
- const errorMessage = error.response
24
- ? `Elevation API Error: ${error.response.status} - ${error.response.data.message}`
25
- : `Elevation API Error: ${error.message}`;
26
- console.error(errorMessage);
27
- throw new Error(errorMessage);
28
- }
29
- }
30
-
31
- /**
32
- * Get elevations for multiple locations.
33
- * @param {string[]} locations - Array of "lat,lng" strings (max 25)
34
- */
35
- async getMultiElevation(locations) {
36
- if (!Array.isArray(locations) || locations.length === 0) {
37
- throw new Error('locations must be a non-empty array of "lat,lng" strings');
38
- }
39
- if (locations.length > 25) {
40
- throw new Error('Maximum 25 locations allowed per request');
41
- }
42
- try {
43
- const { data } = await this.client.post('/places/v1/elevation', { locations }, {
44
- params: { api_key: this.apiKey },
45
- headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
46
- });
47
- return data;
48
- } catch (error) {
49
- const errorMessage = error.response
50
- ? `Elevation API Error: ${error.response.status} - ${error.response.data.message}`
51
- : `Elevation API Error: ${error.message}`;
52
- console.error(errorMessage);
53
- throw new Error(errorMessage);
54
- }
55
- }
56
- }
57
-
58
- module.exports = Elevation;