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.
- package/LICENSE +20 -20
- package/README.md +380 -137
- package/dist/chunk-22747AE4.js +978 -0
- package/dist/chunk-22747AE4.js.map +1 -0
- package/dist/chunk-5YVHNDSA.cjs +282 -0
- package/dist/chunk-5YVHNDSA.cjs.map +1 -0
- package/dist/chunk-6J7XUGWD.cjs +443 -0
- package/dist/chunk-6J7XUGWD.cjs.map +1 -0
- package/dist/chunk-7LV3RPED.js +440 -0
- package/dist/chunk-7LV3RPED.js.map +1 -0
- package/dist/chunk-D5T5ZDIQ.js +268 -0
- package/dist/chunk-D5T5ZDIQ.js.map +1 -0
- package/dist/chunk-SJJRTEQG.js +94 -0
- package/dist/chunk-SJJRTEQG.js.map +1 -0
- package/dist/chunk-WLUKC7YU.cjs +991 -0
- package/dist/chunk-WLUKC7YU.cjs.map +1 -0
- package/dist/chunk-XRJXKY7C.cjs +100 -0
- package/dist/chunk-XRJXKY7C.cjs.map +1 -0
- package/dist/client-Cd22y5wG.d.cts +782 -0
- package/dist/client-DsBMyuG9.d.ts +782 -0
- package/dist/common-Bt8xNzhK.d.cts +115 -0
- package/dist/common-Bt8xNzhK.d.ts +115 -0
- package/dist/index.cjs +115 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +88 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/maplibre/index.cjs +29 -0
- package/dist/maplibre/index.cjs.map +1 -0
- package/dist/maplibre/index.d.cts +63 -0
- package/dist/maplibre/index.d.ts +63 -0
- package/dist/maplibre/index.js +4 -0
- package/dist/maplibre/index.js.map +1 -0
- package/dist/next/index.cjs +173 -0
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +65 -0
- package/dist/next/index.d.ts +65 -0
- package/dist/next/index.js +169 -0
- package/dist/next/index.js.map +1 -0
- package/dist/react/index.cjs +257 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +77 -0
- package/dist/react/index.d.ts +77 -0
- package/dist/react/index.js +251 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +126 -11
- package/src/client.js +0 -37
- package/src/endpoints/places.js +0 -38
- package/src/endpoints/routing.js +0 -39
- package/src/endpoints/tiles.js +0 -55
- package/src/index.js +0 -4
|
@@ -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":["../../src/react/index.ts"],"names":[],"mappings":";;;;;;AAuBA,IAAM,cAAA,GAAiB,cAAoC,IAAI,CAAA;AAaxD,SAAS,eAAA,CAAgB,EAAE,MAAA,EAAQ,MAAA,EAAQ,UAAS,EAAyB;AAClF,EAAA,MAAM,cAAA,GAAiB,QAAQ,MAAM;AACnC,IAAA,IAAI,QAAQ,OAAO,MAAA;AACnB,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,MAAM,8DAA8D,CAAA;AAAA,IAChF;AACA,IAAA,OAAO,IAAI,cAAc,MAAM,CAAA;AAAA,EACjC,CAAA,EAAG,CAAC,MAAA,EAAQ,MAAM,CAAC,CAAA;AAEnB,EAAA,OAAO,cAAc,cAAA,CAAe,QAAA,EAAU,EAAE,KAAA,EAAO,cAAA,IAAkB,QAAQ,CAAA;AACnF;AAKO,SAAS,gBAAA,GAAkC;AAChD,EAAA,MAAM,MAAA,GAAS,WAAW,cAAc,CAAA;AACxC,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,MAAM,4DAA4D,CAAA;AAAA,EAC9E;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,aAAa,KAAA,EAAyB;AAC7C,EAAA,OAAO,KAAA,YAAiB,KAAA,IAAS,KAAA,CAAM,IAAA,KAAS,YAAA;AAClD;AAyBO,SAAS,kBAAA,C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AAA,CAAO,OAAA,EAAS;AAC9B,QAAA,OAAA,CAAQ,GAAG,CAAA;AACX,QAAA,QAAA,CAAS,IAAI,CAAA;AACb,QAAA,UAAA,CAAW,KAAK,CAAA;AAAA,MAClB;AAAA,IACF,CAAC,CAAA,CACA,KAAA,CAAM,CAAC,GAAA,KAAiB;AACvB,MAAA,IAAI,UAAA,CAAW,MAAA,CAAO,OAAA,IAAW,YAAA,CAAa,GAAG,CAAA,EAAG;AACpD,MAAA,QAAA,CAAS,GAAA,YAAe,QAAQ,GAAA,GAAM,IAAI,MAAM,MAAA,CAAO,GAAG,CAAC,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,22 +1,137 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ola-map-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
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
|
|
11
|
-
"maps
|
|
12
|
-
"ola maps sdk",
|
|
77
|
+
"ola-map-sdk",
|
|
78
|
+
"ola maps",
|
|
13
79
|
"ola maps api",
|
|
14
|
-
"ola maps sdk
|
|
80
|
+
"ola maps sdk",
|
|
81
|
+
"typescript",
|
|
82
|
+
"zero-dependency",
|
|
83
|
+
"maplibre",
|
|
84
|
+
"nextjs",
|
|
85
|
+
"react",
|
|
86
|
+
"geocoding",
|
|
87
|
+
"routing",
|
|
88
|
+
"geofencing",
|
|
89
|
+
"elevation",
|
|
90
|
+
"streetview",
|
|
91
|
+
"places api",
|
|
92
|
+
"distance matrix",
|
|
93
|
+
"snap to road",
|
|
94
|
+
"oauth2"
|
|
15
95
|
],
|
|
16
96
|
"author": "Kunal Kongkan Kashyap",
|
|
17
97
|
"license": "MIT",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
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"
|
|
128
|
+
},
|
|
129
|
+
"repository": {
|
|
130
|
+
"type": "git",
|
|
131
|
+
"url": "git+https://github.com/kunalkcube/ola-map-sdk.git"
|
|
132
|
+
},
|
|
133
|
+
"bugs": {
|
|
134
|
+
"url": "https://github.com/kunalkcube/ola-map-sdk/issues"
|
|
135
|
+
},
|
|
136
|
+
"homepage": "https://github.com/kunalkcube/ola-map-sdk#readme"
|
|
22
137
|
}
|
package/src/client.js
DELETED
|
@@ -1,37 +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
|
-
|
|
7
|
-
class OlaMapsClient {
|
|
8
|
-
constructor(apiKey) {
|
|
9
|
-
if (!apiKey) {
|
|
10
|
-
throw new Error('API key is required.');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
this.apiKey = apiKey;
|
|
14
|
-
this.client = this.createAxiosClient();
|
|
15
|
-
|
|
16
|
-
this.initializeEndpoints();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
createAxiosClient() {
|
|
20
|
-
return axios.create({
|
|
21
|
-
baseURL: 'https://api.olamaps.io',
|
|
22
|
-
headers: {
|
|
23
|
-
'Accept': 'application/json',
|
|
24
|
-
'X-Request-Id': uuidv4(),
|
|
25
|
-
'X-Correlation-Id': uuidv4(),
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
initializeEndpoints() {
|
|
31
|
-
this.places = new Places(this.client, this.apiKey);
|
|
32
|
-
this.tiles = new Tiles(this.client, this.apiKey);
|
|
33
|
-
this.routing = new Routing(this.client, this.apiKey);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
module.exports = OlaMapsClient;
|
package/src/endpoints/places.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
class Places {
|
|
2
|
-
constructor(client, apiKey) {
|
|
3
|
-
this.client = client;
|
|
4
|
-
this.apiKey = apiKey;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
async request(endpoint, params) {
|
|
8
|
-
try {
|
|
9
|
-
const { data } = await this.client.get(endpoint, {
|
|
10
|
-
params: { ...params, api_key: this.apiKey }
|
|
11
|
-
});
|
|
12
|
-
return data;
|
|
13
|
-
} catch (error) {
|
|
14
|
-
const errorMessage = error.response
|
|
15
|
-
? `Error ${error.response.status}: ${error.response.data.message}`
|
|
16
|
-
: `Request failed: ${error.message}`;
|
|
17
|
-
console.error(`Places API request failed: ${errorMessage}`);
|
|
18
|
-
throw new Error(`Places API request failed: ${errorMessage}`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
autocomplete(input) {
|
|
23
|
-
return this.request('/places/v1/autocomplete', { input });
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
geocode(address) {
|
|
27
|
-
return this.request('/places/v1/geocode', { address });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
reverseGeocode(lat, lng) {
|
|
31
|
-
if (typeof lat !== 'number' || typeof lng !== 'number') {
|
|
32
|
-
throw new TypeError('Latitude and longitude must be numbers');
|
|
33
|
-
}
|
|
34
|
-
return this.request('/places/v1/reverse-geocode', { latlng: `${lat},${lng}` });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = Places;
|
package/src/endpoints/routing.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
class Routing {
|
|
2
|
-
constructor(client, apiKey) {
|
|
3
|
-
this.client = client;
|
|
4
|
-
this.apiKey = apiKey;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
async getDirections(origin, destination, options = {}) {
|
|
8
|
-
const { lat: originLat, lon: originLon } = origin;
|
|
9
|
-
const { lat: destLat, lon: destLon } = destination;
|
|
10
|
-
|
|
11
|
-
const params = {
|
|
12
|
-
api_key: this.apiKey,
|
|
13
|
-
origin: `${originLat},${originLon}`,
|
|
14
|
-
destination: `${destLat},${destLon}`,
|
|
15
|
-
alternatives: options.alternatives ?? false,
|
|
16
|
-
steps: options.steps ?? false,
|
|
17
|
-
overview: options.overview ?? 'full',
|
|
18
|
-
language: options.language ?? 'en',
|
|
19
|
-
traffic_metadata: options.traffic_metadata ?? false,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const { data } = await this.client.post('/routing/v1/directions', null, {
|
|
24
|
-
params,
|
|
25
|
-
headers: { 'Accept': 'application/json' },
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
return data;
|
|
29
|
-
} catch (error) {
|
|
30
|
-
const errorMessage = error.response
|
|
31
|
-
? `Routing API Error: ${error.response.status} - ${error.response.data.message}`
|
|
32
|
-
: `Routing API Error: ${error.message}`;
|
|
33
|
-
console.error(errorMessage);
|
|
34
|
-
throw new Error(errorMessage);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
module.exports = Routing;
|
package/src/endpoints/tiles.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
class Tiles {
|
|
2
|
-
constructor(client, apiKey) {
|
|
3
|
-
this.client = client;
|
|
4
|
-
this.apiKey = apiKey;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
async request(endpoint, params = {}, headers = {}, responseType = 'json') {
|
|
8
|
-
try {
|
|
9
|
-
const response = await this.client.get(endpoint, {
|
|
10
|
-
params: { ...params, api_key: this.apiKey },
|
|
11
|
-
headers: { 'Accept': 'application/json', ...headers },
|
|
12
|
-
responseType,
|
|
13
|
-
});
|
|
14
|
-
return response.data;
|
|
15
|
-
} catch (error) {
|
|
16
|
-
const errorMessage = error.response
|
|
17
|
-
? `Tiles API Error: ${error.response.status} - ${error.response.data.message}`
|
|
18
|
-
: `Tiles API Error: ${error.message}`;
|
|
19
|
-
console.error(errorMessage);
|
|
20
|
-
throw new Error(errorMessage);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getDataTileJSON(datasetName) {
|
|
25
|
-
return this.request(`/tiles/vector/v1/data/${encodeURIComponent(datasetName)}.json`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getPBFFile(datasetName, z, x, y) {
|
|
29
|
-
return this.request(
|
|
30
|
-
`/tiles/vector/v1/data/${encodeURIComponent(datasetName)}/${z}/${x}/${y}.pbf`,
|
|
31
|
-
{},
|
|
32
|
-
{ 'Accept': 'application/x-protobuf' },
|
|
33
|
-
'arraybuffer'
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
getStyles() {
|
|
38
|
-
return this.request('/tiles/vector/v1/styles.json');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getStyleDetail(styleName) {
|
|
42
|
-
return this.request(`/tiles/vector/v1/styles/${encodeURIComponent(styleName)}/style.json`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
getFontGlyphs(fontstack, start, end) {
|
|
46
|
-
return this.request(
|
|
47
|
-
`/tiles/vector/v1/fonts/${encodeURIComponent(fontstack)}/${start}-${end}.pbf`,
|
|
48
|
-
{},
|
|
49
|
-
{ 'Accept': 'application/x-protobuf' },
|
|
50
|
-
'arraybuffer'
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports = Tiles;
|
package/src/index.js
DELETED