apple-maps-server-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
@@ -1,7 +1,7 @@
1
1
 
2
2
  # Apple Maps Server SDK
3
3
 
4
- The Apple Maps Server SDK for Node.js is a tool that helps developers access the Apple Maps API using the Node.js language. It makes it easy to search for locations, get map data, and generate directions in your Node.js apps. Additionally, it also simplifies the process of managing access tokens, making it easier for you to use the API without having to worry about managing tokens.
4
+ The Apple Maps Server SDK is an npm package that allows easy access to the Apple Maps Server API in JavaScript and TypeScript projects. It includes features such as geocoding, estimated time of arrival, and location search and is well-documented with js/ts examples, making it simpler for developers to access the functionality provided by the API without the need for a deep-dive into Apple's documentation.
5
5
 
6
6
  ## Installation
7
7
 
package/lib/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { GeocodeInput, GeocodeResponse, ReverseGeocodeInput, ReverseGeocodeRespo
3
3
  declare class AppleMaps {
4
4
  accessToken: string;
5
5
  authorizationToken: string;
6
+ accessTokenRetries: number;
6
7
  apiClient: AxiosInstance;
7
8
  constructor({ authorizationToken }: {
8
9
  authorizationToken: string;
package/lib/index.js CHANGED
@@ -36,6 +36,7 @@ const axios_1 = __importStar(require("axios"));
36
36
  class AppleMaps {
37
37
  constructor({ authorizationToken }) {
38
38
  this.accessToken = "";
39
+ this.accessTokenRetries = 0;
39
40
  this.authorizationToken = authorizationToken;
40
41
  if (!authorizationToken) {
41
42
  throw new Error("'authorizationToken' param is required");
@@ -56,7 +57,7 @@ class AppleMaps {
56
57
  this.accessToken = response.data.accessToken;
57
58
  }
58
59
  catch (error) {
59
- console.error(error);
60
+ throw error;
60
61
  }
61
62
  return;
62
63
  });
@@ -76,6 +77,10 @@ class AppleMaps {
76
77
  catch (error) {
77
78
  if (error instanceof axios_1.AxiosError) {
78
79
  if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
80
+ if (this.accessTokenRetries > 3) {
81
+ throw new Error("Unable to get access token");
82
+ }
83
+ this.accessTokenRetries++;
79
84
  yield this.getAccessToken();
80
85
  return this.geocode(input);
81
86
  }
@@ -103,6 +108,10 @@ class AppleMaps {
103
108
  catch (error) {
104
109
  if (error instanceof axios_1.AxiosError) {
105
110
  if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
111
+ if (this.accessTokenRetries > 3) {
112
+ throw new Error("Unable to get access token");
113
+ }
114
+ this.accessTokenRetries++;
106
115
  yield this.getAccessToken();
107
116
  return this.reverseGeocode(input);
108
117
  }
@@ -130,6 +139,10 @@ class AppleMaps {
130
139
  catch (error) {
131
140
  if (error instanceof axios_1.AxiosError) {
132
141
  if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
142
+ if (this.accessTokenRetries > 3) {
143
+ throw new Error("Unable to get access token");
144
+ }
145
+ this.accessTokenRetries++;
133
146
  yield this.getAccessToken();
134
147
  return this.eta(input);
135
148
  }
@@ -157,6 +170,10 @@ class AppleMaps {
157
170
  catch (error) {
158
171
  if (error instanceof axios_1.AxiosError) {
159
172
  if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
173
+ if (this.accessTokenRetries > 3) {
174
+ throw new Error("Unable to get access token");
175
+ }
176
+ this.accessTokenRetries++;
160
177
  yield this.getAccessToken();
161
178
  return this.search(input);
162
179
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apple-maps-server-sdk",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "An SDK for the Apple Maps Server API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "type": "git",
14
14
  "url": "git+https://github.com/JS00001/apple-maps-server-sdk.git"
15
15
  },
16
- "keywords": [],
16
+ "keywords": ["apple", "mapkit", "apple-mapkit", "apple-maps", "maps", "sdk"],
17
17
  "author": "JS00001",
18
18
  "license": "ISC",
19
19
  "bugs": {
package/src/index.ts CHANGED
@@ -13,10 +13,12 @@ import {
13
13
  class AppleMaps {
14
14
  accessToken: string;
15
15
  authorizationToken: string;
16
+ accessTokenRetries: number;
16
17
  apiClient: AxiosInstance;
17
18
 
18
19
  constructor({ authorizationToken }: { authorizationToken: string }) {
19
20
  this.accessToken = "";
21
+ this.accessTokenRetries = 0;
20
22
  this.authorizationToken = authorizationToken;
21
23
 
22
24
  if (!authorizationToken) {
@@ -40,7 +42,7 @@ class AppleMaps {
40
42
 
41
43
  this.accessToken = response.data.accessToken;
42
44
  } catch (error) {
43
- console.error(error);
45
+ throw error;
44
46
  }
45
47
 
46
48
  return;
@@ -59,6 +61,12 @@ class AppleMaps {
59
61
  } catch (error) {
60
62
  if (error instanceof AxiosError) {
61
63
  if (error.response?.status === 401) {
64
+ if (this.accessTokenRetries > 3) {
65
+ throw new Error("Unable to get access token");
66
+ }
67
+
68
+ this.accessTokenRetries++;
69
+
62
70
  await this.getAccessToken();
63
71
  return this.geocode(input);
64
72
  } else {
@@ -81,6 +89,11 @@ class AppleMaps {
81
89
  } catch (error) {
82
90
  if (error instanceof AxiosError) {
83
91
  if (error.response?.status === 401) {
92
+ if (this.accessTokenRetries > 3) {
93
+ throw new Error("Unable to get access token");
94
+ }
95
+
96
+ this.accessTokenRetries++;
84
97
  await this.getAccessToken();
85
98
  return this.reverseGeocode(input);
86
99
  } else {
@@ -103,6 +116,11 @@ class AppleMaps {
103
116
  } catch (error) {
104
117
  if (error instanceof AxiosError) {
105
118
  if (error.response?.status === 401) {
119
+ if (this.accessTokenRetries > 3) {
120
+ throw new Error("Unable to get access token");
121
+ }
122
+
123
+ this.accessTokenRetries++;
106
124
  await this.getAccessToken();
107
125
  return this.eta(input);
108
126
  } else {
@@ -125,6 +143,11 @@ class AppleMaps {
125
143
  } catch (error) {
126
144
  if (error instanceof AxiosError) {
127
145
  if (error.response?.status === 401) {
146
+ if (this.accessTokenRetries > 3) {
147
+ throw new Error("Unable to get access token");
148
+ }
149
+
150
+ this.accessTokenRetries++;
128
151
  await this.getAccessToken();
129
152
  return this.search(input);
130
153
  } else {