opencage-api-client
Version:
An OpenCageData Geocoder API client library for node (ESM, CJS) and browsers (UMD)
1 lines • 4.49 kB
Source Map (JSON)
{"version":3,"file":"geocode.cjs","sources":["webpack://opencage-api-client/webpack/runtime/define_property_getters","webpack://opencage-api-client/webpack/runtime/has_own_property","webpack://opencage-api-client/webpack/runtime/make_namespace_object","webpack://opencage-api-client/./src/geocode.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { GeocodingRequest } from './types/GeocodingRequest';\nimport type { GeocodingResponse } from './types/GeocodingResponse';\nimport type { GeocodingOptions } from './types/GeocodingOptions';\nimport { fetchUrl } from './fetch';\nimport {\n buildValidationError,\n isUndefinedOrNull,\n buildQueryString,\n buildQuery,\n} from './helpers/geocodeHelpers';\n\nconst MISSING_OR_BAD_QUERY = 'missing or bad query';\nconst MISSING_API_KEY = 'missing API key';\n\n/**\n * geocode address and reverse geocode coordinates using\n * [OpenCage API](https://opencagedata.com/api) requesting the json format.\n *\n * @param {GeocodingRequest} input the input query parameter as JSON object,\n * the attribute `q` is required, the `key` can be omitted when using\n * a `proxyURL`, and when using node with a dedicated environment variable\n * (OPENCAGE_API_KEY).\n * Others optional parameters can be found at OpenCage Data API\n * [documentation](https://opencagedata.com/api#forward-opt)\n *\n * @param {Object} options the options object,\n * the attribute `signal` is used to abort the request when the signal is aborted.\n * the attribute `proxyURL` is used to proxy the request to a different URL.\n *\n * @return {Promise<GeocodingResponse>} a promise resolved by the json format API payload\n */\nexport async function geocode(\n input: GeocodingRequest,\n options?: GeocodingOptions\n): Promise<GeocodingResponse> {\n return new Promise((resolve, reject) => {\n if (isUndefinedOrNull(input)) {\n const error = buildValidationError(400, MISSING_OR_BAD_QUERY);\n reject(error);\n return;\n }\n const params = buildQuery(input, options);\n if (params.missingKey) {\n const error = buildValidationError(401, MISSING_API_KEY);\n reject(error);\n return;\n }\n const { query, endpoint } = params;\n const qs = buildQueryString(query);\n const url = `${endpoint}?${qs}`;\n // console.debug(url);\n fetchUrl(url, resolve, reject, options?.signal);\n });\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","MISSING_OR_BAD_QUERY","MISSING_API_KEY","geocode","input","options","Promise","resolve","reject","isUndefinedOrNull","error","buildValidationError","params","buildQuery","query","endpoint","qs","buildQueryString","url","fetchUrl"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;ACKA,MAAMI,uBAAuB;AAC7B,MAAMC,kBAAkB;AAmBjB,eAAeC,QACpBC,KAAuB,EACvBC,OAA0B;IAE1B,OAAO,IAAIC,QAAQ,CAACC,SAASC;QAC3B,IA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