apple-maps-server-sdk 1.0.4 → 1.0.6
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/lib/index.js +10 -21
- package/package.json +1 -1
- package/src/{types.d.ts → globals.d.ts} +51 -0
- package/src/index.ts +7 -19
- package/src/inputs.d.ts +0 -33
- package/src/responses.d.ts +0 -16
package/lib/index.js
CHANGED
|
@@ -31,12 +31,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
35
|
const axios_1 = __importStar(require("axios"));
|
|
39
|
-
const qs_1 = __importDefault(require("qs"));
|
|
40
36
|
class AppleMaps {
|
|
41
37
|
constructor({ authorizationToken }) {
|
|
42
38
|
this.accessToken = "";
|
|
@@ -46,9 +42,6 @@ class AppleMaps {
|
|
|
46
42
|
}
|
|
47
43
|
this.apiClient = axios_1.default.create({
|
|
48
44
|
baseURL: "https://maps-api.apple.com/v1",
|
|
49
|
-
paramsSerializer: {
|
|
50
|
-
serialize: (params) => qs_1.default.stringify(params, { arrayFormat: "comma" }),
|
|
51
|
-
},
|
|
52
45
|
});
|
|
53
46
|
this.getAccessToken();
|
|
54
47
|
}
|
|
@@ -71,13 +64,12 @@ class AppleMaps {
|
|
|
71
64
|
geocode(input) {
|
|
72
65
|
var _a;
|
|
73
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
const params = qs_1.default.stringify(input);
|
|
75
67
|
try {
|
|
76
68
|
const response = yield this.apiClient.get("/geocode", {
|
|
77
69
|
headers: {
|
|
78
70
|
Authorization: `Bearer ${this.accessToken}`,
|
|
79
71
|
},
|
|
80
|
-
params,
|
|
72
|
+
params: input,
|
|
81
73
|
});
|
|
82
74
|
return response.data;
|
|
83
75
|
}
|
|
@@ -97,15 +89,14 @@ class AppleMaps {
|
|
|
97
89
|
});
|
|
98
90
|
}
|
|
99
91
|
reverseGeocode(input) {
|
|
100
|
-
var _a;
|
|
92
|
+
var _a, _b;
|
|
101
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
const params = qs_1.default.stringify(input);
|
|
103
94
|
try {
|
|
104
95
|
const response = yield this.apiClient.get("/reverseGeocode", {
|
|
105
96
|
headers: {
|
|
106
97
|
Authorization: `Bearer ${this.accessToken}`,
|
|
107
98
|
},
|
|
108
|
-
params,
|
|
99
|
+
params: input,
|
|
109
100
|
});
|
|
110
101
|
return response.data;
|
|
111
102
|
}
|
|
@@ -116,7 +107,7 @@ class AppleMaps {
|
|
|
116
107
|
return this.reverseGeocode(input);
|
|
117
108
|
}
|
|
118
109
|
else {
|
|
119
|
-
throw error;
|
|
110
|
+
throw (_b = error.response) === null || _b === void 0 ? void 0 : _b.data;
|
|
120
111
|
}
|
|
121
112
|
}
|
|
122
113
|
else
|
|
@@ -125,15 +116,14 @@ class AppleMaps {
|
|
|
125
116
|
});
|
|
126
117
|
}
|
|
127
118
|
eta(input) {
|
|
128
|
-
var _a;
|
|
119
|
+
var _a, _b;
|
|
129
120
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
const params = qs_1.default.stringify(input);
|
|
131
121
|
try {
|
|
132
122
|
const response = yield this.apiClient.get("/etas", {
|
|
133
123
|
headers: {
|
|
134
124
|
Authorization: `Bearer ${this.accessToken}`,
|
|
135
125
|
},
|
|
136
|
-
params,
|
|
126
|
+
params: input,
|
|
137
127
|
});
|
|
138
128
|
return response.data;
|
|
139
129
|
}
|
|
@@ -144,7 +134,7 @@ class AppleMaps {
|
|
|
144
134
|
return this.eta(input);
|
|
145
135
|
}
|
|
146
136
|
else {
|
|
147
|
-
throw error;
|
|
137
|
+
throw (_b = error.response) === null || _b === void 0 ? void 0 : _b.data;
|
|
148
138
|
}
|
|
149
139
|
}
|
|
150
140
|
else
|
|
@@ -153,15 +143,14 @@ class AppleMaps {
|
|
|
153
143
|
});
|
|
154
144
|
}
|
|
155
145
|
search(input) {
|
|
156
|
-
var _a;
|
|
146
|
+
var _a, _b;
|
|
157
147
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
const params = qs_1.default.stringify(input);
|
|
159
148
|
try {
|
|
160
149
|
const response = yield this.apiClient.get("/search", {
|
|
161
150
|
headers: {
|
|
162
151
|
Authorization: `Bearer ${this.accessToken}`,
|
|
163
152
|
},
|
|
164
|
-
params,
|
|
153
|
+
params: input,
|
|
165
154
|
});
|
|
166
155
|
return response.data;
|
|
167
156
|
}
|
|
@@ -172,7 +161,7 @@ class AppleMaps {
|
|
|
172
161
|
return this.search(input);
|
|
173
162
|
}
|
|
174
163
|
else {
|
|
175
|
-
throw error;
|
|
164
|
+
throw (_b = error.response) === null || _b === void 0 ? void 0 : _b.data;
|
|
176
165
|
}
|
|
177
166
|
}
|
|
178
167
|
else
|
package/package.json
CHANGED
|
@@ -93,3 +93,54 @@ interface ETA {
|
|
|
93
93
|
interface SearchResponsePlace extends Place {
|
|
94
94
|
poiCategory: PoiCategory;
|
|
95
95
|
}
|
|
96
|
+
|
|
97
|
+
interface GeocodeInput {
|
|
98
|
+
q: string;
|
|
99
|
+
limitToCountries?: string[];
|
|
100
|
+
lang?: string;
|
|
101
|
+
searchLocation?: string;
|
|
102
|
+
searchRegion?: string;
|
|
103
|
+
userLocation?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface ReverseGeocodeInput {
|
|
107
|
+
q: string;
|
|
108
|
+
lang?: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
interface ETAInput {
|
|
112
|
+
origin: string;
|
|
113
|
+
destinations: string[];
|
|
114
|
+
transportType?: TransportType;
|
|
115
|
+
departureDate?: string;
|
|
116
|
+
arrivalDate?: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
interface SearchInput {
|
|
120
|
+
q: string;
|
|
121
|
+
excludePoiCategories?: PoiCategory[];
|
|
122
|
+
includePoiCategories?: PoiCategory[];
|
|
123
|
+
limitToCountries?: string[];
|
|
124
|
+
resultTypeFilter?: "Poi" | "Address";
|
|
125
|
+
lang?: string;
|
|
126
|
+
searchLocation?: string;
|
|
127
|
+
searchRegion?: string;
|
|
128
|
+
userLocation?: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
interface GeocodeResponse {
|
|
132
|
+
response: Place[];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface ReverseGeocodeResponse {
|
|
136
|
+
response: Place[];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface ETAResponse {
|
|
140
|
+
etas: ETA[];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
interface SearchResponse {
|
|
144
|
+
displayMapRegion: MapRegion;
|
|
145
|
+
results: SearchResponsePlace[];
|
|
146
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import axios, { AxiosError, AxiosInstance } from "axios";
|
|
2
|
-
import qs from "qs";
|
|
3
2
|
|
|
4
3
|
class AppleMaps {
|
|
5
4
|
accessToken: string;
|
|
@@ -16,9 +15,6 @@ class AppleMaps {
|
|
|
16
15
|
|
|
17
16
|
this.apiClient = axios.create({
|
|
18
17
|
baseURL: "https://maps-api.apple.com/v1",
|
|
19
|
-
paramsSerializer: {
|
|
20
|
-
serialize: (params) => qs.stringify(params, { arrayFormat: "comma" }),
|
|
21
|
-
},
|
|
22
18
|
});
|
|
23
19
|
|
|
24
20
|
this.getAccessToken();
|
|
@@ -41,14 +37,12 @@ class AppleMaps {
|
|
|
41
37
|
}
|
|
42
38
|
|
|
43
39
|
async geocode(input: GeocodeInput): Promise<GeocodeResponse> {
|
|
44
|
-
const params = qs.stringify(input);
|
|
45
|
-
|
|
46
40
|
try {
|
|
47
41
|
const response = await this.apiClient.get("/geocode", {
|
|
48
42
|
headers: {
|
|
49
43
|
Authorization: `Bearer ${this.accessToken}`,
|
|
50
44
|
},
|
|
51
|
-
params,
|
|
45
|
+
params: input,
|
|
52
46
|
});
|
|
53
47
|
|
|
54
48
|
return response.data;
|
|
@@ -65,14 +59,12 @@ class AppleMaps {
|
|
|
65
59
|
}
|
|
66
60
|
|
|
67
61
|
async reverseGeocode(input: ReverseGeocodeInput): Promise<ReverseGeocodeResponse> {
|
|
68
|
-
const params = qs.stringify(input);
|
|
69
|
-
|
|
70
62
|
try {
|
|
71
63
|
const response = await this.apiClient.get("/reverseGeocode", {
|
|
72
64
|
headers: {
|
|
73
65
|
Authorization: `Bearer ${this.accessToken}`,
|
|
74
66
|
},
|
|
75
|
-
params,
|
|
67
|
+
params: input,
|
|
76
68
|
});
|
|
77
69
|
|
|
78
70
|
return response.data;
|
|
@@ -82,21 +74,19 @@ class AppleMaps {
|
|
|
82
74
|
await this.getAccessToken();
|
|
83
75
|
return this.reverseGeocode(input);
|
|
84
76
|
} else {
|
|
85
|
-
throw error;
|
|
77
|
+
throw error.response?.data;
|
|
86
78
|
}
|
|
87
79
|
} else throw error;
|
|
88
80
|
}
|
|
89
81
|
}
|
|
90
82
|
|
|
91
83
|
async eta(input: ETAInput): Promise<ETAResponse> {
|
|
92
|
-
const params = qs.stringify(input);
|
|
93
|
-
|
|
94
84
|
try {
|
|
95
85
|
const response = await this.apiClient.get("/etas", {
|
|
96
86
|
headers: {
|
|
97
87
|
Authorization: `Bearer ${this.accessToken}`,
|
|
98
88
|
},
|
|
99
|
-
params,
|
|
89
|
+
params: input,
|
|
100
90
|
});
|
|
101
91
|
|
|
102
92
|
return response.data;
|
|
@@ -106,21 +96,19 @@ class AppleMaps {
|
|
|
106
96
|
await this.getAccessToken();
|
|
107
97
|
return this.eta(input);
|
|
108
98
|
} else {
|
|
109
|
-
throw error;
|
|
99
|
+
throw error.response?.data;
|
|
110
100
|
}
|
|
111
101
|
} else throw error;
|
|
112
102
|
}
|
|
113
103
|
}
|
|
114
104
|
|
|
115
105
|
async search(input: SearchInput): Promise<SearchResponse> {
|
|
116
|
-
const params = qs.stringify(input);
|
|
117
|
-
|
|
118
106
|
try {
|
|
119
107
|
const response = await this.apiClient.get("/search", {
|
|
120
108
|
headers: {
|
|
121
109
|
Authorization: `Bearer ${this.accessToken}`,
|
|
122
110
|
},
|
|
123
|
-
params,
|
|
111
|
+
params: input,
|
|
124
112
|
});
|
|
125
113
|
|
|
126
114
|
return response.data;
|
|
@@ -130,7 +118,7 @@ class AppleMaps {
|
|
|
130
118
|
await this.getAccessToken();
|
|
131
119
|
return this.search(input);
|
|
132
120
|
} else {
|
|
133
|
-
throw error;
|
|
121
|
+
throw error.response?.data;
|
|
134
122
|
}
|
|
135
123
|
} else throw error;
|
|
136
124
|
}
|
package/src/inputs.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
interface GeocodeInput {
|
|
2
|
-
q: string;
|
|
3
|
-
limitToCountries?: string[];
|
|
4
|
-
lang?: string;
|
|
5
|
-
searchLocation?: string;
|
|
6
|
-
searchRegion?: string;
|
|
7
|
-
userLocation?: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface ReverseGeocodeInput {
|
|
11
|
-
q: string;
|
|
12
|
-
lang?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface ETAInput {
|
|
16
|
-
origin: string;
|
|
17
|
-
destinations: string[];
|
|
18
|
-
transportType?: TransportType;
|
|
19
|
-
departureDate?: string;
|
|
20
|
-
arrivalDate?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface SearchInput {
|
|
24
|
-
q: string;
|
|
25
|
-
excludePoiCategories?: PoiCategory[];
|
|
26
|
-
includePoiCategories?: PoiCategory[];
|
|
27
|
-
limitToCountries?: string[];
|
|
28
|
-
resultTypeFilter?: "Poi" | "Address";
|
|
29
|
-
lang?: string;
|
|
30
|
-
searchLocation?: string;
|
|
31
|
-
searchRegion?: string;
|
|
32
|
-
userLocation?: string;
|
|
33
|
-
}
|
package/src/responses.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
interface GeocodeResponse {
|
|
2
|
-
response: Place[];
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
interface ReverseGeocodeResponse {
|
|
6
|
-
response: Place[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface ETAResponse {
|
|
10
|
-
etas: ETA[];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface SearchResponse {
|
|
14
|
-
displayMapRegion: MapRegion;
|
|
15
|
-
results: SearchResponsePlace[];
|
|
16
|
-
}
|