mapnests-browser-sdk 1.0.10 → 1.1.1

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,10 +32,8 @@ 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
- - [Detailed Geolocation Information ](#detailed-geolocation-information)
39
37
  - [Geocode Search](#geocode-search)
40
38
  - [Detailed Search By PlaceId ](#detailed-search-by-placeId)
41
39
 
@@ -417,8 +415,27 @@ console.log(revRes);
417
415
  **Example Input:**
418
416
 
419
417
  ```ts
418
+ //Without optional value
420
419
  const autoCompleteRes = await client.autocomplete({ Query: "Gulshan Road"});
421
420
  console.log(autoCompleteRes);
421
+
422
+ // Optional parameter: ActiveZone.
423
+ // If ActiveZone is set to true, the search results will be returned within the zone. (By Default ActiveZone is true)
424
+ // If ActiveZone is set to false, the search results will be not consider any zone data.
425
+ const autoCompleteRes = await client.autocomplete({ Query: "Gulshan Road", ActiveZone: true });
426
+ console.log(autoCompleteRes);
427
+
428
+ // Optional parameters: Latitude, Longitude, and Radius.
429
+ // If provided, the search results will be returned within a specified radius,
430
+ // using the given latitude and longitude as the center point.
431
+ const autoCompleteRes = await client.autocomplete({ Query: "Gulshan Road", Lat: 23.7806, Lon: 90.3984, Radius: 5000 });
432
+ console.log(autoCompleteRes);
433
+
434
+ // Optional parameter: Limit.
435
+ // If provided, the search results will be returned within a specified limit.
436
+ const autoCompleteRes = await client.autocomplete({ Query: "Gulshan Road", Limit: 1 });
437
+ console.log(autoCompleteRes);
438
+
422
439
  ```
423
440
 
424
441
  **Example Output:**
@@ -445,34 +462,6 @@ console.log(autoCompleteRes);
445
462
 
446
463
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
447
464
 
448
- ### Autocomplete Without Zone
449
-
450
- > Auto Complete suggests relevant places, streets, and landmarks as you type a partial search query.
451
-
452
- **Example Input:**
453
-
454
- ```ts
455
- const autocompleteResWithoutZone = await client.autocompleteWithoutZone({ Query: "Uttara"});
456
- console.log( JSON.stringify(autocompleteResWithoutZone,));
457
- ```
458
-
459
- **Example Output:**
460
-
461
- ```json
462
- {
463
- "data": [
464
- {
465
- "placeId": "7d7e8fd275bfd9be9853ada14417d104e824d1c11600599bd326fb858429d83c",
466
- "name": "Uttara",
467
- "address": "Uttara, House#21, Road 17, Sector 11, Uttara, Dhaka-1230",
468
- "types": [
469
- "amenity",
470
- "restaurant",
471
- "amenity"
472
- ]
473
- }
474
- }
475
- ```
476
465
 
477
466
  ### Search By Radius
478
467
 
@@ -606,53 +595,6 @@ console.log(searchByRadiusRes);
606
595
 
607
596
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
608
597
 
609
- ### Detailed Geolocation Information
610
-
611
- > Provide detailed geolocation information for a place using its unique place_id, including address, coordinates, administrative regions, contact details, and metadata.
612
-
613
- **Example Input:**
614
-
615
- ```ts
616
- const detailsRes = await client.details({ PlaceId: "a97641e310481507f5bfdbeed6f0e946358b252bb3f82103ed7f5e59b04d422e" });
617
- ```
618
-
619
- **Example Output:**
620
-
621
- ```json
622
- {
623
- "data": {
624
- "placeId": "a97641e310481507f5bfdbeed6f0e946358b252bb3f82103ed7f5e59b04d422e",
625
- "lat": 23.8696386,
626
- "lon": 90.3995743,
627
- "types": [
628
- "shop",
629
- "travel_agency",
630
- "shop"
631
- ],
632
- "address": "Uttara",
633
- "name": "Nogor Travel Agency",
634
- "houseNumber": "9",
635
- "houseName": "",
636
- "street": "Road 7",
637
- "phone": "",
638
- "website": "",
639
- "country": "Bangladesh",
640
- "city": "Uttara, Dhaka",
641
- "thana": "Uttara West",
642
- "division": "",
643
- "district": "Dhaka",
644
- "postalCode": "1230",
645
- "plusCode": "",
646
- "sublocality": "",
647
- "localArea": ""
648
- },
649
- "message": "Success",
650
- "status": true
651
- }
652
- ```
653
-
654
- <p align="right">(<a href="#readme-top">back to top</a>)</p>
655
-
656
598
  ### Geocode Search
657
599
 
658
600
  > Search for details about places, streets, and landmarks using a text query.
package/dist/build_url.js CHANGED
@@ -21,7 +21,7 @@ function buildURLFromJSON(label, baseUrl, jsonStr) {
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);
package/dist/client.d.ts CHANGED
@@ -21,7 +21,6 @@ export interface IClient {
21
21
  geocode(request: GeocodeRequest): Promise<GeocodeResponse>;
22
22
  multiStopPoint(request: MultiStopPointsRequest): Promise<MultiStopPointsResponse>;
23
23
  autocomplete(request: AutocompleteRequest): Promise<AutocompleteResponse>;
24
- autocompleteWithoutZone(request: AutocompleteRequest): Promise<AutocompleteResponse>;
25
24
  searchByRadius(request: SearchByRadiusRequest): Promise<SearchByRadiusResponse>;
26
25
  searchWithBbox(request: SearchBboxRequest): Promise<string>;
27
26
  }
@@ -38,7 +37,6 @@ export declare class Client implements IClient {
38
37
  reverse(request: ReverseRequest): Promise<ReverseResponse>;
39
38
  search(request: SearchRequest): Promise<SearchResponse>;
40
39
  autocomplete(request: AutocompleteRequest): Promise<AutocompleteResponse>;
41
- autocompleteWithoutZone(request: AutocompleteRequest): Promise<AutocompleteResponse>;
42
40
  searchWithBbox(request: SearchBboxRequest): Promise<string>;
43
41
  searchByRadius(request: SearchByRadiusRequest): Promise<SearchByRadiusResponse>;
44
42
  geocode(request: GeocodeRequest): Promise<GeocodeResponse>;
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);
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,16 +124,12 @@ 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: "" });
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);
@@ -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
  }
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.performSecureRequest = performSecureRequest;
7
- const axios_1 = __importDefault(require("axios"));
8
4
  const build_url_1 = require("./build_url");
9
5
  const generate_token_1 = require("./generate_token");
10
6
  const BASE_URL = 'https://engine.mapnests.com';
@@ -19,9 +15,28 @@ const HTTP_METHOD_MAP = {
19
15
  geocode: 'GET',
20
16
  detailsByPlaceId: 'GET',
21
17
  autocomplete: 'GET',
22
- autocompleteWithoutZone: 'GET',
23
18
  searchByRadius: 'GET',
24
19
  };
20
+ async function executeFetch(url, method, headers, body, timeoutMs) {
21
+ const response = await fetch(url, {
22
+ method,
23
+ headers,
24
+ body: method === 'POST' ? body : undefined,
25
+ signal: AbortSignal.timeout(timeoutMs),
26
+ });
27
+ const success = response.status >= 200 && response.status < 300;
28
+ if (!success) {
29
+ return {
30
+ success: false,
31
+ statusCode: response.status,
32
+ response: '',
33
+ errorMessage: response.statusText,
34
+ _headers: response.headers,
35
+ };
36
+ }
37
+ const data = await response.json();
38
+ return { success: true, statusCode: response.status, response: data };
39
+ }
25
40
  async function performSecureRequest(label, apiKey, origin, jsonRequest, timeOutMs) {
26
41
  let urlStr;
27
42
  try {
@@ -32,54 +47,29 @@ async function performSecureRequest(label, apiKey, origin, jsonRequest, timeOutM
32
47
  }
33
48
  let tokenHeader = await (0, generate_token_1.generateToken)(apiKey);
34
49
  const method = HTTP_METHOD_MAP[label] || 'GET';
50
+ const timeout = timeOutMs || 30000;
35
51
  const headers = {
36
52
  'X-API-KEY': apiKey,
37
53
  'Origin': origin,
38
54
  'fxsrf': tokenHeader,
39
55
  'Content-Type': 'application/json',
40
56
  };
41
- const axiosConfig = {
42
- headers,
43
- timeout: timeOutMs || 30000,
44
- };
45
57
  try {
46
- const response = method === 'POST'
47
- ? await axios_1.default.post(urlStr, JSON.parse(jsonRequest), axiosConfig)
48
- : await axios_1.default.get(urlStr, axiosConfig);
49
- return {
50
- success: response.status >= 200 && response.status < 300,
51
- statusCode: response.status,
52
- response: response.data,
53
- };
54
- }
55
- catch (err) {
56
- if (err.response?.status === 401 && err.response.headers['cf-ray-status-id-tn']) {
58
+ const result = await executeFetch(urlStr, method, headers, jsonRequest, timeout);
59
+ if (result.statusCode === 401 &&
60
+ result._headers?.get('cf-ray-status-id-tn')) {
57
61
  tokenHeader = await (0, generate_token_1.generateToken)(apiKey);
58
62
  headers.fxsrf = tokenHeader;
59
63
  try {
60
- const retryResponse = method === 'POST'
61
- ? await axios_1.default.post(urlStr, JSON.parse(jsonRequest), axiosConfig)
62
- : await axios_1.default.get(urlStr, axiosConfig);
63
- return {
64
- success: retryResponse.status >= 200 && retryResponse.status < 300,
65
- statusCode: retryResponse.status,
66
- response: retryResponse.data,
67
- };
64
+ return await executeFetch(urlStr, method, headers, jsonRequest, timeout);
68
65
  }
69
66
  catch (retryErr) {
70
- return {
71
- success: false,
72
- statusCode: retryErr.response?.status || 0,
73
- response: '',
74
- errorMessage: retryErr.message,
75
- };
67
+ return { success: false, statusCode: 0, response: '', errorMessage: retryErr.message };
76
68
  }
77
69
  }
78
- return {
79
- success: false,
80
- statusCode: err.response?.status || 0,
81
- response: '',
82
- errorMessage: err.message,
83
- };
70
+ return result;
71
+ }
72
+ catch (err) {
73
+ return { success: false, statusCode: 0, response: '', errorMessage: err.message };
84
74
  }
85
75
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mapnests-browser-sdk",
3
- "description": "TypeScript SDK for Mapnests API integration (Distance Matrix, Distance Matrix Details, Geocode, Reverse Geocode)",
4
- "version": "1.0.10",
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.1",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
@@ -36,7 +36,6 @@
36
36
  "devDependencies": {
37
37
  "@types/jest": "^29.0.0",
38
38
  "@types/node": "^24.0.13",
39
- "axios": "^1.10.0",
40
39
  "jest": "^29.0.0",
41
40
  "rimraf": "^5.0.1",
42
41
  "tsx": "^4.20.3",
@@ -46,4 +45,4 @@
46
45
  "type": "git",
47
46
  "url": "git@vcs.technonext.com:mapnests/map-libraries/tn-map-js-library.git"
48
47
  }
49
- }
48
+ }