mapnests-browser-sdk 1.0.9 → 1.1.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/README.md CHANGED
@@ -35,8 +35,8 @@ A secure and efficient TS SDK for the **Mapnests Platform**, enabling powerful g
35
35
  - [Autocomplete Without Zone](#autocomplete-without-zone)
36
36
  - [Search By Radius](#search-by-radius)
37
37
  - [Multi Stop Point](#multi-stop-point)
38
- - [Detailed Geolocation Information ](#detailed-geolocation-information)
39
38
  - [Geocode Search](#geocode-search)
39
+ - [Detailed Search By PlaceId ](#detailed-search-by-placeId)
40
40
 
41
41
  - [License](#license)
42
42
  - [Contact](#contact)
@@ -379,8 +379,6 @@ console.log(revRes);
379
379
  {
380
380
  "data": {
381
381
  "placeId": "a4d8c105e24fbc3d91bb0486e1701fa20b9b56329df0fc5c47f7df003e3cc579",
382
- "lat": 23.7952951,
383
- "lon": 90.41680379038863,
384
382
  "category": "",
385
383
  "type": "yes",
386
384
  "class": "building",
@@ -607,53 +605,6 @@ console.log(searchByRadiusRes);
607
605
 
608
606
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
609
607
 
610
- ### Detailed Geolocation Information
611
-
612
- > Provide detailed geolocation information for a place using its unique place_id, including address, coordinates, administrative regions, contact details, and metadata.
613
-
614
- **Example Input:**
615
-
616
- ```ts
617
- const detailsRes = await client.details({ PlaceId: "a97641e310481507f5bfdbeed6f0e946358b252bb3f82103ed7f5e59b04d422e" });
618
- ```
619
-
620
- **Example Output:**
621
-
622
- ```json
623
- {
624
- "data": {
625
- "placeId": "a97641e310481507f5bfdbeed6f0e946358b252bb3f82103ed7f5e59b04d422e",
626
- "lat": 23.8696386,
627
- "lon": 90.3995743,
628
- "types": [
629
- "shop",
630
- "travel_agency",
631
- "shop"
632
- ],
633
- "address": "Uttara",
634
- "name": "Nogor Travel Agency",
635
- "houseNumber": "9",
636
- "houseName": "",
637
- "street": "Road 7",
638
- "phone": "",
639
- "website": "",
640
- "country": "Bangladesh",
641
- "city": "Uttara, Dhaka",
642
- "thana": "Uttara West",
643
- "division": "",
644
- "district": "Dhaka",
645
- "postalCode": "1230",
646
- "plusCode": "",
647
- "sublocality": "",
648
- "localArea": ""
649
- },
650
- "message": "Success",
651
- "status": true
652
- }
653
- ```
654
-
655
- <p align="right">(<a href="#readme-top">back to top</a>)</p>
656
-
657
608
  ### Geocode Search
658
609
 
659
610
  > Search for details about places, streets, and landmarks using a text query.
@@ -713,6 +664,57 @@ const geocodeRes = await client.geocode({ Query: "Mirpur" });
713
664
  "status": true
714
665
  }
715
666
  ```
667
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
668
+
669
+ ### Detailed Search By PlaceId
670
+
671
+ <a name="detailed-search-by-placeId"></a>
672
+
673
+ > Provide detailed geolocation information for a place using its unique place_id, including address, coordinates, administrative regions, contact details, and metadata.
674
+
675
+ **Example Input:**
676
+
677
+ ```ts
678
+ const detailsByPlaceId = await client.details({
679
+ PlaceId: "4355aad6b8eb0b4f0ee3fa972ff9ac3fdc2d7f86f634d81f79dcf396f21826a0"
680
+ });
681
+ console.log(detailsByPlaceId);
682
+ ```
683
+
684
+ **Example Output:**
685
+
686
+ ```json
687
+ {
688
+ "data": {
689
+ "placeId": "4355aad6b8eb0b4f0ee3fa972ff9ac3fdc2d7f86f634d81f79dcf396f21826a0",
690
+ "lat": 23.8060476,
691
+ "lon": 90.3744551,
692
+ "types": [
693
+ "office",
694
+ "office"
695
+ ],
696
+ "address": "Notari Public, House# 42, Mirpur Road, Senpara Parbata, Mirpur, Dhaka-1216",
697
+ "name": "Mirpur",
698
+ "houseNumber": "42",
699
+ "houseName": "",
700
+ "street": "Mirpur Road",
701
+ "phone": "",
702
+ "website": "",
703
+ "country": "Bangladesh",
704
+ "city": "Mirpur, Dhaka",
705
+ "thana": "Kafrul",
706
+ "division": "",
707
+ "district": "Dhaka",
708
+ "postalCode": "1216",
709
+ "plusCode": "",
710
+ "sublocality": "",
711
+ "localArea": ""
712
+ },
713
+ "message": "Success",
714
+ "status": true
715
+ }
716
+ ```
717
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
716
718
 
717
719
  ---
718
720
 
package/dist/client.js CHANGED
@@ -43,6 +43,8 @@ class Client {
43
43
  async reverse(request) {
44
44
  console.log("📍 Reverse request:", request);
45
45
  const response = await this.makeRequest("reverse", request);
46
+ delete response.data?.lat;
47
+ delete response.data?.lon;
46
48
  console.log("📍 Reverse response:", response);
47
49
  return response;
48
50
  }
package/dist/main.js CHANGED
@@ -125,7 +125,7 @@ const index_1 = require("./index");
125
125
  });
126
126
  console.log("============================> MultiStopPoint:", JSON.stringify(multiStopRes, null, 2));
127
127
  // ✅ Details By PlaceId Example
128
- const detailsRes = await cl.details({ PlaceId: "" });
128
+ const detailsRes = await cl.details({ PlaceId: "4355aad6b8eb0b4f0ee3fa972ff9ac3fdc2d7f86f634d81f79dcf396f21826a0" });
129
129
  console.log("============================> Details by Place ID:", detailsRes);
130
130
  // ✅ AutocompleteRequest Example
131
131
  const autoCompleteRes = await cl.autocomplete({ Query: "Gulshan Road", limit: 1 });
@@ -9,8 +9,8 @@ export interface ReverseResponse {
9
9
  }
10
10
  export interface ReverseData {
11
11
  placeId: string;
12
- lat: number;
13
- lon: number;
12
+ lat?: number;
13
+ lon?: number;
14
14
  category: string;
15
15
  type: string;
16
16
  class: string;
@@ -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';
@@ -22,6 +18,26 @@ const HTTP_METHOD_MAP = {
22
18
  autocompleteWithoutZone: 'GET',
23
19
  searchByRadius: 'GET',
24
20
  };
21
+ async function executeFetch(url, method, headers, body, timeoutMs) {
22
+ const response = await fetch(url, {
23
+ method,
24
+ headers,
25
+ body: method === 'POST' ? body : undefined,
26
+ signal: AbortSignal.timeout(timeoutMs),
27
+ });
28
+ const success = response.status >= 200 && response.status < 300;
29
+ if (!success) {
30
+ return {
31
+ success: false,
32
+ statusCode: response.status,
33
+ response: '',
34
+ errorMessage: response.statusText,
35
+ _headers: response.headers,
36
+ };
37
+ }
38
+ const data = await response.json();
39
+ return { success: true, statusCode: response.status, response: data };
40
+ }
25
41
  async function performSecureRequest(label, apiKey, origin, jsonRequest, timeOutMs) {
26
42
  let urlStr;
27
43
  try {
@@ -32,54 +48,29 @@ async function performSecureRequest(label, apiKey, origin, jsonRequest, timeOutM
32
48
  }
33
49
  let tokenHeader = await (0, generate_token_1.generateToken)(apiKey);
34
50
  const method = HTTP_METHOD_MAP[label] || 'GET';
51
+ const timeout = timeOutMs || 30000;
35
52
  const headers = {
36
53
  'X-API-KEY': apiKey,
37
54
  'Origin': origin,
38
55
  'fxsrf': tokenHeader,
39
56
  'Content-Type': 'application/json',
40
57
  };
41
- const axiosConfig = {
42
- headers,
43
- timeout: timeOutMs || 30000,
44
- };
45
58
  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']) {
59
+ const result = await executeFetch(urlStr, method, headers, jsonRequest, timeout);
60
+ if (result.statusCode === 401 &&
61
+ result._headers?.get('cf-ray-status-id-tn')) {
57
62
  tokenHeader = await (0, generate_token_1.generateToken)(apiKey);
58
63
  headers.fxsrf = tokenHeader;
59
64
  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
- };
65
+ return await executeFetch(urlStr, method, headers, jsonRequest, timeout);
68
66
  }
69
67
  catch (retryErr) {
70
- return {
71
- success: false,
72
- statusCode: retryErr.response?.status || 0,
73
- response: '',
74
- errorMessage: retryErr.message,
75
- };
68
+ return { success: false, statusCode: 0, response: '', errorMessage: retryErr.message };
76
69
  }
77
70
  }
78
- return {
79
- success: false,
80
- statusCode: err.response?.status || 0,
81
- response: '',
82
- errorMessage: err.message,
83
- };
71
+ return result;
72
+ }
73
+ catch (err) {
74
+ return { success: false, statusCode: 0, response: '', errorMessage: err.message };
84
75
  }
85
76
  }
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.9",
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",
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
+ }