mapnests-browser-sdk 1.1.0 β†’ 1.1.2

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/README.md CHANGED
@@ -32,11 +32,11 @@ A secure and efficient TS SDK for the **Mapnests Platform**, enabling powerful g
32
32
  - [Search](#search)
33
33
  - [Reverse](#reverse)
34
34
  - [Autocomplete](#autocomplete)
35
- - [Autocomplete Without Zone](#autocomplete-without-zone)
36
35
  - [Search By Radius](#search-by-radius)
37
36
  - [Multi Stop Point](#multi-stop-point)
38
37
  - [Geocode Search](#geocode-search)
39
- - [Detailed Search By PlaceId ](#detailed-search-by-placeId)
38
+ - [Detailed Search By PlaceId](#detailed-search-by-placeId)
39
+ - [Snap to Road](#snap-to-road)
40
40
 
41
41
  - [License](#license)
42
42
  - [Contact](#contact)
@@ -416,8 +416,27 @@ console.log(revRes);
416
416
  **Example Input:**
417
417
 
418
418
  ```ts
419
+ //Without optional value
419
420
  const autoCompleteRes = await client.autocomplete({ Query: "Gulshan Road"});
420
421
  console.log(autoCompleteRes);
422
+
423
+ // Optional parameter: ActiveZone.
424
+ // If ActiveZone is set to true, the search results will be returned within the zone. (By Default ActiveZone is true)
425
+ // If ActiveZone is set to false, the search results will be not consider any zone data.
426
+ const autoCompleteRes = await client.autocomplete({ Query: "Gulshan Road", ActiveZone: true });
427
+ console.log(autoCompleteRes);
428
+
429
+ // Optional parameters: Latitude, Longitude, and Radius.
430
+ // If provided, the search results will be returned within a specified radius,
431
+ // using the given latitude and longitude as the center point.
432
+ const autoCompleteRes = await client.autocomplete({ Query: "Gulshan Road", Lat: 23.7806, Lon: 90.3984, Radius: 5000 });
433
+ console.log(autoCompleteRes);
434
+
435
+ // Optional parameter: Limit.
436
+ // If provided, the search results will be returned within a specified limit.
437
+ const autoCompleteRes = await client.autocomplete({ Query: "Gulshan Road", Limit: 1 });
438
+ console.log(autoCompleteRes);
439
+
421
440
  ```
422
441
 
423
442
  **Example Output:**
@@ -444,34 +463,6 @@ console.log(autoCompleteRes);
444
463
 
445
464
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
446
465
 
447
- ### Autocomplete Without Zone
448
-
449
- > Auto Complete suggests relevant places, streets, and landmarks as you type a partial search query.
450
-
451
- **Example Input:**
452
-
453
- ```ts
454
- const autocompleteResWithoutZone = await client.autocompleteWithoutZone({ Query: "Uttara"});
455
- console.log( JSON.stringify(autocompleteResWithoutZone,));
456
- ```
457
-
458
- **Example Output:**
459
-
460
- ```json
461
- {
462
- "data": [
463
- {
464
- "placeId": "7d7e8fd275bfd9be9853ada14417d104e824d1c11600599bd326fb858429d83c",
465
- "name": "Uttara",
466
- "address": "Uttara, House#21, Road 17, Sector 11, Uttara, Dhaka-1230",
467
- "types": [
468
- "amenity",
469
- "restaurant",
470
- "amenity"
471
- ]
472
- }
473
- }
474
- ```
475
466
 
476
467
  ### Search By Radius
477
468
 
@@ -716,6 +707,45 @@ console.log(detailsByPlaceId);
716
707
  ```
717
708
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
718
709
 
710
+ ### Snap to Road
711
+
712
+ <a name="snap-to-road"></a>
713
+
714
+ > Returns the nearest road’s latitude and longitude for the given input coordinates.
715
+
716
+ **Example Input:**
717
+
718
+ ```ts
719
+ const snapToRoad = await client.snapToRoad({
720
+ mode: "walking",
721
+ latitude: 23.8103,
722
+ longitude: 90.4125
723
+ });
724
+ console.log(snapToRoad);
725
+ ```
726
+
727
+ **Example Output:**
728
+
729
+ ```json
730
+ {
731
+ "data": {
732
+ "waypoints": [
733
+ {
734
+ "address": "Lane 11 East",
735
+ "location": [
736
+ 90.412496,
737
+ 23.810403
738
+ ],
739
+ "distance_meters": 11.41511481
740
+ }
741
+ ]
742
+ },
743
+ "message": "Success",
744
+ "status": true
745
+ }
746
+ ```
747
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
748
+
719
749
  ---
720
750
 
721
751
  ## License
package/dist/build_url.js CHANGED
@@ -17,11 +17,11 @@ function buildURLFromJSON(label, baseUrl, jsonStr) {
17
17
  const toLon = data.DestLon;
18
18
  const mode = encodeURIComponent(data.Mode);
19
19
  const path = label === 'distanceMatrixDetails' ? 'distancematrixdetails' : 'distancematrix';
20
- const apiVersion = label === 'distanceMatrixDetails' ? 'v1' : 'v3';
20
+ const apiVersion = label === 'distanceMatrixDetails' ? 'v2' : 'v3';
21
21
  return `${baseUrl}/routemap/api/${apiVersion}/routes/${path}?fromLat=${fromLat}&fromLong=${fromLon}&toLat=${toLat}&toLong=${toLon}&mode=${mode}`;
22
22
  }
23
23
  case 'pairwiseRouteSummary': {
24
- return `${baseUrl}/routemap/api/v1/routes/pairwise-summary`;
24
+ return `${baseUrl}/routemap/api/v2/routes/pairwise-summary`;
25
25
  }
26
26
  case 'multiSourceSummary': {
27
27
  return `${baseUrl}/routemap/api/v1/routes/multi-source-summary`;
@@ -53,14 +53,8 @@ function buildURLFromJSON(label, baseUrl, jsonStr) {
53
53
  const limit = data.Limit ? `&limit=${data.Limit}` : '';
54
54
  const lat = data.Lat ? `&lat=${data.Lat}` : '';
55
55
  const lon = data.Lon ? `&lon=${data.Lon}` : '';
56
- return `${baseUrl}/geomap/api/v1/autocomplete?q=${query}${limit}${lat}${lon}`;
57
- }
58
- case 'autocompleteWithoutZone': {
59
- const query = encodeURIComponent(data.Query);
60
- const limit = data.Limit ? `&limit=${data.Limit}` : '';
61
- const lat = data.Lat ? `&lat=${data.Lat}` : '';
62
- const lon = data.Lon ? `&lon=${data.Lon}` : '';
63
- return `${baseUrl}/geomap/api/v1/autocomplete/all?q=${query}${limit}${lat}${lon}`;
56
+ const zoneActiveOnly = data.ZoneActiveOnly != undefined ? `&zoneActiveOnly=${data.ZoneActiveOnly}` : "";
57
+ return `${baseUrl}/geomap/api/v2/autocomplete?q=${query}${zoneActiveOnly}${limit}${lat}${lon}`;
64
58
  }
65
59
  case 'searchByRadius': {
66
60
  const query = encodeURIComponent(data.Query);
@@ -72,6 +66,9 @@ function buildURLFromJSON(label, baseUrl, jsonStr) {
72
66
  const page = data.Page ? `&page=${data.Page}` : '';
73
67
  return `${baseUrl}/geomap/api/v2/search/radius?q=${query}&lat=${lat}&lon=${lon}&radius=${radius}&activeLocations=${activeLocations}${limit}${page}`;
74
68
  }
69
+ case 'snapToRoad': {
70
+ return `${exports.BASE_URL}/routemap/api/v1/nearest/road`;
71
+ }
75
72
  default:
76
73
  throw new Error(`unsupported label: ${label}`);
77
74
  }
package/dist/client.d.ts CHANGED
@@ -10,6 +10,7 @@ import { ReverseRequest, ReverseResponse } from "./modules/reverse";
10
10
  import { SearchRequest, SearchResponse } from "./modules/search";
11
11
  import { SearchBboxRequest } from "./modules/search_bbox";
12
12
  import { SearchByRadiusRequest, SearchByRadiusResponse } from "./modules/search_by_radius";
13
+ import { SnapToRoadRequest, SnapToRoadResponse } from "./modules/snap_to_road";
13
14
  export interface IClient {
14
15
  distanceMatrix(request: DistanceMatrixRequest): Promise<DistanceMatrixResponse>;
15
16
  pairwiseRouteSummary(request: PairwiseRouteSummaryRequest): Promise<PairwiseRouteSummaryResponse>;
@@ -21,8 +22,8 @@ export interface IClient {
21
22
  geocode(request: GeocodeRequest): Promise<GeocodeResponse>;
22
23
  multiStopPoint(request: MultiStopPointsRequest): Promise<MultiStopPointsResponse>;
23
24
  autocomplete(request: AutocompleteRequest): Promise<AutocompleteResponse>;
24
- autocompleteWithoutZone(request: AutocompleteRequest): Promise<AutocompleteResponse>;
25
25
  searchByRadius(request: SearchByRadiusRequest): Promise<SearchByRadiusResponse>;
26
+ snapToRoad(request: SnapToRoadRequest): Promise<SnapToRoadResponse>;
26
27
  searchWithBbox(request: SearchBboxRequest): Promise<string>;
27
28
  }
28
29
  export declare class Client implements IClient {
@@ -38,10 +39,10 @@ export declare class Client implements IClient {
38
39
  reverse(request: ReverseRequest): Promise<ReverseResponse>;
39
40
  search(request: SearchRequest): Promise<SearchResponse>;
40
41
  autocomplete(request: AutocompleteRequest): Promise<AutocompleteResponse>;
41
- autocompleteWithoutZone(request: AutocompleteRequest): Promise<AutocompleteResponse>;
42
42
  searchWithBbox(request: SearchBboxRequest): Promise<string>;
43
43
  searchByRadius(request: SearchByRadiusRequest): Promise<SearchByRadiusResponse>;
44
44
  geocode(request: GeocodeRequest): Promise<GeocodeResponse>;
45
45
  multiStopPoint(request: MultiStopPointsRequest): Promise<MultiStopPointsResponse>;
46
46
  details(request: DetailsRequest): Promise<DetailsResponse>;
47
+ snapToRoad(request: SnapToRoadRequest): Promise<SnapToRoadResponse>;
47
48
  }
package/dist/client.js CHANGED
@@ -64,14 +64,6 @@ class Client {
64
64
  console.dir(response, { depth: null, colors: true });
65
65
  return response;
66
66
  }
67
- async autocompleteWithoutZone(request) {
68
- console.log("πŸ“ Autocomplete Without Zone request:", request);
69
- request.Query = (0, validate_query_length_1.validateAndNormalizeQuery)(request.Query);
70
- const response = await this.makeRequest("autocompleteWithoutZone", request);
71
- console.log("πŸ“ Autocomplete Without Zone response:");
72
- console.dir(response, { depth: null, colors: true });
73
- return response;
74
- }
75
67
  //Under Maintenance
76
68
  async searchWithBbox(request) {
77
69
  console.log("πŸ“ Search Bbox request:", request);
@@ -107,5 +99,12 @@ class Client {
107
99
  console.log("πŸ“ Details Search by Place ID response:", response);
108
100
  return response;
109
101
  }
102
+ async snapToRoad(request) {
103
+ console.log("πŸ“ Snap to Road request:", request);
104
+ const response = await this.makeRequest("snapToRoad", request);
105
+ console.log("πŸ“ Snap to Road response:");
106
+ console.dir(response, { depth: null, colors: true });
107
+ return response;
108
+ }
110
109
  }
111
110
  exports.Client = Client;
package/dist/main.js CHANGED
@@ -72,7 +72,7 @@ const index_1 = require("./index");
72
72
  },
73
73
  ],
74
74
  });
75
- console.log("============================> PairwiseRouteSummary:", pairwiseRes);
75
+ console.log("============================> PairwiseRouteSummary:", JSON.stringify(pairwiseRes));
76
76
  // βœ… MultiSourceRouteSummaryRequest Example
77
77
  const multiSourceRes = await cl.multiSourceRouteSummary({
78
78
  sources: [
@@ -124,22 +124,21 @@ const index_1 = require("./index");
124
124
  Mode: index_1.Mode.Car,
125
125
  });
126
126
  console.log("============================> MultiStopPoint:", JSON.stringify(multiStopRes, null, 2));
127
- // βœ… Details By PlaceId Example
128
- const detailsRes = await cl.details({ PlaceId: "4355aad6b8eb0b4f0ee3fa972ff9ac3fdc2d7f86f634d81f79dcf396f21826a0" });
129
- console.log("============================> Details by Place ID:", detailsRes);
127
+ // // βœ… Details By PlaceId Example
128
+ // const detailsRes = await cl.details({ PlaceId: "4355aad6b8eb0b4f0ee3fa972ff9ac3fdc2d7f86f634d81f79dcf396f21826a0" });
129
+ // console.log("============================> Details by Place ID:", detailsRes);
130
130
  // βœ… AutocompleteRequest Example
131
- const autoCompleteRes = await cl.autocomplete({ Query: "Gulshan Road", limit: 1 });
131
+ const autoCompleteRes = await cl.autocomplete({ Query: "Mirpur", Limit: 1, ZoneActiveOnly: true });
132
132
  console.log("============================> Autocomplete:", JSON.stringify(autoCompleteRes, null, 2));
133
- console.dir(autoCompleteRes, { depth: null, color: true });
134
- // βœ… AutocompleteWithoutZoneRequest Example
135
- const autocompleteResWithoutZone = await cl.autocompleteWithoutZone({ Query: "Uttara", limit: 2 });
136
- console.log("============================> Autocomplete Without Zone:", JSON.stringify(autocompleteResWithoutZone, null, 2));
137
133
  // βœ… SearchBboxRequest Example
138
134
  const searchBboxRes = await cl.searchWithBbox({ Query: "uttara", TopLeftLat: 23.799012278864893, TopLeftLon: 90.43487817491183, BottomRightLat: 23.798243503885544, BottomRightLon: 90.43537003653393 });
139
135
  console.log("============================> Search With Boundary box:", searchBboxRes);
140
136
  // βœ… SearchByRadiusRequest Example
141
137
  const searchByRadiusRes = await cl.searchByRadius({ Query: "uttara", Lat: 23.7272064, Lon: 90.3861125, Radius: 5000, Limit: 1 });
142
138
  console.log("============================> Search By Radius:", JSON.stringify(searchByRadiusRes, null, 2));
139
+ // βœ… Snap to Road Example
140
+ const snapToRoadRes = await cl.snapToRoad({ mode: "walking", latitude: 23.8103, longitude: 90.4125 });
141
+ console.log("============================> Snap to Road:", JSON.stringify(snapToRoadRes, null, 2));
143
142
  }
144
143
  catch (err) {
145
144
  console.error("πŸ”₯ Error:", err);
@@ -1,5 +1,6 @@
1
1
  export interface AutocompleteRequest {
2
2
  Query: string;
3
+ ZoneActiveOnly?: boolean;
3
4
  Lat?: number;
4
5
  Lon?: number;
5
6
  Limit?: number;
@@ -1,4 +1,5 @@
1
1
  import { Mode } from './distance_matrix';
2
+ import { Leg } from './distance_matrix_details';
2
3
  export interface Coordinate {
3
4
  lat: number;
4
5
  lon: number;
@@ -12,15 +13,21 @@ export interface PairwiseRoute {
12
13
  export interface PairwiseRouteSummaryRequest {
13
14
  pairs: PairwiseRoute[];
14
15
  }
16
+ export interface LegWithAnnotation extends Leg {
17
+ annotation: Record<string, unknown>;
18
+ }
15
19
  export interface RouteSummary {
16
20
  id: number;
17
21
  distanceInMeters?: number;
18
22
  etaInSeconds?: number;
19
23
  geometry?: string;
24
+ legs?: LegWithAnnotation[];
20
25
  error?: string;
21
26
  }
22
27
  export interface PairwiseRouteSummaryResponse {
23
28
  status: boolean;
24
29
  message: string;
25
- data: RouteSummary[];
30
+ data: {
31
+ routeSummaries: RouteSummary[];
32
+ };
26
33
  }
@@ -0,0 +1,13 @@
1
+ import { PlaceDetail } from "./details_by_place_id";
2
+ import { Mode } from "./distance_matrix";
3
+ export interface SnapToRoadRequest {
4
+ mode: Mode;
5
+ latitude: number;
6
+ longitude: number;
7
+ numberOfNearestRoad?: number;
8
+ }
9
+ export interface SnapToRoadResponse {
10
+ data: PlaceDetail[];
11
+ message: string;
12
+ status: boolean;
13
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -15,8 +15,8 @@ const HTTP_METHOD_MAP = {
15
15
  geocode: 'GET',
16
16
  detailsByPlaceId: 'GET',
17
17
  autocomplete: 'GET',
18
- autocompleteWithoutZone: 'GET',
19
18
  searchByRadius: 'GET',
19
+ snapToRoad: 'POST',
20
20
  };
21
21
  async function executeFetch(url, method, headers, body, timeoutMs) {
22
22
  const response = await fetch(url, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mapnests-browser-sdk",
3
3
  "description": "TypeScript SDK for Mapnests API integration (Distance Matrix, Distance Matrix Details, Pairwise Route Summary, Multi Source Route Summary, Search, Reverse, Autocomplete, Autocomplete Without Zone, Multi Stop Points, Details By Place ID, Search By Radius, Geocode)",
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {