apple-maps-server-sdk
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,1 +0,13 @@ | ||
export declare const Greeter: (name: string) => string; | ||
import { AxiosInstance } from "axios"; | ||
declare class AppleMaps { | ||
accessToken: string; | ||
authorizationToken: string; | ||
apiClient: AxiosInstance; | ||
constructor(authorizationToken: string); | ||
getAccessToken(): Promise<undefined>; | ||
geocode(input: GeocodeInput): Promise<GeocodeResponse>; | ||
reverseGeocode(input: ReverseGeocodeInput): Promise<ReverseGeocodeResponse>; | ||
eta(input: ETAInput): Promise<ETAResponse>; | ||
search(input: SearchInput): Promise<SearchResponse>; | ||
} | ||
export default AppleMaps; |
178
lib/index.js
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Greeter = void 0; | ||
var Greeter = function (name) { return "Hello ".concat(name); }; | ||
exports.Greeter = Greeter; | ||
const axios_1 = __importStar(require("axios")); | ||
const qs_1 = __importDefault(require("qs")); | ||
class AppleMaps { | ||
constructor(authorizationToken) { | ||
this.accessToken = ""; | ||
this.authorizationToken = authorizationToken; | ||
this.apiClient = axios_1.default.create({ | ||
baseURL: "https://maps-api.apple.com/v1", | ||
}); | ||
} | ||
getAccessToken() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const response = yield this.apiClient.get("/token", { | ||
headers: { | ||
Authorization: `Bearer ${this.authorizationToken}`, | ||
}, | ||
}); | ||
this.accessToken = response.data.accessToken; | ||
} | ||
catch (error) { | ||
console.error(error); | ||
} | ||
return; | ||
}); | ||
} | ||
geocode(input) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = qs_1.default.stringify(input); | ||
try { | ||
const response = yield this.apiClient.get("/geocode", { | ||
headers: { | ||
Authorization: `Bearer ${this.accessToken}`, | ||
}, | ||
params, | ||
}); | ||
return response.data; | ||
} | ||
catch (error) { | ||
if (error instanceof axios_1.AxiosError) { | ||
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) { | ||
yield this.getAccessToken(); | ||
return this.geocode(input); | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
else | ||
throw error; | ||
} | ||
}); | ||
} | ||
reverseGeocode(input) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = qs_1.default.stringify(input); | ||
try { | ||
const response = yield this.apiClient.get("/reverseGeocode", { | ||
headers: { | ||
Authorization: `Bearer ${this.accessToken}`, | ||
}, | ||
params, | ||
}); | ||
return response.data; | ||
} | ||
catch (error) { | ||
if (error instanceof axios_1.AxiosError) { | ||
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) { | ||
yield this.getAccessToken(); | ||
return this.reverseGeocode(input); | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
else | ||
throw error; | ||
} | ||
}); | ||
} | ||
eta(input) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = qs_1.default.stringify(input); | ||
try { | ||
const response = yield this.apiClient.get("/etas", { | ||
headers: { | ||
Authorization: `Bearer ${this.accessToken}`, | ||
}, | ||
params, | ||
}); | ||
return response.data; | ||
} | ||
catch (error) { | ||
if (error instanceof axios_1.AxiosError) { | ||
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) { | ||
yield this.getAccessToken(); | ||
return this.eta(input); | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
else | ||
throw error; | ||
} | ||
}); | ||
} | ||
search(input) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const params = qs_1.default.stringify(input); | ||
try { | ||
const response = yield this.apiClient.get("/search", { | ||
headers: { | ||
Authorization: `Bearer ${this.accessToken}`, | ||
}, | ||
params, | ||
}); | ||
return response.data; | ||
} | ||
catch (error) { | ||
if (error instanceof axios_1.AxiosError) { | ||
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) { | ||
yield this.getAccessToken(); | ||
return this.search(input); | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
else | ||
throw error; | ||
} | ||
}); | ||
} | ||
} | ||
exports.default = AppleMaps; |
{ | ||
"name": "apple-maps-server-sdk", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "An SDK for the Apple Maps Server API", | ||
@@ -24,4 +24,9 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@types/qs": "^6.9.7", | ||
"typescript": "^4.9.4" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.2.2", | ||
"qs": "^6.11.0" | ||
} | ||
} |
131
src/index.ts
@@ -1,1 +0,130 @@ | ||
export const Greeter = (name: string) => `Hello ${name}`; | ||
import axios, { AxiosError, AxiosInstance } from "axios"; | ||
import qs from "qs"; | ||
class AppleMaps { | ||
accessToken: string; | ||
authorizationToken: string; | ||
apiClient: AxiosInstance; | ||
constructor(authorizationToken: string) { | ||
this.accessToken = ""; | ||
this.authorizationToken = authorizationToken; | ||
this.apiClient = axios.create({ | ||
baseURL: "https://maps-api.apple.com/v1", | ||
}); | ||
} | ||
async getAccessToken(): Promise<undefined> { | ||
try { | ||
const response = await this.apiClient.get("/token", { | ||
headers: { | ||
Authorization: `Bearer ${this.authorizationToken}`, | ||
}, | ||
}); | ||
this.accessToken = response.data.accessToken; | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
return; | ||
} | ||
async geocode(input: GeocodeInput): Promise<GeocodeResponse> { | ||
const params = qs.stringify(input); | ||
try { | ||
const response = await this.apiClient.get("/geocode", { | ||
headers: { | ||
Authorization: `Bearer ${this.accessToken}`, | ||
}, | ||
params, | ||
}); | ||
return response.data; | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
if (error.response?.status === 401) { | ||
await this.getAccessToken(); | ||
return this.geocode(input); | ||
} else { | ||
throw error; | ||
} | ||
} else throw error; | ||
} | ||
} | ||
async reverseGeocode(input: ReverseGeocodeInput): Promise<ReverseGeocodeResponse> { | ||
const params = qs.stringify(input); | ||
try { | ||
const response = await this.apiClient.get("/reverseGeocode", { | ||
headers: { | ||
Authorization: `Bearer ${this.accessToken}`, | ||
}, | ||
params, | ||
}); | ||
return response.data; | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
if (error.response?.status === 401) { | ||
await this.getAccessToken(); | ||
return this.reverseGeocode(input); | ||
} else { | ||
throw error; | ||
} | ||
} else throw error; | ||
} | ||
} | ||
async eta(input: ETAInput): Promise<ETAResponse> { | ||
const params = qs.stringify(input); | ||
try { | ||
const response = await this.apiClient.get("/etas", { | ||
headers: { | ||
Authorization: `Bearer ${this.accessToken}`, | ||
}, | ||
params, | ||
}); | ||
return response.data; | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
if (error.response?.status === 401) { | ||
await this.getAccessToken(); | ||
return this.eta(input); | ||
} else { | ||
throw error; | ||
} | ||
} else throw error; | ||
} | ||
} | ||
async search(input: SearchInput): Promise<SearchResponse> { | ||
const params = qs.stringify(input); | ||
try { | ||
const response = await this.apiClient.get("/search", { | ||
headers: { | ||
Authorization: `Bearer ${this.accessToken}`, | ||
}, | ||
params, | ||
}); | ||
return response.data; | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
if (error.response?.status === 401) { | ||
await this.getAccessToken(); | ||
return this.search(input); | ||
} else { | ||
throw error; | ||
} | ||
} else throw error; | ||
} | ||
} | ||
} | ||
export default AppleMaps; |
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"target": "ES6", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"outDir": "./lib", | ||
"strict": true | ||
"strict": true, | ||
"esModuleInterop": true, | ||
}, | ||
@@ -9,0 +11,0 @@ "include": ["src"], |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14550
8
444
2
2
1
+ Addedaxios@^1.2.2
+ Addedqs@^6.11.0
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@1.7.8(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedproxy-from-env@1.1.0(transitive)
+ Addedqs@6.13.1(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedside-channel@1.0.6(transitive)