apple-maps-server-sdk 1.1.7 → 1.1.8

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.
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ const axios_1 = __importStar(require("axios"));
36
+ class AppleMaps {
37
+ constructor({ authorizationToken }) {
38
+ this.accessToken = "";
39
+ this.accessTokenRetries = 0;
40
+ this.authorizationToken = authorizationToken;
41
+ if (!authorizationToken) {
42
+ throw new Error("'authorizationToken' param is required");
43
+ }
44
+ this.apiClient = axios_1.default.create({
45
+ baseURL: "https://maps-api.apple.com/v1",
46
+ });
47
+ this.getAccessToken();
48
+ }
49
+ /**
50
+ * Take an authorization token and fetch an access token from apples servers
51
+ */
52
+ getAccessToken() {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ try {
55
+ const response = yield this.apiClient.get("/token", {
56
+ headers: {
57
+ Authorization: `Bearer ${this.authorizationToken}`,
58
+ },
59
+ });
60
+ this.accessToken = response.data.accessToken;
61
+ }
62
+ catch (error) {
63
+ throw error;
64
+ }
65
+ return;
66
+ });
67
+ }
68
+ handleError(err, callback) {
69
+ var _a;
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ if (err instanceof axios_1.AxiosError) {
72
+ if (((_a = err.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
73
+ if (this.accessTokenRetries > 3) {
74
+ this.accessTokenRetries = 0;
75
+ throw new Error("Unable to get access token");
76
+ }
77
+ this.accessTokenRetries++;
78
+ yield this.getAccessToken();
79
+ this.accessTokenRetries = 0;
80
+ return callback();
81
+ }
82
+ }
83
+ throw err;
84
+ });
85
+ }
86
+ /**
87
+ * Returns the latitude and longitude of the address you specify.
88
+ */
89
+ geocode(input) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ try {
92
+ const response = yield this.apiClient.get("/geocode", {
93
+ headers: {
94
+ Authorization: `Bearer ${this.accessToken}`,
95
+ },
96
+ params: input,
97
+ });
98
+ return response.data;
99
+ }
100
+ catch (error) {
101
+ return this.handleError(error, () => this.geocode(input));
102
+ }
103
+ });
104
+ }
105
+ /**
106
+ * Returns an array of addresses present at the coordinates you provide.
107
+ */
108
+ reverseGeocode(input) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ try {
111
+ const response = yield this.apiClient.get("/reverseGeocode", {
112
+ headers: {
113
+ Authorization: `Bearer ${this.accessToken}`,
114
+ },
115
+ params: input,
116
+ });
117
+ return response.data;
118
+ }
119
+ catch (error) {
120
+ return this.handleError(error, () => this.reverseGeocode(input));
121
+ }
122
+ });
123
+ }
124
+ /**
125
+ * Returns the estimated time of arrival (ETA) and distance between starting and ending locations.
126
+ */
127
+ eta(input) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ try {
130
+ const response = yield this.apiClient.get("/etas", {
131
+ headers: {
132
+ Authorization: `Bearer ${this.accessToken}`,
133
+ },
134
+ params: input,
135
+ });
136
+ return response.data;
137
+ }
138
+ catch (error) {
139
+ return this.handleError(error, () => this.eta(input));
140
+ }
141
+ });
142
+ }
143
+ /**
144
+ * Find places by name or by specific search criteria.
145
+ */
146
+ search(input) {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ try {
149
+ const response = yield this.apiClient.get("/search", {
150
+ headers: {
151
+ Authorization: `Bearer ${this.accessToken}`,
152
+ },
153
+ params: input,
154
+ });
155
+ return response.data;
156
+ }
157
+ catch (error) {
158
+ return this.handleError(error, () => this.search(input));
159
+ }
160
+ });
161
+ }
162
+ }
163
+ exports.default = AppleMaps;
@@ -0,0 +1,87 @@
1
+ type PoiCategory = "Airport" | "AirportGate" | "AirportTerminal" | "AmusementPark" | "ATM" | "Aquarium" | "Bakery" | "Bank" | "Beach" | "Brewery" | "Cafe" | "Campground" | "CarRental" | "EVCharger" | "FireStation" | "FitnessCenter" | "FoodMarket" | "GasStation" | "Hospital" | "Hotel" | "Laundry" | "Library" | "Marina" | "MovieTheater" | "Museum" | "NationalPark" | "Nightlife" | "Park" | "Parking" | "Pharmacy" | "Playground" | "Police" | "PostOffice" | "PublicTransport" | "ReligiousSite" | "Restaurant" | "Restroom" | "School" | "Stadium" | "Store" | "Theater" | "University" | "Winery" | "Zoo";
2
+ type TransportType = "Automobile" | "Transit" | "Walking";
3
+ interface Location {
4
+ latitude: number;
5
+ longitude: number;
6
+ }
7
+ interface MapRegion {
8
+ eastLongitude: number;
9
+ northLatitude: number;
10
+ southLatitude: number;
11
+ westLongitude: number;
12
+ }
13
+ interface StructuredAddress {
14
+ administrativeArea: string;
15
+ administrativeAreaCode: string;
16
+ areasOfInterest: string[];
17
+ dependentLocalities: string[];
18
+ fullThoroughfare: string;
19
+ locality: string;
20
+ postCode: string;
21
+ subLocality: string;
22
+ subThoroughfare: string;
23
+ thoroughfare: string;
24
+ }
25
+ interface Place {
26
+ country: string;
27
+ countryCode: string;
28
+ displayMapRegion: MapRegion;
29
+ formattedAddressLines: string[];
30
+ name: string;
31
+ coordinate: Location;
32
+ structuredAddress: StructuredAddress;
33
+ }
34
+ interface ETA {
35
+ destination: Location;
36
+ distanceMeters: number;
37
+ expectedTravelTimeSeconds: number;
38
+ staticTravelTimeSeconds: number;
39
+ transportType: TransportType;
40
+ }
41
+ interface SearchResponsePlace extends Place {
42
+ poiCategory: PoiCategory;
43
+ }
44
+ export interface GeocodeInput {
45
+ q: string;
46
+ limitToCountries?: string[];
47
+ lang?: string;
48
+ searchLocation?: string;
49
+ searchRegion?: string;
50
+ userLocation?: string;
51
+ }
52
+ export interface ReverseGeocodeInput {
53
+ loc: string;
54
+ lang?: string;
55
+ }
56
+ export interface ETAInput {
57
+ origin: string;
58
+ destinations: string[];
59
+ transportType?: TransportType;
60
+ departureDate?: string;
61
+ arrivalDate?: string;
62
+ }
63
+ export interface SearchInput {
64
+ q: string;
65
+ excludePoiCategories?: PoiCategory[];
66
+ includePoiCategories?: PoiCategory[];
67
+ limitToCountries?: string[];
68
+ resultTypeFilter?: "Poi" | "Address";
69
+ lang?: string;
70
+ searchLocation?: string;
71
+ searchRegion?: string;
72
+ userLocation?: string;
73
+ }
74
+ export interface GeocodeResponse {
75
+ results: Place[];
76
+ }
77
+ export interface ReverseGeocodeResponse {
78
+ results: Place[];
79
+ }
80
+ export interface ETAResponse {
81
+ etas: ETA[];
82
+ }
83
+ export interface SearchResponse {
84
+ displayMapRegion: MapRegion;
85
+ results: SearchResponsePlace[];
86
+ }
87
+ export {};
@@ -0,0 +1,34 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { GeocodeInput, GeocodeResponse, ReverseGeocodeInput, ReverseGeocodeResponse, ETAInput, ETAResponse, SearchInput, SearchResponse } from "./globals";
3
+ declare class AppleMaps {
4
+ accessToken: string;
5
+ authorizationToken: string;
6
+ accessTokenRetries: number;
7
+ apiClient: AxiosInstance;
8
+ constructor({ authorizationToken }: {
9
+ authorizationToken: string;
10
+ });
11
+ /**
12
+ * Take an authorization token and fetch an access token from apples servers
13
+ */
14
+ private getAccessToken;
15
+ private handleError;
16
+ /**
17
+ * Returns the latitude and longitude of the address you specify.
18
+ */
19
+ geocode(input: GeocodeInput): Promise<GeocodeResponse>;
20
+ /**
21
+ * Returns an array of addresses present at the coordinates you provide.
22
+ */
23
+ reverseGeocode(input: ReverseGeocodeInput): Promise<ReverseGeocodeResponse>;
24
+ /**
25
+ * Returns the estimated time of arrival (ETA) and distance between starting and ending locations.
26
+ */
27
+ eta(input: ETAInput): Promise<ETAResponse>;
28
+ /**
29
+ * Find places by name or by specific search criteria.
30
+ */
31
+ search(input: SearchInput): Promise<SearchResponse>;
32
+ }
33
+ export type { GeocodeInput, GeocodeResponse, ReverseGeocodeInput, ReverseGeocodeResponse, ETAInput, ETAResponse, SearchInput, SearchResponse, };
34
+ export default AppleMaps;
package/package.json CHANGED
@@ -1,13 +1,20 @@
1
1
  {
2
2
  "name": "apple-maps-server-sdk",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "type": "module",
5
5
  "description": "An SDK for the Apple Maps Server API",
6
- "main": "lib/index.js",
7
- "types": "lib/index.d.ts",
6
+ "main": "lib/cjs/index.js",
7
+ "module": "lib/esm/index.js",
8
+ "types": "lib/cjs/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./lib/esm/index.js",
12
+ "require": "./lib/cjs/index.js",
13
+ "types": "./lib/cjs/index.d.ts"
14
+ }
15
+ },
8
16
  "scripts": {
9
- "test": "echo \"Error: no test specified\" && exit 1",
10
- "build": "tsc",
17
+ "build": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json",
11
18
  "prepare": "npm run build"
12
19
  },
13
20
  "repository": {
@@ -30,7 +37,7 @@
30
37
  "homepage": "https://github.com/JS00001/apple-maps-server-sdk#readme",
31
38
  "devDependencies": {
32
39
  "@types/qs": "^6.9.7",
33
- "typescript": "^4.9.4"
40
+ "typescript": "^4.9.5"
34
41
  },
35
42
  "dependencies": {
36
43
  "axios": "^1.2.2",
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "CommonJS",
5
+ "moduleResolution": "node",
6
+ "outDir": "./lib/cjs"
7
+ }
8
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "ESNext",
5
+ "outDir": "./lib/esm"
6
+ }
7
+ }
package/tsconfig.json CHANGED
@@ -3,7 +3,6 @@
3
3
  "target": "ES6",
4
4
  "module": "esnext",
5
5
  "declaration": true,
6
- "outDir": "./lib",
7
6
  "strict": true,
8
7
  "esModuleInterop": true,
9
8
  "moduleResolution": "node"
File without changes
File without changes
File without changes
File without changes