mapnests-browser-sdk 1.0.10 → 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,7 +35,6 @@ 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)
40
39
  - [Detailed Search By PlaceId ](#detailed-search-by-placeId)
41
40
 
@@ -606,53 +605,6 @@ console.log(searchByRadiusRes);
606
605
 
607
606
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
608
607
 
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
608
  ### Geocode Search
657
609
 
658
610
  > Search for details about places, streets, and landmarks using a text query.
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 });
@@ -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.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.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
+ }