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,991 @@
1
+ 'use strict';
2
+
3
+ var chunkXRJXKY7C_cjs = require('./chunk-XRJXKY7C.cjs');
4
+ var chunk6J7XUGWD_cjs = require('./chunk-6J7XUGWD.cjs');
5
+ var chunk5YVHNDSA_cjs = require('./chunk-5YVHNDSA.cjs');
6
+
7
+ // src/core/validate.ts
8
+ function assertNonEmptyString(value, fieldName) {
9
+ if (typeof value !== "string" || value.trim().length === 0) {
10
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(`${fieldName} must be a non-empty string`);
11
+ }
12
+ return value.trim();
13
+ }
14
+ function assertFiniteNumber(value, fieldName) {
15
+ const num = typeof value === "string" && value.trim() !== "" ? Number(value) : value;
16
+ if (typeof num !== "number" || !Number.isFinite(num)) {
17
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(`${fieldName} must be a finite number`);
18
+ }
19
+ return num;
20
+ }
21
+ function assertRange(value, min, max, fieldName) {
22
+ if (!Number.isFinite(value) || value < min || value > max) {
23
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(
24
+ `${fieldName} must be between ${min} and ${max} (received ${value})`
25
+ );
26
+ }
27
+ return value;
28
+ }
29
+ function assertOneOf(value, allowed, fieldName) {
30
+ if (typeof value !== "string" || !allowed.includes(value)) {
31
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(`${fieldName} must be one of: ${allowed.join(", ")}`);
32
+ }
33
+ return value;
34
+ }
35
+ function parseLatLngPair(lat, lng, label = "coordinate") {
36
+ const parsedLat = assertRange(assertFiniteNumber(lat, `${label}.lat`), -90, 90, `${label}.lat`);
37
+ const parsedLng = assertRange(assertFiniteNumber(lng, `${label}.lng`), -180, 180, `${label}.lng`);
38
+ return { lat: parsedLat, lng: parsedLng };
39
+ }
40
+ function normalizeCoordinate(input, label = "coordinate") {
41
+ if (typeof input === "string") {
42
+ const parts = input.split(",");
43
+ if (parts.length !== 2) {
44
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(`${label} string must be in "lat,lng" format`);
45
+ }
46
+ return parseLatLngPair(parts[0].trim(), parts[1].trim(), label);
47
+ }
48
+ if (Array.isArray(input)) {
49
+ if (input.length !== 2) {
50
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(`${label} tuple must be [lng, lat] with exactly 2 elements`);
51
+ }
52
+ return parseLatLngPair(input[1], input[0], label);
53
+ }
54
+ if (input !== null && typeof input === "object") {
55
+ const obj = input;
56
+ const rawLng = obj.lng !== void 0 ? obj.lng : obj.lon;
57
+ if (obj.lat === void 0 || rawLng === void 0) {
58
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(`${label} object must include "lat" and "lng" (or "lon")`);
59
+ }
60
+ return parseLatLngPair(obj.lat, rawLng, label);
61
+ }
62
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(
63
+ `${label} must be { lat, lng }, { lat, lon }, [lng, lat], or "lat,lng"`
64
+ );
65
+ }
66
+ function formatLatLng(input, label = "coordinate") {
67
+ const { lat, lng } = normalizeCoordinate(input, label);
68
+ return `${lat},${lng}`;
69
+ }
70
+ function formatCoordinateList(input, options) {
71
+ const { label, min = 1, max } = options;
72
+ let rawItems;
73
+ if (typeof input === "string") {
74
+ const trimmed = input.trim();
75
+ if (!trimmed) {
76
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(`${label} must not be empty`);
77
+ }
78
+ rawItems = trimmed.split("|").map((item) => item.trim());
79
+ } else if (Array.isArray(input)) {
80
+ rawItems = input;
81
+ } else {
82
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(
83
+ `${label} must be a pipe-separated string or an array of coordinates`
84
+ );
85
+ }
86
+ if (rawItems.length < min) {
87
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(`${label} requires at least ${min} coordinate(s)`);
88
+ }
89
+ if (max !== void 0 && rawItems.length > max) {
90
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(
91
+ `${label} supports at most ${max} coordinates (received ${rawItems.length})`
92
+ );
93
+ }
94
+ return rawItems.map((coord, i) => formatLatLng(coord, `${label}[${i}]`)).join("|");
95
+ }
96
+
97
+ // src/endpoints/elevation.ts
98
+ var Elevation = class {
99
+ constructor(transport) {
100
+ this.transport = transport;
101
+ }
102
+ transport;
103
+ getElevation(latOrCoord, lngOrRequestOptions, maybeRequestOptions) {
104
+ let location;
105
+ let requestOptions;
106
+ if (typeof latOrCoord === "object" && latOrCoord !== null || typeof latOrCoord === "string" && latOrCoord.includes(",")) {
107
+ location = formatLatLng(latOrCoord, "location");
108
+ requestOptions = lngOrRequestOptions;
109
+ } else {
110
+ const parsed = parseLatLngPair(
111
+ latOrCoord,
112
+ lngOrRequestOptions,
113
+ "location"
114
+ );
115
+ location = `${parsed.lat},${parsed.lng}`;
116
+ requestOptions = maybeRequestOptions;
117
+ }
118
+ return this.transport.request({
119
+ method: "GET",
120
+ path: "/places/v1/elevation",
121
+ query: { location },
122
+ requestOptions
123
+ });
124
+ }
125
+ /**
126
+ * Get elevations for multiple locations (max 25 per request).
127
+ */
128
+ getMultiElevation(locations, requestOptions) {
129
+ if (!Array.isArray(locations) || locations.length === 0) {
130
+ throw new chunk5YVHNDSA_cjs.OlaValidationError("locations must be a non-empty array of coordinates");
131
+ }
132
+ if (locations.length > 25) {
133
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(
134
+ `Maximum 25 locations allowed per request (received ${locations.length})`
135
+ );
136
+ }
137
+ const formatted = locations.map((loc, index) => formatLatLng(loc, `locations[${index}]`));
138
+ return this.transport.request({
139
+ method: "POST",
140
+ path: "/places/v1/elevation",
141
+ body: { locations: formatted },
142
+ requestOptions
143
+ });
144
+ }
145
+ };
146
+
147
+ // src/endpoints/geofencing.ts
148
+ var Geofencing = class {
149
+ constructor(transport) {
150
+ this.transport = transport;
151
+ }
152
+ transport;
153
+ create(geofenceData, requestOptions) {
154
+ if (!geofenceData || typeof geofenceData !== "object") {
155
+ throw new chunk5YVHNDSA_cjs.OlaValidationError("geofenceData is required");
156
+ }
157
+ return this.transport.request({
158
+ method: "POST",
159
+ path: "/places/v1/geofence",
160
+ body: geofenceData,
161
+ requestOptions
162
+ });
163
+ }
164
+ update(id, geofenceData, requestOptions) {
165
+ const validatedId = assertNonEmptyString(id, "id");
166
+ if (!geofenceData || typeof geofenceData !== "object") {
167
+ throw new chunk5YVHNDSA_cjs.OlaValidationError("geofenceData is required");
168
+ }
169
+ return this.transport.request({
170
+ method: "PUT",
171
+ path: `/places/v1/geofence/${encodeURIComponent(validatedId)}`,
172
+ body: geofenceData,
173
+ requestOptions
174
+ });
175
+ }
176
+ getById(id, requestOptions) {
177
+ const validatedId = assertNonEmptyString(id, "id");
178
+ return this.transport.request({
179
+ method: "GET",
180
+ path: `/places/v1/geofence/${encodeURIComponent(validatedId)}`,
181
+ requestOptions
182
+ });
183
+ }
184
+ deleteById(id, requestOptions) {
185
+ const validatedId = assertNonEmptyString(id, "id");
186
+ return this.transport.request({
187
+ method: "DELETE",
188
+ path: `/places/v1/geofence/${encodeURIComponent(validatedId)}`,
189
+ requestOptions
190
+ });
191
+ }
192
+ list(projectId, page = 1, size = 10, requestOptions) {
193
+ const validatedProjectId = assertNonEmptyString(projectId, "projectId");
194
+ return this.transport.request({
195
+ method: "GET",
196
+ path: "/places/v1/geofences",
197
+ query: {
198
+ projectId: validatedProjectId,
199
+ page: assertFiniteNumber(page, "page"),
200
+ size: assertFiniteNumber(size, "size")
201
+ },
202
+ requestOptions
203
+ });
204
+ }
205
+ checkStatus(geofenceId, coordinates, requestOptions) {
206
+ return this.transport.request({
207
+ method: "GET",
208
+ path: "/places/v1/geofence/status",
209
+ query: {
210
+ geofenceId: assertNonEmptyString(geofenceId, "geofenceId"),
211
+ coordinates: formatLatLng(coordinates, "coordinates")
212
+ },
213
+ requestOptions
214
+ });
215
+ }
216
+ };
217
+
218
+ // src/endpoints/places.ts
219
+ var Places = class {
220
+ constructor(transport) {
221
+ this.transport = transport;
222
+ }
223
+ transport;
224
+ autocomplete(input, options = {}, requestOptions) {
225
+ const query = {
226
+ input: assertNonEmptyString(input, "input")
227
+ };
228
+ if (options.location !== void 0) {
229
+ query.location = formatLatLng(options.location, "options.location");
230
+ }
231
+ if (options.radius != null) query.radius = options.radius;
232
+ if (options.strictbounds != null) query.strictbounds = options.strictbounds;
233
+ if (options.language) query.language = options.language;
234
+ if (options.types) query.types = options.types;
235
+ return this.transport.request({
236
+ method: "GET",
237
+ path: "/places/v1/autocomplete",
238
+ query,
239
+ requestOptions
240
+ });
241
+ }
242
+ geocode(address, languageOrOptions, requestOptions) {
243
+ const query = {
244
+ address: assertNonEmptyString(address, "address")
245
+ };
246
+ if (typeof languageOrOptions === "string") {
247
+ if (languageOrOptions) query.language = languageOrOptions;
248
+ } else if (languageOrOptions) {
249
+ if (languageOrOptions.language) query.language = languageOrOptions.language;
250
+ if (languageOrOptions.bounds) query.bounds = languageOrOptions.bounds;
251
+ }
252
+ return this.transport.request({
253
+ method: "GET",
254
+ path: "/places/v1/geocode",
255
+ query,
256
+ requestOptions
257
+ });
258
+ }
259
+ reverseGeocode(latOrCoordinate, lngOrOptions, languageOrRequestOptions, maybeRequestOptions) {
260
+ let latlng;
261
+ let language;
262
+ let requestOptions;
263
+ if (typeof latOrCoordinate === "object" && latOrCoordinate !== null) {
264
+ latlng = formatLatLng(latOrCoordinate, "coordinate");
265
+ if (typeof lngOrOptions === "string") {
266
+ language = lngOrOptions;
267
+ } else if (lngOrOptions && typeof lngOrOptions === "object") {
268
+ language = lngOrOptions.language;
269
+ }
270
+ requestOptions = languageOrRequestOptions;
271
+ } else {
272
+ const parsed = parseLatLngPair(
273
+ latOrCoordinate,
274
+ lngOrOptions,
275
+ "reverseGeocode"
276
+ );
277
+ latlng = `${parsed.lat},${parsed.lng}`;
278
+ if (typeof languageOrRequestOptions === "string") {
279
+ language = languageOrRequestOptions;
280
+ } else if (languageOrRequestOptions && typeof languageOrRequestOptions === "object" && "language" in languageOrRequestOptions) {
281
+ language = languageOrRequestOptions.language;
282
+ }
283
+ requestOptions = maybeRequestOptions;
284
+ }
285
+ const query = { latlng };
286
+ if (language) query.language = language;
287
+ return this.transport.request({
288
+ method: "GET",
289
+ path: "/places/v1/reverse-geocode",
290
+ query,
291
+ requestOptions
292
+ });
293
+ }
294
+ placeDetails(placeId, language, requestOptions) {
295
+ const query = {
296
+ place_id: assertNonEmptyString(placeId, "placeId")
297
+ };
298
+ if (language) query.language = language;
299
+ return this.transport.request({
300
+ method: "GET",
301
+ path: "/places/v1/details",
302
+ query,
303
+ requestOptions
304
+ });
305
+ }
306
+ placeDetailsAdvanced(placeId, language, requestOptions) {
307
+ const query = {
308
+ place_id: assertNonEmptyString(placeId, "placeId")
309
+ };
310
+ if (language) query.language = language;
311
+ return this.transport.request({
312
+ method: "GET",
313
+ path: "/places/v1/details/advanced",
314
+ query,
315
+ requestOptions
316
+ });
317
+ }
318
+ nearbySearch(location, options = {}, requestOptions) {
319
+ return this.executeNearbySearch("/places/v1/nearbysearch", location, options, requestOptions);
320
+ }
321
+ nearbySearchAdvanced(location, options = {}, requestOptions) {
322
+ return this.executeNearbySearch(
323
+ "/places/v1/nearbysearch/advanced",
324
+ location,
325
+ options,
326
+ requestOptions
327
+ );
328
+ }
329
+ textSearch(input, options = {}, requestOptions) {
330
+ const query = {
331
+ input: assertNonEmptyString(input, "input")
332
+ };
333
+ if (options.location !== void 0) {
334
+ query.location = formatLatLng(options.location, "options.location");
335
+ }
336
+ if (options.radius != null) query.radius = options.radius;
337
+ if (options.types) query.types = options.types;
338
+ if (options.size != null) query.size = options.size;
339
+ return this.transport.request({
340
+ method: "GET",
341
+ path: "/places/v1/textsearch",
342
+ query,
343
+ requestOptions
344
+ });
345
+ }
346
+ addressValidation(address, requestOptions) {
347
+ return this.transport.request({
348
+ method: "GET",
349
+ path: "/places/v1/addressvalidation",
350
+ query: { address: assertNonEmptyString(address, "address") },
351
+ requestOptions
352
+ });
353
+ }
354
+ photo(photoReference, requestOptions) {
355
+ return this.transport.request({
356
+ method: "GET",
357
+ path: "/places/v1/photo",
358
+ query: { photo_reference: assertNonEmptyString(photoReference, "photoReference") },
359
+ requestOptions
360
+ });
361
+ }
362
+ executeNearbySearch(path, location, options, requestOptions) {
363
+ const query = {
364
+ location: formatLatLng(location, "location")
365
+ };
366
+ if (options.layers) query.layers = options.layers;
367
+ if (options.types) query.types = options.types;
368
+ if (options.language) query.language = options.language;
369
+ if (options.radius != null) query.radius = options.radius;
370
+ if (options.withCentroid != null) query.withCentroid = options.withCentroid;
371
+ if (options.rankBy) query.rankBy = options.rankBy;
372
+ if (options.limit != null) {
373
+ query.limit = assertRange(options.limit, 1, 50, "options.limit");
374
+ }
375
+ return this.transport.request({
376
+ method: "GET",
377
+ path,
378
+ query,
379
+ requestOptions
380
+ });
381
+ }
382
+ };
383
+
384
+ // src/endpoints/roads.ts
385
+ var NEAREST_ROADS_MODES = [
386
+ "DRIVING",
387
+ "WALKING",
388
+ "BICYCLING",
389
+ "TRANSIT"
390
+ ];
391
+ var SNAP_STRATEGIES = ["snaptoroad", "nearestroad"];
392
+ var Roads = class {
393
+ constructor(transport) {
394
+ this.transport = transport;
395
+ }
396
+ transport;
397
+ /**
398
+ * Snap up to 50 coordinates to the nearest road segments.
399
+ */
400
+ snapToRoad(points, enhancePathOrOptions = false, requestOptions) {
401
+ const formattedPoints = formatCoordinateList(points, {
402
+ label: "points",
403
+ min: 1,
404
+ max: 50
405
+ });
406
+ const enhancePath = typeof enhancePathOrOptions === "boolean" ? enhancePathOrOptions : enhancePathOrOptions.enhancePath ?? false;
407
+ return this.transport.request({
408
+ method: "GET",
409
+ path: "/routing/v1/snapToRoad",
410
+ query: { points: formattedPoints, enhancePath },
411
+ requestOptions
412
+ });
413
+ }
414
+ /**
415
+ * Find nearest roads for up to 100 coordinates.
416
+ */
417
+ nearestRoads(points, mode, radiusOrOptions, requestOptions) {
418
+ const formattedPoints = formatCoordinateList(points, {
419
+ label: "points",
420
+ min: 1,
421
+ max: 100
422
+ });
423
+ const validatedMode = assertOneOf(mode, NEAREST_ROADS_MODES, "mode");
424
+ const query = {
425
+ points: formattedPoints,
426
+ mode: validatedMode
427
+ };
428
+ const radius = typeof radiusOrOptions === "number" ? radiusOrOptions : radiusOrOptions?.radius;
429
+ if (radius != null) {
430
+ query.radius = assertFiniteNumber(radius, "radius");
431
+ }
432
+ return this.transport.request({
433
+ method: "GET",
434
+ path: "/routing/v1/nearestRoads",
435
+ query,
436
+ requestOptions
437
+ });
438
+ }
439
+ /**
440
+ * Get speed limits for up to 50 coordinates along snapped road segments.
441
+ */
442
+ speedLimits(points, snapStrategyOrOptions = "snaptoroad", requestOptions) {
443
+ const formattedPoints = formatCoordinateList(points, {
444
+ label: "points",
445
+ min: 1,
446
+ max: 50
447
+ });
448
+ const rawStrategy = typeof snapStrategyOrOptions === "string" ? snapStrategyOrOptions : snapStrategyOrOptions.snapStrategy ?? "snaptoroad";
449
+ const snapStrategy = assertOneOf(rawStrategy, SNAP_STRATEGIES, "snapStrategy");
450
+ return this.transport.request({
451
+ method: "GET",
452
+ path: "/routing/v1/speedLimits",
453
+ query: { points: formattedPoints, snapStrategy },
454
+ requestOptions
455
+ });
456
+ }
457
+ };
458
+
459
+ // src/endpoints/routing.ts
460
+ var Routing = class {
461
+ constructor(transport) {
462
+ this.transport = transport;
463
+ }
464
+ transport;
465
+ getDirections(origin, destination, options = {}, requestOptions) {
466
+ const query = {
467
+ origin: formatLatLng(origin, "origin"),
468
+ destination: formatLatLng(destination, "destination"),
469
+ alternatives: options.alternatives ?? false,
470
+ steps: options.steps ?? true,
471
+ overview: options.overview ?? "full",
472
+ language: options.language ?? "en",
473
+ traffic_metadata: options.traffic_metadata ?? false
474
+ };
475
+ if (options.waypoints !== void 0) {
476
+ query.waypoints = formatCoordinateList(options.waypoints, {
477
+ label: "options.waypoints",
478
+ min: 1
479
+ });
480
+ }
481
+ if (options.mode) query.mode = options.mode;
482
+ if (options.route_preference) query.route_preference = options.route_preference;
483
+ return this.transport.request({
484
+ method: "POST",
485
+ path: "/routing/v1/directions",
486
+ query,
487
+ requestOptions
488
+ });
489
+ }
490
+ getDirectionsBasic(origin, destination, options = {}, requestOptions) {
491
+ const query = {
492
+ origin: formatLatLng(origin, "origin"),
493
+ destination: formatLatLng(destination, "destination"),
494
+ alternatives: options.alternatives ?? false,
495
+ steps: options.steps ?? true,
496
+ overview: options.overview ?? "full",
497
+ language: options.language ?? "en"
498
+ };
499
+ if (options.waypoints !== void 0) {
500
+ query.waypoints = formatCoordinateList(options.waypoints, {
501
+ label: "options.waypoints",
502
+ min: 1
503
+ });
504
+ }
505
+ if (options.route_preference) query.route_preference = options.route_preference;
506
+ return this.transport.request({
507
+ method: "POST",
508
+ path: "/routing/v1/directions/basic",
509
+ query,
510
+ requestOptions
511
+ });
512
+ }
513
+ getDistanceMatrix(origins, destinations, options = {}, requestOptions) {
514
+ const query = {
515
+ origins: formatCoordinateList(origins, { label: "origins", min: 1 }),
516
+ destinations: formatCoordinateList(destinations, { label: "destinations", min: 1 }),
517
+ mode: options.mode ?? "driving"
518
+ };
519
+ if (options.route_preference) query.route_preference = options.route_preference;
520
+ return this.transport.request({
521
+ method: "GET",
522
+ path: "/routing/v1/distanceMatrix",
523
+ query,
524
+ requestOptions
525
+ });
526
+ }
527
+ getDistanceMatrixBasic(origins, destinations, options = {}, requestOptions) {
528
+ const query = {
529
+ origins: formatCoordinateList(origins, { label: "origins", min: 1 }),
530
+ destinations: formatCoordinateList(destinations, { label: "destinations", min: 1 })
531
+ };
532
+ if (options.route_preference) query.route_preference = options.route_preference;
533
+ return this.transport.request({
534
+ method: "GET",
535
+ path: "/routing/v1/distanceMatrix/basic",
536
+ query,
537
+ requestOptions
538
+ });
539
+ }
540
+ /**
541
+ * Optimize waypoint order for up to 25 locations.
542
+ */
543
+ routeOptimizer(locations, options = {}, requestOptions) {
544
+ const query = {
545
+ locations: formatCoordinateList(locations, {
546
+ label: "locations",
547
+ min: 1,
548
+ max: 25
549
+ }),
550
+ source: options.source ?? "first",
551
+ destination: options.destination ?? "last",
552
+ round_trip: options.round_trip ?? false,
553
+ mode: options.mode ?? "driving",
554
+ steps: options.steps ?? true,
555
+ overview: options.overview ?? "full",
556
+ language: options.language ?? "en",
557
+ traffic_metadata: options.traffic_metadata ?? false
558
+ };
559
+ if (options.route_preference) query.route_preference = options.route_preference;
560
+ return this.transport.request({
561
+ method: "POST",
562
+ path: "/routing/v1/routeOptimizer",
563
+ query,
564
+ requestOptions
565
+ });
566
+ }
567
+ /**
568
+ * Plan multi-vehicle fleet routes using browser/Edge/Node-safe Web `FormData` & `Blob`.
569
+ * Accepts a plain JSON object, JSON string, `Blob`/`File`, `Uint8Array`, or `ArrayBuffer`.
570
+ */
571
+ fleetPlanner(inputData, strategy, options = {}, requestOptions) {
572
+ if (inputData === void 0 || inputData === null) {
573
+ throw new chunk5YVHNDSA_cjs.OlaValidationError("inputData is required");
574
+ }
575
+ const normalizedStrategy = assertNonEmptyString(strategy, "strategy");
576
+ const filename = options.filename ?? "input.json";
577
+ const form = new FormData();
578
+ let blob;
579
+ if (typeof Blob !== "undefined" && inputData instanceof Blob) {
580
+ blob = inputData;
581
+ } else if (inputData instanceof ArrayBuffer) {
582
+ blob = new Blob([inputData], { type: "application/json" });
583
+ } else if (inputData instanceof Uint8Array) {
584
+ const copy = new Uint8Array(inputData.byteLength);
585
+ copy.set(inputData);
586
+ blob = new Blob([copy], { type: "application/json" });
587
+ } else if (typeof inputData === "string") {
588
+ blob = new Blob([inputData], { type: "application/json" });
589
+ } else if (typeof inputData === "object") {
590
+ blob = new Blob([JSON.stringify(inputData)], { type: "application/json" });
591
+ } else {
592
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(
593
+ "inputData must be a JSON object, JSON string, Blob, Uint8Array, or ArrayBuffer"
594
+ );
595
+ }
596
+ form.append("input", blob, filename);
597
+ const query = {
598
+ strategy: normalizedStrategy
599
+ };
600
+ if (options.route_preference) query.route_preference = options.route_preference;
601
+ return this.transport.request({
602
+ method: "POST",
603
+ path: "/routing/v1/fleetPlanner",
604
+ query,
605
+ body: form,
606
+ requestOptions
607
+ });
608
+ }
609
+ };
610
+
611
+ // src/endpoints/streetview.ts
612
+ var StreetView = class {
613
+ constructor(transport) {
614
+ this.transport = transport;
615
+ }
616
+ transport;
617
+ /**
618
+ * Fetch Street View coverage geometry within a bounding box.
619
+ * Accepts `{ xMin, yMin, xMax, yMax }` or `{ minLng, minLat, maxLng, maxLat }`.
620
+ */
621
+ getCoverage(bbox, requestOptions) {
622
+ if (!bbox || typeof bbox !== "object") {
623
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(
624
+ "bbox must be an object with { xMin, yMin, xMax, yMax } or { minLng, minLat, maxLng, maxLat }"
625
+ );
626
+ }
627
+ const rawXMin = "xMin" in bbox ? bbox.xMin : bbox.minLng;
628
+ const rawYMin = "yMin" in bbox ? bbox.yMin : bbox.minLat;
629
+ const rawXMax = "xMax" in bbox ? bbox.xMax : bbox.maxLng;
630
+ const rawYMax = "yMax" in bbox ? bbox.yMax : bbox.maxLat;
631
+ const xMin = assertRange(assertFiniteNumber(rawXMin, "xMin"), -180, 180, "xMin");
632
+ const yMin = assertRange(assertFiniteNumber(rawYMin, "yMin"), -90, 90, "yMin");
633
+ const xMax = assertRange(assertFiniteNumber(rawXMax, "xMax"), -180, 180, "xMax");
634
+ const yMax = assertRange(assertFiniteNumber(rawYMax, "yMax"), -90, 90, "yMax");
635
+ if (xMin >= xMax || yMin >= yMax) {
636
+ throw new chunk5YVHNDSA_cjs.OlaValidationError("bbox requires xMin < xMax and yMin < yMax");
637
+ }
638
+ return this.transport.request({
639
+ method: "GET",
640
+ path: "/sli/v1/streetview/coverage",
641
+ query: { xMin, yMin, xMax, yMax },
642
+ requestOptions
643
+ });
644
+ }
645
+ getImageId(latOrCoordinate, lonOrOptions, optionsOrRequestOptions, maybeRequestOptions) {
646
+ let lat;
647
+ let lon;
648
+ let options;
649
+ let requestOptions;
650
+ if (typeof latOrCoordinate === "object" && latOrCoordinate !== null) {
651
+ const normalized = normalizeCoordinate(latOrCoordinate, "coordinate");
652
+ lat = normalized.lat;
653
+ lon = normalized.lng;
654
+ options = lonOrOptions;
655
+ requestOptions = optionsOrRequestOptions;
656
+ } else {
657
+ const parsed = parseLatLngPair(
658
+ latOrCoordinate,
659
+ lonOrOptions,
660
+ "streetView.getImageId"
661
+ );
662
+ lat = parsed.lat;
663
+ lon = parsed.lng;
664
+ options = optionsOrRequestOptions;
665
+ requestOptions = maybeRequestOptions;
666
+ }
667
+ const query = { lat, lon };
668
+ if (options?.radius != null) {
669
+ query.radius = assertFiniteNumber(options.radius, "options.radius");
670
+ }
671
+ return this.transport.request({
672
+ method: "GET",
673
+ path: "/sli/streetview/imageId",
674
+ query,
675
+ requestOptions
676
+ });
677
+ }
678
+ /**
679
+ * Fetch panoramic image metadata (`lat`, `lon`, `bearing`, `imageUrl`, `neighbors`) for an `imageId`.
680
+ */
681
+ getMetadata(imageId, requestOptions) {
682
+ return this.transport.request({
683
+ method: "GET",
684
+ path: "/sli/streetview/metadata",
685
+ query: { imageId: assertNonEmptyString(imageId, "imageId") },
686
+ requestOptions
687
+ });
688
+ }
689
+ };
690
+
691
+ // src/endpoints/tiles.ts
692
+ var STATIC_MAP_FORMATS = ["png", "jpg"];
693
+ function validateDimensions(width, height) {
694
+ assertRange(assertFiniteNumber(width, "width"), 1, 2048, "width");
695
+ assertRange(assertFiniteNumber(height, "height"), 1, 2048, "height");
696
+ }
697
+ function buildStaticMapQuery(options) {
698
+ const query = {};
699
+ if (options.marker !== void 0) {
700
+ query.marker = options.marker;
701
+ }
702
+ if (options.path !== void 0) {
703
+ query.path = options.path;
704
+ }
705
+ return query;
706
+ }
707
+ var Tiles = class {
708
+ constructor(transport) {
709
+ this.transport = transport;
710
+ }
711
+ transport;
712
+ /**
713
+ * Fetch TileJSON metadata for a vector tile dataset.
714
+ * Note: Vector tile dataset helpers correspond to Ola's vector tile service endpoints.
715
+ */
716
+ getDataTileJSON(datasetName, requestOptions) {
717
+ const name = assertNonEmptyString(datasetName, "datasetName");
718
+ return this.transport.request({
719
+ method: "GET",
720
+ path: `/tiles/vector/v1/data/${encodeURIComponent(name)}.json`,
721
+ requestOptions
722
+ });
723
+ }
724
+ /**
725
+ * Fetch a raw Mapbox Vector Tile (.pbf) as an `ArrayBuffer`.
726
+ */
727
+ getPBFFile(datasetName, z, x, y, requestOptions) {
728
+ const name = assertNonEmptyString(datasetName, "datasetName");
729
+ const zoom = assertRange(assertFiniteNumber(z, "z"), 0, 24, "z");
730
+ const tileX = assertFiniteNumber(x, "x");
731
+ const tileY = assertFiniteNumber(y, "y");
732
+ return this.transport.request({
733
+ method: "GET",
734
+ path: `/tiles/vector/v1/data/${encodeURIComponent(name)}/${zoom}/${tileX}/${tileY}.pbf`,
735
+ headers: { Accept: "application/x-protobuf" },
736
+ responseFormat: "arrayBuffer",
737
+ requestOptions
738
+ });
739
+ }
740
+ /**
741
+ * Fetch a raster map tile image (`/{z}/{x}/{y}.{format}`) as an `ArrayBuffer`.
742
+ */
743
+ getRasterTile(styleName, z, x, y, format = "png", requestOptions) {
744
+ const style = assertNonEmptyString(styleName, "styleName");
745
+ const zoom = assertRange(assertFiniteNumber(z, "z"), 0, 24, "z");
746
+ const tileX = assertFiniteNumber(x, "x");
747
+ const tileY = assertFiniteNumber(y, "y");
748
+ const validFormat = assertOneOf(format, STATIC_MAP_FORMATS, "format");
749
+ return this.transport.request({
750
+ method: "GET",
751
+ path: `/tiles/v1/styles/${encodeURIComponent(style)}/${zoom}/${tileX}/${tileY}.${validFormat}`,
752
+ headers: { Accept: validFormat === "png" ? "image/png" : "image/jpeg" },
753
+ responseFormat: "arrayBuffer",
754
+ requestOptions
755
+ });
756
+ }
757
+ /**
758
+ * List all available Ola Maps vector styles.
759
+ */
760
+ getStyles(requestOptions) {
761
+ return this.transport.request({
762
+ method: "GET",
763
+ path: "/tiles/vector/v1/styles.json",
764
+ requestOptions
765
+ });
766
+ }
767
+ /**
768
+ * Fetch a MapLibre Style Specification JSON for a named Ola Maps style.
769
+ */
770
+ getStyleDetail(styleName, requestOptions) {
771
+ const name = assertNonEmptyString(styleName, "styleName");
772
+ return this.transport.request({
773
+ method: "GET",
774
+ path: `/tiles/vector/v1/styles/${encodeURIComponent(name)}/style.json`,
775
+ requestOptions
776
+ });
777
+ }
778
+ /**
779
+ * Fetch SDF font glyph ranges (.pbf) as an `ArrayBuffer`.
780
+ */
781
+ getFontGlyphs(fontstack, start, end, requestOptions) {
782
+ const font = assertNonEmptyString(fontstack, "fontstack");
783
+ const startCode = assertRange(assertFiniteNumber(start, "start"), 0, 65535, "start");
784
+ const endCode = assertRange(assertFiniteNumber(end, "end"), startCode, 65535, "end");
785
+ return this.transport.request({
786
+ method: "GET",
787
+ path: `/tiles/vector/v1/fonts/${encodeURIComponent(font)}/${startCode}-${endCode}.pbf`,
788
+ headers: { Accept: "application/x-protobuf" },
789
+ responseFormat: "arrayBuffer",
790
+ requestOptions
791
+ });
792
+ }
793
+ /**
794
+ * Fetch a static map image centered on `(lon, lat)` at a given `zoom` (0–23).
795
+ * Width and height must be between 1 and 2048 pixels.
796
+ */
797
+ getStaticMapByCenter(styleName, lon, lat, zoom, width, height, format, options = {}, requestOptions) {
798
+ const style = assertNonEmptyString(styleName, "styleName");
799
+ const validLon = assertRange(assertFiniteNumber(lon, "lon"), -180, 180, "lon");
800
+ const validLat = assertRange(assertFiniteNumber(lat, "lat"), -90, 90, "lat");
801
+ const validZoom = assertRange(assertFiniteNumber(zoom, "zoom"), 0, 23, "zoom");
802
+ validateDimensions(width, height);
803
+ const validFormat = assertOneOf(format, STATIC_MAP_FORMATS, "format");
804
+ return this.transport.request({
805
+ method: "GET",
806
+ path: `/tiles/v1/styles/${encodeURIComponent(style)}/static/${validLon},${validLat},${validZoom}/${width}x${height}.${validFormat}`,
807
+ query: buildStaticMapQuery(options),
808
+ headers: { Accept: validFormat === "png" ? "image/png" : "image/jpeg" },
809
+ responseFormat: "arrayBuffer",
810
+ requestOptions
811
+ });
812
+ }
813
+ /**
814
+ * Fetch a static map image bounded by `{ minx, miny, maxx, maxy }`.
815
+ */
816
+ getStaticMapByBBox(styleName, bbox, width, height, format, options = {}, requestOptions) {
817
+ const style = assertNonEmptyString(styleName, "styleName");
818
+ if (!bbox || typeof bbox !== "object") {
819
+ throw new chunk5YVHNDSA_cjs.OlaValidationError("bbox must be an object with { minx, miny, maxx, maxy }");
820
+ }
821
+ const minx = assertRange(assertFiniteNumber(bbox.minx, "bbox.minx"), -180, 180, "bbox.minx");
822
+ const miny = assertRange(assertFiniteNumber(bbox.miny, "bbox.miny"), -90, 90, "bbox.miny");
823
+ const maxx = assertRange(assertFiniteNumber(bbox.maxx, "bbox.maxx"), -180, 180, "bbox.maxx");
824
+ const maxy = assertRange(assertFiniteNumber(bbox.maxy, "bbox.maxy"), -90, 90, "bbox.maxy");
825
+ if (minx >= maxx || miny >= maxy) {
826
+ throw new chunk5YVHNDSA_cjs.OlaValidationError("bbox requires minx < maxx and miny < maxy");
827
+ }
828
+ validateDimensions(width, height);
829
+ const validFormat = assertOneOf(format, STATIC_MAP_FORMATS, "format");
830
+ return this.transport.request({
831
+ method: "GET",
832
+ path: `/tiles/v1/styles/${encodeURIComponent(style)}/static/${minx},${miny},${maxx},${maxy}/${width}x${height}.${validFormat}`,
833
+ query: buildStaticMapQuery(options),
834
+ headers: { Accept: validFormat === "png" ? "image/png" : "image/jpeg" },
835
+ responseFormat: "arrayBuffer",
836
+ requestOptions
837
+ });
838
+ }
839
+ /**
840
+ * Fetch a static map image with auto-fit bounds.
841
+ * Requires at least one `marker` or `path` in `options`.
842
+ */
843
+ getStaticMapAuto(styleName, width, height, format, options, requestOptions) {
844
+ const style = assertNonEmptyString(styleName, "styleName");
845
+ validateDimensions(width, height);
846
+ const validFormat = assertOneOf(format, STATIC_MAP_FORMATS, "format");
847
+ const hasMarker = Array.isArray(options?.marker) ? options.marker.length > 0 : typeof options?.marker === "string" && options.marker.trim().length > 0;
848
+ const hasPath = typeof options?.path === "string" && options.path.trim().length > 0;
849
+ if (!hasMarker && !hasPath) {
850
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(
851
+ "getStaticMapAuto requires at least one marker or path option to compute bounds"
852
+ );
853
+ }
854
+ return this.transport.request({
855
+ method: "GET",
856
+ path: `/tiles/v1/styles/${encodeURIComponent(style)}/static/auto/${width}x${height}.${validFormat}`,
857
+ query: buildStaticMapQuery(options),
858
+ headers: { Accept: validFormat === "png" ? "image/png" : "image/jpeg" },
859
+ responseFormat: "arrayBuffer",
860
+ requestOptions
861
+ });
862
+ }
863
+ /**
864
+ * Fetch the 3D buildings tileset JSON.
865
+ */
866
+ get3DTileset(requestOptions) {
867
+ return this.transport.request({
868
+ method: "GET",
869
+ path: "/tiles/vector/v1/3dtiles/tileset.json",
870
+ requestOptions
871
+ });
872
+ }
873
+ };
874
+
875
+ // src/client.ts
876
+ var OlaMapsClient = class {
877
+ places;
878
+ tiles;
879
+ routing;
880
+ roads;
881
+ geofencing;
882
+ elevation;
883
+ streetView;
884
+ auth;
885
+ transport;
886
+ staticAccessToken;
887
+ /**
888
+ * Create an Ola Maps client.
889
+ *
890
+ * Supports both the v1 shorthand (`new OlaMapsClient('YOUR_API_KEY')`) and the
891
+ * v2 configuration object supporting API Key, OAuth 2.0 (`client_credentials`),
892
+ * pre-issued Bearer `accessToken`, or Proxy Mode (`{ baseUrl: '/api/ola-maps' }`).
893
+ */
894
+ constructor(configOrApiKey) {
895
+ let config;
896
+ if (typeof configOrApiKey === "string") {
897
+ if (!configOrApiKey.trim()) {
898
+ throw new chunk5YVHNDSA_cjs.OlaValidationError("API key is required.");
899
+ }
900
+ config = { apiKey: configOrApiKey };
901
+ } else if (configOrApiKey && typeof configOrApiKey === "object") {
902
+ config = configOrApiKey;
903
+ } else {
904
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(
905
+ "OlaMapsClient requires an API key string or configuration object."
906
+ );
907
+ }
908
+ const fetchImpl = config.fetch ?? globalThis.fetch?.bind(globalThis);
909
+ if (!fetchImpl) {
910
+ throw new chunk5YVHNDSA_cjs.OlaValidationError(
911
+ "No global fetch implementation found. Use Node 18+ or pass a custom `fetch` in config."
912
+ );
913
+ }
914
+ this.auth = new chunk5YVHNDSA_cjs.AuthManager(config, fetchImpl);
915
+ this.transport = new chunk6J7XUGWD_cjs.HttpTransport(config, this.auth, fetchImpl);
916
+ this.staticAccessToken = typeof config.accessToken === "string" ? config.accessToken : void 0;
917
+ this.places = new Places(this.transport);
918
+ this.tiles = new Tiles(this.transport);
919
+ this.routing = new Routing(this.transport);
920
+ this.roads = new Roads(this.transport);
921
+ this.geofencing = new Geofencing(this.transport);
922
+ this.elevation = new Elevation(this.transport);
923
+ this.streetView = new StreetView(this.transport);
924
+ }
925
+ /** Active authentication mode (`'apiKey'`, `'oauth'`, `'accessToken'`, or `'proxy'`). */
926
+ get authMode() {
927
+ return this.auth.mode;
928
+ }
929
+ /** Configured API base URL. */
930
+ get baseUrl() {
931
+ return this.transport.baseUrl;
932
+ }
933
+ /**
934
+ * Fetch or return the cached OAuth 2.0 / Bearer access token.
935
+ */
936
+ getAccessToken(forceRefresh = false) {
937
+ return this.auth.getAccessToken(forceRefresh);
938
+ }
939
+ /**
940
+ * Clear any cached in-memory GET responses.
941
+ */
942
+ clearCache() {
943
+ this.transport.clearCache();
944
+ }
945
+ // ── MapLibre GL Convenience Helpers ───────────────────────────────
946
+ /**
947
+ * Get the full MapLibre style URL for a named Ola Maps style.
948
+ */
949
+ getStyleURL(styleName = "default-light-standard") {
950
+ const styleBase = this.auth.mode === "proxy" ? this.transport.baseUrl : chunk5YVHNDSA_cjs.DEFAULT_BASE_URL;
951
+ return chunkXRJXKY7C_cjs.getStyleURL(styleName, styleBase);
952
+ }
953
+ /**
954
+ * Get a host-safe MapLibre `transformRequest` callback.
955
+ * Credentials are strictly restricted to `*.olamaps.io` hosts and never leak to third-party URLs.
956
+ */
957
+ getTransformRequest() {
958
+ if (this.auth.mode === "proxy") {
959
+ return chunkXRJXKY7C_cjs.getTransformRequest({ proxyBaseUrl: this.transport.baseUrl });
960
+ }
961
+ return chunkXRJXKY7C_cjs.getTransformRequest({
962
+ apiKey: this.auth.getApiKey(),
963
+ accessToken: this.staticAccessToken
964
+ });
965
+ }
966
+ /**
967
+ * Build a ready-to-use MapLibre GL `Map` options object.
968
+ */
969
+ getMapOptions(options = {}) {
970
+ const authOpts = this.auth.mode === "proxy" ? { proxyBaseUrl: this.transport.baseUrl } : {
971
+ apiKey: this.auth.getApiKey(),
972
+ accessToken: this.staticAccessToken
973
+ };
974
+ return chunkXRJXKY7C_cjs.getMapOptions(authOpts, options);
975
+ }
976
+ };
977
+
978
+ exports.Elevation = Elevation;
979
+ exports.Geofencing = Geofencing;
980
+ exports.OlaMapsClient = OlaMapsClient;
981
+ exports.Places = Places;
982
+ exports.Roads = Roads;
983
+ exports.Routing = Routing;
984
+ exports.StreetView = StreetView;
985
+ exports.Tiles = Tiles;
986
+ exports.formatCoordinateList = formatCoordinateList;
987
+ exports.formatLatLng = formatLatLng;
988
+ exports.normalizeCoordinate = normalizeCoordinate;
989
+ exports.parseLatLngPair = parseLatLngPair;
990
+ //# sourceMappingURL=chunk-WLUKC7YU.cjs.map
991
+ //# sourceMappingURL=chunk-WLUKC7YU.cjs.map