UNPKG

fruit-company

Version:
99 lines 4.43 kB
"use strict"; /* * MIT No Attribution * * Copyright 2024 Peter "Kevin" Contreras * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * software and associated documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReverseGeocodeAddress = exports.GeocodeAddress = void 0; const serene_front_1 = require("serene-front"); const models_1 = require("./models"); const places_1 = require("./models/places"); class MapsGeocodingRequest { constructor() { } prepare({}) { throw new Error("Method not implemented."); } parse(_a) { return __awaiter(this, arguments, void 0, function* ({ fetchResponse }) { if (!fetchResponse.ok) { const errorResponse = yield fetchResponse.json(); throw new serene_front_1.RESTError(fetchResponse.status, fetchResponse.statusText, `${errorResponse.message} (${errorResponse.details.join(', ')})`); } const json = yield fetchResponse.text(); return (0, places_1.parsePlaceResults)(json); }); } } class GeocodeAddress extends MapsGeocodingRequest { constructor(options) { super(); this.options = options; } prepare({}) { const url = new URL(`${models_1.mapKitApiUrl}/geocode`); url.searchParams.append("q", this.options.query); if (this.options.limitToCountries !== undefined) { url.searchParams.append("limitToCountries", this.options.limitToCountries.join(",")); } if (this.options.language !== undefined) { url.searchParams.append("lang", this.options.language); } if (this.options.searchLocation !== undefined) { url.searchParams.append("searchLocation", this.options.searchLocation.urlPair); } if (this.options.searchRegion !== undefined) { url.searchParams.append("searchRegion", this.options.searchRegion.urlPair); } if (this.options.userLocation !== undefined) { url.searchParams.append("userLocation", this.options.userLocation.urlPair); } return new Request(url); } toString() { return `GeocodeAddress(${JSON.stringify(this.options)})`; } } exports.GeocodeAddress = GeocodeAddress; class ReverseGeocodeAddress extends MapsGeocodingRequest { constructor(options) { super(); this.options = options; } prepare({}) { const url = new URL(`${models_1.mapKitApiUrl}/reverseGeocode`); url.searchParams.append("loc", this.options.location.urlPair); if (this.options.language !== undefined) { url.searchParams.append("lang", this.options.language); } return new Request(url); } toString() { return `ReverseGeocodeAddress(${JSON.stringify(this.options)})`; } } exports.ReverseGeocodeAddress = ReverseGeocodeAddress; //# sourceMappingURL=requests.js.map