Comparing version 1.4.1 to 2.0.0
import { AxiosProxyConfig } from 'axios'; | ||
import { Auth, Search, Common, Convert, Theme, Planning, Population, Route, StaticMap } from './services'; | ||
import { Search, ReverseGeocode, CoordinateConverter, Theme, PlanningArea, Population, Route } from './services'; | ||
export interface Credential { | ||
@@ -12,14 +12,14 @@ email: string; | ||
export declare class OneMap { | ||
static readonly BASE_URL = "https://developers.onemap.sg"; | ||
#private; | ||
static readonly BASE_URL = "https://www.onemap.gov.sg/api"; | ||
readonly options?: Options; | ||
readonly auth: Auth; | ||
readonly search: Search; | ||
readonly common: Common; | ||
readonly convert: Convert; | ||
readonly reverseGeocode: ReverseGeocode; | ||
readonly coordinateConverter: CoordinateConverter; | ||
readonly theme: Theme; | ||
readonly planning: Planning; | ||
readonly planningArea: PlanningArea; | ||
readonly population: Population; | ||
readonly route: Route; | ||
readonly staticMap: StaticMap; | ||
constructor(options?: Options); | ||
getAccessToken(): Promise<string>; | ||
} |
"use strict"; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
}; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
if (kind === "m") throw new TypeError("Private method is not writable"); | ||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var _OneMap_token; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OneMap = void 0; | ||
const axios_1 = __importDefault(require("axios")); | ||
const services_1 = require("./services"); | ||
class OneMap { | ||
constructor(options) { | ||
_OneMap_token.set(this, void 0); | ||
this.options = options; | ||
this.auth = new services_1.Auth(this); | ||
this.search = new services_1.Search(this); | ||
this.common = new services_1.Common(this); | ||
this.convert = new services_1.Convert(this); | ||
this.reverseGeocode = new services_1.ReverseGeocode(this); | ||
this.coordinateConverter = new services_1.CoordinateConverter(this); | ||
this.theme = new services_1.Theme(this); | ||
this.planning = new services_1.Planning(this); | ||
this.planningArea = new services_1.PlanningArea(this); | ||
this.population = new services_1.Population(this); | ||
this.route = new services_1.Route(this); | ||
this.staticMap = new services_1.StaticMap(this); | ||
} | ||
async getAccessToken() { | ||
if (__classPrivateFieldGet(this, _OneMap_token, "f")) { | ||
const { access_token, expiry_timestamp } = __classPrivateFieldGet(this, _OneMap_token, "f"); | ||
if (expiry_timestamp > new Date().getTime()) { | ||
return access_token; | ||
} | ||
} | ||
if (!this.options?.credential) { | ||
throw new Error('No credential provided.'); | ||
} | ||
if (!this.options?.credential?.email || !this.options?.credential?.password) { | ||
throw new Error('Incomplete credential provided.'); | ||
} | ||
const response = await (0, axios_1.default)(`${OneMap.BASE_URL}/auth/post/getToken`, { | ||
proxy: this.options?.proxy, | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
data: this.options.credential | ||
}); | ||
const { access_token, expiry_timestamp } = response.data; | ||
__classPrivateFieldSet(this, _OneMap_token, { access_token, expiry_timestamp: Number(expiry_timestamp) }, "f"); | ||
return access_token; | ||
} | ||
} | ||
OneMap.BASE_URL = 'https://developers.onemap.sg'; | ||
_OneMap_token = new WeakMap(); | ||
OneMap.BASE_URL = 'https://www.onemap.gov.sg/api'; | ||
exports.OneMap = OneMap; |
export { Service } from './Service'; | ||
export { Auth } from './Auth'; | ||
export { Search } from './Search'; | ||
export { Common } from './Common'; | ||
export { Convert } from './Convert'; | ||
export { ReverseGeocode } from './ReverseGeocode'; | ||
export { CoordinateConverter } from './CoordinateConverter'; | ||
export { Theme } from './Theme'; | ||
export { Planning } from './Planning'; | ||
export { PlanningArea } from './PlanningArea'; | ||
export { Population } from './Population'; | ||
export { Route } from './Route'; | ||
export { StaticMap } from './StaticMap'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StaticMap = exports.Route = exports.Population = exports.Planning = exports.Theme = exports.Convert = exports.Common = exports.Search = exports.Auth = exports.Service = void 0; | ||
exports.Route = exports.Population = exports.PlanningArea = exports.Theme = exports.CoordinateConverter = exports.ReverseGeocode = exports.Search = exports.Service = void 0; | ||
var Service_1 = require("./Service"); | ||
Object.defineProperty(exports, "Service", { enumerable: true, get: function () { return Service_1.Service; } }); | ||
var Auth_1 = require("./Auth"); | ||
Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return Auth_1.Auth; } }); | ||
var Search_1 = require("./Search"); | ||
Object.defineProperty(exports, "Search", { enumerable: true, get: function () { return Search_1.Search; } }); | ||
var Common_1 = require("./Common"); | ||
Object.defineProperty(exports, "Common", { enumerable: true, get: function () { return Common_1.Common; } }); | ||
var Convert_1 = require("./Convert"); | ||
Object.defineProperty(exports, "Convert", { enumerable: true, get: function () { return Convert_1.Convert; } }); | ||
var ReverseGeocode_1 = require("./ReverseGeocode"); | ||
Object.defineProperty(exports, "ReverseGeocode", { enumerable: true, get: function () { return ReverseGeocode_1.ReverseGeocode; } }); | ||
var CoordinateConverter_1 = require("./CoordinateConverter"); | ||
Object.defineProperty(exports, "CoordinateConverter", { enumerable: true, get: function () { return CoordinateConverter_1.CoordinateConverter; } }); | ||
var Theme_1 = require("./Theme"); | ||
Object.defineProperty(exports, "Theme", { enumerable: true, get: function () { return Theme_1.Theme; } }); | ||
var Planning_1 = require("./Planning"); | ||
Object.defineProperty(exports, "Planning", { enumerable: true, get: function () { return Planning_1.Planning; } }); | ||
var PlanningArea_1 = require("./PlanningArea"); | ||
Object.defineProperty(exports, "PlanningArea", { enumerable: true, get: function () { return PlanningArea_1.PlanningArea; } }); | ||
var Population_1 = require("./Population"); | ||
@@ -22,3 +20,1 @@ Object.defineProperty(exports, "Population", { enumerable: true, get: function () { return Population_1.Population; } }); | ||
Object.defineProperty(exports, "Route", { enumerable: true, get: function () { return Route_1.Route; } }); | ||
var StaticMap_1 = require("./StaticMap"); | ||
Object.defineProperty(exports, "StaticMap", { enumerable: true, get: function () { return StaticMap_1.StaticMap; } }); |
@@ -7,62 +7,62 @@ "use strict"; | ||
constructor(onemap) { | ||
super(onemap, 'popapi'); | ||
super(onemap, 'public/popapi', true); | ||
} | ||
async getEconomicStatus(req) { | ||
return this.privateapi('getEconomicStatus', req); | ||
return this.fetch('getEconomicStatus', req); | ||
} | ||
async getEducationAttending(req) { | ||
return this.privateapi('getEducationAttending', req); | ||
return this.fetch('getEducationAttending', req); | ||
} | ||
async getEthnicGroup(req) { | ||
return this.privateapi('getEthnicGroup', req); | ||
return this.fetch('getEthnicGroup', req); | ||
} | ||
async getHouseholdMonthlyIncomeWork(req) { | ||
return this.privateapi('getHouseholdMonthlyIncomeWork', req); | ||
return this.fetch('getHouseholdMonthlyIncomeWork', req); | ||
} | ||
async getHouseholdSize(req) { | ||
return this.privateapi('getHouseholdSize', req); | ||
return this.fetch('getHouseholdSize', req); | ||
} | ||
async getHouseholdStructure(req) { | ||
return this.privateapi('getHouseholdStructure', req); | ||
return this.fetch('getHouseholdStructure', req); | ||
} | ||
async getIncomeFromWork(req) { | ||
return this.privateapi('getIncomeFromWork', req); | ||
return this.fetch('getIncomeFromWork', req); | ||
} | ||
async getIndustry(req) { | ||
return this.privateapi('getIndustry', req); | ||
return this.fetch('getIndustry', req); | ||
} | ||
async getLanguageLiterate(req) { | ||
return this.privateapi('getLanguageLiterate', req); | ||
return this.fetch('getLanguageLiterate', req); | ||
} | ||
async getMaritalStatus(req) { | ||
return this.privateapi('getMaritalStatus', req); | ||
return this.fetch('getMaritalStatus', req); | ||
} | ||
async getModeOfTransportSchool(req) { | ||
return this.privateapi('getModeOfTransportSchool', req); | ||
return this.fetch('getModeOfTransportSchool', req); | ||
} | ||
async getModeOfTransportWork(req) { | ||
return this.privateapi('getModeOfTransportWork', req); | ||
return this.fetch('getModeOfTransportWork', req); | ||
} | ||
async getOccupation(req) { | ||
return this.privateapi('getOccupation', req); | ||
return this.fetch('getOccupation', req); | ||
} | ||
async getPopulationAgeGroup(req) { | ||
return this.privateapi('getPopulationAgeGroup', req); | ||
return this.fetch('getPopulationAgeGroup', req); | ||
} | ||
async getReligion(req) { | ||
return this.privateapi('getReligion', req); | ||
return this.fetch('getReligion', req); | ||
} | ||
async getSpokenAtHome(req) { | ||
return this.privateapi('getSpokenAtHome', req); | ||
return this.fetch('getSpokenAtHome', req); | ||
} | ||
async getTenancy(req) { | ||
return this.privateapi('getTenancy', req); | ||
return this.fetch('getTenancy', req); | ||
} | ||
async getTypeOfDwellingHousehold(req) { | ||
return this.privateapi('getTypeOfDwellingHousehold', req); | ||
return this.fetch('getTypeOfDwellingHousehold', req); | ||
} | ||
async getTypeOfDwellingPop(req) { | ||
return this.privateapi('getTypeOfDwellingPop', req); | ||
return this.fetch('getTypeOfDwellingPop', req); | ||
} | ||
} | ||
exports.Population = Population; |
@@ -7,3 +7,3 @@ "use strict"; | ||
constructor(onemap) { | ||
super(onemap, 'routingsvc'); | ||
super(onemap, 'public/routingsvc', true); | ||
} | ||
@@ -14,5 +14,5 @@ async route(req) { | ||
newReq.end = newReq.end.join(','); | ||
return this.privateapi('route', newReq); | ||
return this.fetch('route', newReq); | ||
} | ||
} | ||
exports.Route = Route; |
@@ -7,8 +7,8 @@ "use strict"; | ||
constructor(onemap) { | ||
super(onemap, 'search'); | ||
super(onemap, 'common/elastic/search'); | ||
} | ||
async search(req) { | ||
return this.commonapi('', req); | ||
return this.fetch('', req); | ||
} | ||
} | ||
exports.Search = Search; |
@@ -5,6 +5,4 @@ import { OneMap } from '../OneMap'; | ||
protected readonly onemap: OneMap; | ||
protected constructor(onemap: OneMap, serviceName: string); | ||
protected commonapi(endpoint: string, query?: any): Promise<any>; | ||
protected privateapi(endpoint: string, query?: any): Promise<any>; | ||
protected getCommonApiUri(endpoint: string, query?: any): string; | ||
protected constructor(onemap: OneMap, route: string, auth?: boolean); | ||
fetch(endpoint: string, query: any): Promise<any>; | ||
} |
@@ -16,3 +16,3 @@ "use strict"; | ||
}; | ||
var _Service_instances, _Service_serviceName, _Service_getUri, _Service_fetch; | ||
var _Service_instances, _Service_route, _Service_auth, _Service_getUri; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -24,43 +24,31 @@ exports.Service = void 0; | ||
class Service { | ||
constructor(onemap, serviceName) { | ||
constructor(onemap, route, auth) { | ||
_Service_instances.add(this); | ||
_Service_serviceName.set(this, void 0); | ||
_Service_route.set(this, void 0); | ||
_Service_auth.set(this, void 0); | ||
this.onemap = onemap; | ||
__classPrivateFieldSet(this, _Service_serviceName, serviceName, "f"); | ||
__classPrivateFieldSet(this, _Service_route, route, "f"); | ||
__classPrivateFieldSet(this, _Service_auth, auth, "f"); | ||
} | ||
async commonapi(endpoint, query) { | ||
return __classPrivateFieldGet(this, _Service_instances, "m", _Service_fetch).call(this, 'commonapi', endpoint, query); | ||
} | ||
async privateapi(endpoint, query) { | ||
const auth = await this.onemap.auth.getToken(); | ||
if (query) { | ||
query.token = auth.access_token; | ||
async fetch(endpoint, query) { | ||
if (__classPrivateFieldGet(this, _Service_auth, "f")) { | ||
query.token = await this.onemap.getAccessToken(); | ||
} | ||
else { | ||
query = { token: auth.access_token }; | ||
} | ||
return __classPrivateFieldGet(this, _Service_instances, "m", _Service_fetch).call(this, 'privateapi', endpoint, query); | ||
const uri = __classPrivateFieldGet(this, _Service_instances, "m", _Service_getUri).call(this, endpoint, query); | ||
const response = await (0, axios_1.default)(uri, { | ||
proxy: this.onemap.options?.proxy, | ||
method: 'GET' | ||
}); | ||
return response.data; | ||
} | ||
getCommonApiUri(endpoint, query) { | ||
return __classPrivateFieldGet(this, _Service_instances, "m", _Service_getUri).call(this, 'commonapi', endpoint, query); | ||
} | ||
} | ||
exports.Service = Service; | ||
_Service_serviceName = new WeakMap(), _Service_instances = new WeakSet(), _Service_getUri = function _Service_getUri(type, endpoint, query) { | ||
if (query) { | ||
for (const key in query) { | ||
if (typeof query[key] === 'boolean') { | ||
query[key] = query[key] ? 'Y' : 'N'; | ||
} | ||
_Service_route = new WeakMap(), _Service_auth = new WeakMap(), _Service_instances = new WeakSet(), _Service_getUri = function _Service_getUri(endpoint, query) { | ||
for (const key in query) { | ||
if (typeof query[key] === 'boolean') { | ||
query[key] = query[key] ? 'Y' : 'N'; | ||
} | ||
endpoint += `?${querystring_1.default.stringify(query)}`; | ||
} | ||
return `${OneMap_1.OneMap.BASE_URL}/${type}/${__classPrivateFieldGet(this, _Service_serviceName, "f")}/${endpoint}`; | ||
}, _Service_fetch = async function _Service_fetch(type, endpoint, query) { | ||
const uri = __classPrivateFieldGet(this, _Service_instances, "m", _Service_getUri).call(this, type, endpoint, query); | ||
const response = await (0, axios_1.default)(uri, { | ||
proxy: this.onemap.options?.proxy, | ||
method: 'GET' | ||
}); | ||
return response.data; | ||
endpoint += `?${querystring_1.default.stringify(query)}`; | ||
return `${OneMap_1.OneMap.BASE_URL}/${__classPrivateFieldGet(this, _Service_route, "f")}/${endpoint}`; | ||
}; |
@@ -11,3 +11,3 @@ "use strict"; | ||
constructor(onemap) { | ||
super(onemap, 'themesvc'); | ||
super(onemap, 'public/themesvc', true); | ||
} | ||
@@ -17,9 +17,9 @@ async checkThemeStatus(req) { | ||
newReq.dateTime = (0, dayjs_1.default)(req.dateTime).format('YYYY-MM-DD[T]HH:mm:ss[:000Z]'); | ||
return this.privateapi('checkThemeStatus', newReq); | ||
return this.fetch('checkThemeStatus', newReq); | ||
} | ||
async getThemeInfo(req) { | ||
return this.privateapi('getThemeInfo', req); | ||
return this.fetch('getThemeInfo', req); | ||
} | ||
async getAllThemesInfo(req) { | ||
return this.privateapi('getAllThemesInfo', req); | ||
return this.fetch('getAllThemesInfo', req); | ||
} | ||
@@ -33,5 +33,5 @@ async retrieveTheme(req) { | ||
newReq.extents = extents.join(','); | ||
return this.privateapi('retrieveTheme', req); | ||
return this.fetch('retrieveTheme', req); | ||
} | ||
} | ||
exports.Theme = Theme; |
{ | ||
"name": "onemapsg", | ||
"version": "1.4.1", | ||
"version": "2.0.0", | ||
"author": "Chang Zhe Jiet", | ||
@@ -5,0 +5,0 @@ "description": "Helper library for using OneMap APIs.", |
@@ -18,3 +18,3 @@ # **onemapsg** | ||
```javascript | ||
```typescript | ||
import OneMap from 'onemapsg'; | ||
@@ -21,0 +21,0 @@ |
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
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
32751
27
881