From c263f3398b2814ffa46315dae92824565a71e11d Mon Sep 17 00:00:00 2001 From: wiredmatt <29718978+wiredmatt@users.noreply.github.com> Date: Wed, 31 Jan 2024 11:08:07 -0300 Subject: [PATCH] chore: temporarily add dist --- .gitignore | 2 +- dist/adapter.d.ts | 18 + dist/adapter.js | 86 ++ dist/adapter.js.map | 1 + dist/adapter.test.d.ts | 16 + dist/adapter.test.js | 84 ++ dist/adapter.test.js.map | 1 + dist/client.d.ts | 115 ++ dist/client.js | 206 +++ dist/client.js.map | 1 + dist/client.test.d.ts | 16 + dist/client.test.js | 193 +++ dist/client.test.js.map | 1 + dist/common.d.ts | 1557 +++++++++++++++++++++ dist/common.js | 716 ++++++++++ dist/common.js.map | 1 + dist/directions.d.ts | 171 +++ dist/directions.js | 56 + dist/directions.js.map | 1 + dist/directions.test.d.ts | 16 + dist/directions.test.js | 51 + dist/directions.test.js.map | 1 + dist/distance.d.ts | 152 ++ dist/distance.js | 48 + dist/distance.js.map | 1 + dist/distance.test.d.ts | 16 + dist/distance.test.js | 51 + dist/distance.test.js.map | 1 + dist/elevation.d.ts | 66 + dist/elevation.js | 46 + dist/elevation.js.map | 1 + dist/elevation.test.d.ts | 16 + dist/elevation.test.js | 68 + dist/elevation.test.js.map | 1 + dist/geocode/geocode.d.ts | 92 ++ dist/geocode/geocode.js | 46 + dist/geocode/geocode.js.map | 1 + dist/geocode/geocode.test.d.ts | 16 + dist/geocode/geocode.test.js | 39 + dist/geocode/geocode.test.js.map | 1 + dist/geocode/reversegeocode.d.ts | 93 ++ dist/geocode/reversegeocode.js | 63 + dist/geocode/reversegeocode.js.map | 1 + dist/geocode/reversegeocode.test.d.ts | 16 + dist/geocode/reversegeocode.test.js | 45 + dist/geocode/reversegeocode.test.js.map | 1 + dist/geolocate.d.ts | 109 ++ dist/geolocate.js | 76 + dist/geolocate.js.map | 1 + dist/geolocate.test.d.ts | 16 + dist/geolocate.test.js | 40 + dist/geolocate.test.js.map | 1 + dist/index.d.ts | 33 + dist/index.js | 43 + dist/index.js.map | 1 + dist/index.test.d.ts | 16 + dist/index.test.js | 22 + dist/index.test.js.map | 1 + dist/places/autocomplete.d.ts | 155 ++ dist/places/autocomplete.js | 73 + dist/places/autocomplete.js.map | 1 + dist/places/autocomplete.test.d.ts | 16 + dist/places/autocomplete.test.js | 39 + dist/places/autocomplete.test.js.map | 1 + dist/places/details.d.ts | 62 + dist/places/details.js | 45 + dist/places/details.js.map | 1 + dist/places/details.test.d.ts | 16 + dist/places/details.test.js | 43 + dist/places/details.test.js.map | 1 + dist/places/findplacefromtext.d.ts | 50 + dist/places/findplacefromtext.js | 45 + dist/places/findplacefromtext.js.map | 1 + dist/places/findplacefromtext.test.d.ts | 16 + dist/places/findplacefromtext.test.js | 45 + dist/places/findplacefromtext.test.js.map | 1 + dist/places/photo.d.ts | 57 + dist/places/photo.js | 44 + dist/places/photo.js.map | 1 + dist/places/photo.test.d.ts | 16 + dist/places/photo.test.js | 51 + dist/places/photo.test.js.map | 1 + dist/places/placesnearby.d.ts | 102 ++ dist/places/placesnearby.js | 56 + dist/places/placesnearby.js.map | 1 + dist/places/placesnearby.test.d.ts | 16 + dist/places/placesnearby.test.js | 43 + dist/places/placesnearby.test.js.map | 1 + dist/places/queryautocomplete.d.ts | 77 + dist/places/queryautocomplete.js | 43 + dist/places/queryautocomplete.js.map | 1 + dist/places/queryautocomplete.test.d.ts | 16 + dist/places/queryautocomplete.test.js | 39 + dist/places/queryautocomplete.test.js.map | 1 + dist/places/textsearch.d.ts | 93 ++ dist/places/textsearch.js | 43 + dist/places/textsearch.js.map | 1 + dist/places/textsearch.test.d.ts | 16 + dist/places/textsearch.test.js | 39 + dist/places/textsearch.test.js.map | 1 + dist/roads/nearestroads.d.ts | 36 + dist/roads/nearestroads.js | 45 + dist/roads/nearestroads.js.map | 1 + dist/roads/nearestroads.test.d.ts | 16 + dist/roads/nearestroads.test.js | 43 + dist/roads/nearestroads.test.js.map | 1 + dist/roads/snaptoroads.d.ts | 51 + dist/roads/snaptoroads.js | 45 + dist/roads/snaptoroads.js.map | 1 + dist/roads/snaptoroads.test.d.ts | 16 + dist/roads/snaptoroads.test.js | 43 + dist/roads/snaptoroads.test.js.map | 1 + dist/serialize.d.ts | 30 + dist/serialize.js | 148 ++ dist/serialize.js.map | 1 + dist/serialize.test.d.ts | 16 + dist/serialize.test.js | 131 ++ dist/serialize.test.js.map | 1 + dist/timezone.d.ts | 67 + dist/timezone.js | 46 + dist/timezone.js.map | 1 + dist/timezone.test.d.ts | 16 + dist/timezone.test.js | 47 + dist/timezone.test.js.map | 1 + dist/util.d.ts | 29 + dist/util.js | 82 ++ dist/util.js.map | 1 + dist/util.test.d.ts | 16 + dist/util.test.js | 104 ++ dist/util.test.js.map | 1 + 130 files changed, 6956 insertions(+), 1 deletion(-) create mode 100644 dist/adapter.d.ts create mode 100644 dist/adapter.js create mode 100644 dist/adapter.js.map create mode 100644 dist/adapter.test.d.ts create mode 100644 dist/adapter.test.js create mode 100644 dist/adapter.test.js.map create mode 100644 dist/client.d.ts create mode 100644 dist/client.js create mode 100644 dist/client.js.map create mode 100644 dist/client.test.d.ts create mode 100644 dist/client.test.js create mode 100644 dist/client.test.js.map create mode 100644 dist/common.d.ts create mode 100644 dist/common.js create mode 100644 dist/common.js.map create mode 100644 dist/directions.d.ts create mode 100644 dist/directions.js create mode 100644 dist/directions.js.map create mode 100644 dist/directions.test.d.ts create mode 100644 dist/directions.test.js create mode 100644 dist/directions.test.js.map create mode 100644 dist/distance.d.ts create mode 100644 dist/distance.js create mode 100644 dist/distance.js.map create mode 100644 dist/distance.test.d.ts create mode 100644 dist/distance.test.js create mode 100644 dist/distance.test.js.map create mode 100644 dist/elevation.d.ts create mode 100644 dist/elevation.js create mode 100644 dist/elevation.js.map create mode 100644 dist/elevation.test.d.ts create mode 100644 dist/elevation.test.js create mode 100644 dist/elevation.test.js.map create mode 100644 dist/geocode/geocode.d.ts create mode 100644 dist/geocode/geocode.js create mode 100644 dist/geocode/geocode.js.map create mode 100644 dist/geocode/geocode.test.d.ts create mode 100644 dist/geocode/geocode.test.js create mode 100644 dist/geocode/geocode.test.js.map create mode 100644 dist/geocode/reversegeocode.d.ts create mode 100644 dist/geocode/reversegeocode.js create mode 100644 dist/geocode/reversegeocode.js.map create mode 100644 dist/geocode/reversegeocode.test.d.ts create mode 100644 dist/geocode/reversegeocode.test.js create mode 100644 dist/geocode/reversegeocode.test.js.map create mode 100644 dist/geolocate.d.ts create mode 100644 dist/geolocate.js create mode 100644 dist/geolocate.js.map create mode 100644 dist/geolocate.test.d.ts create mode 100644 dist/geolocate.test.js create mode 100644 dist/geolocate.test.js.map create mode 100644 dist/index.d.ts create mode 100644 dist/index.js create mode 100644 dist/index.js.map create mode 100644 dist/index.test.d.ts create mode 100644 dist/index.test.js create mode 100644 dist/index.test.js.map create mode 100644 dist/places/autocomplete.d.ts create mode 100644 dist/places/autocomplete.js create mode 100644 dist/places/autocomplete.js.map create mode 100644 dist/places/autocomplete.test.d.ts create mode 100644 dist/places/autocomplete.test.js create mode 100644 dist/places/autocomplete.test.js.map create mode 100644 dist/places/details.d.ts create mode 100644 dist/places/details.js create mode 100644 dist/places/details.js.map create mode 100644 dist/places/details.test.d.ts create mode 100644 dist/places/details.test.js create mode 100644 dist/places/details.test.js.map create mode 100644 dist/places/findplacefromtext.d.ts create mode 100644 dist/places/findplacefromtext.js create mode 100644 dist/places/findplacefromtext.js.map create mode 100644 dist/places/findplacefromtext.test.d.ts create mode 100644 dist/places/findplacefromtext.test.js create mode 100644 dist/places/findplacefromtext.test.js.map create mode 100644 dist/places/photo.d.ts create mode 100644 dist/places/photo.js create mode 100644 dist/places/photo.js.map create mode 100644 dist/places/photo.test.d.ts create mode 100644 dist/places/photo.test.js create mode 100644 dist/places/photo.test.js.map create mode 100644 dist/places/placesnearby.d.ts create mode 100644 dist/places/placesnearby.js create mode 100644 dist/places/placesnearby.js.map create mode 100644 dist/places/placesnearby.test.d.ts create mode 100644 dist/places/placesnearby.test.js create mode 100644 dist/places/placesnearby.test.js.map create mode 100644 dist/places/queryautocomplete.d.ts create mode 100644 dist/places/queryautocomplete.js create mode 100644 dist/places/queryautocomplete.js.map create mode 100644 dist/places/queryautocomplete.test.d.ts create mode 100644 dist/places/queryautocomplete.test.js create mode 100644 dist/places/queryautocomplete.test.js.map create mode 100644 dist/places/textsearch.d.ts create mode 100644 dist/places/textsearch.js create mode 100644 dist/places/textsearch.js.map create mode 100644 dist/places/textsearch.test.d.ts create mode 100644 dist/places/textsearch.test.js create mode 100644 dist/places/textsearch.test.js.map create mode 100644 dist/roads/nearestroads.d.ts create mode 100644 dist/roads/nearestroads.js create mode 100644 dist/roads/nearestroads.js.map create mode 100644 dist/roads/nearestroads.test.d.ts create mode 100644 dist/roads/nearestroads.test.js create mode 100644 dist/roads/nearestroads.test.js.map create mode 100644 dist/roads/snaptoroads.d.ts create mode 100644 dist/roads/snaptoroads.js create mode 100644 dist/roads/snaptoroads.js.map create mode 100644 dist/roads/snaptoroads.test.d.ts create mode 100644 dist/roads/snaptoroads.test.js create mode 100644 dist/roads/snaptoroads.test.js.map create mode 100644 dist/serialize.d.ts create mode 100644 dist/serialize.js create mode 100644 dist/serialize.js.map create mode 100644 dist/serialize.test.d.ts create mode 100644 dist/serialize.test.js create mode 100644 dist/serialize.test.js.map create mode 100644 dist/timezone.d.ts create mode 100644 dist/timezone.js create mode 100644 dist/timezone.js.map create mode 100644 dist/timezone.test.d.ts create mode 100644 dist/timezone.test.js create mode 100644 dist/timezone.test.js.map create mode 100644 dist/util.d.ts create mode 100644 dist/util.js create mode 100644 dist/util.js.map create mode 100644 dist/util.test.d.ts create mode 100644 dist/util.test.js create mode 100644 dist/util.test.js.map diff --git a/.gitignore b/.gitignore index 83f2a05ba8..f65296ea39 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Logs logs *.log -dist/ +# dist/ docs/ # Runtime data pids diff --git a/dist/adapter.d.ts b/dist/adapter.d.ts new file mode 100644 index 0000000000..885a4c5cfb --- /dev/null +++ b/dist/adapter.d.ts @@ -0,0 +1,18 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { Status } from "./common"; +export declare function statusToCode(status: Status): number; +export declare const customAdapter: import("axios").AxiosAdapter; diff --git a/dist/adapter.js b/dist/adapter.js new file mode 100644 index 0000000000..1a0452059b --- /dev/null +++ b/dist/adapter.js @@ -0,0 +1,86 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.customAdapter = exports.statusToCode = void 0; +const common_1 = require("./common"); +const axios_1 = __importDefault(require("axios")); +function statusToCode(status) { + switch (status) { + case common_1.Status.OK: + case common_1.Status.ZERO_RESULTS: { + return 200; + } + case common_1.Status.INVALID_REQUEST: + case common_1.Status.MAX_ROUTE_LENGTH_EXCEEDED: + case common_1.Status.MAX_WAYPOINTS_EXCEEDED: { + return 400; + } + case common_1.Status.REQUEST_DENIED: { + return 403; + } + case common_1.Status.NOT_FOUND: { + return 404; + } + case common_1.Status.OVER_DAILY_LIMIT: + case common_1.Status.OVER_QUERY_LIMIT: { + return 429; + } + case common_1.Status.UNKNOWN_ERROR: { + return 500; + } + default: { + return 200; + } + } +} +exports.statusToCode = statusToCode; +function settle(resolve, reject, response) { + const validateStatus = response.config.validateStatus; + if (!response.status || !validateStatus || validateStatus(response.status)) { + resolve(response); + } + else { + reject(new axios_1.default.AxiosError("Request failed with status code " + response.status, [axios_1.default.AxiosError.ERR_BAD_REQUEST, axios_1.default.AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4], response.config, response.request, response)); + } +} +exports.customAdapter = axios_1.default.getAdapter((config) => { + const httpAdapter = axios_1.default.getAdapter("http"); + return new Promise((resolve, reject) => { + httpAdapter(config) + .then((r) => { + // unfortunately data is transformed after the adapter + let data = r.data; + if (config.transformResponse) { + const t = Array.isArray(config.transformResponse) + ? config.transformResponse + : [config.transformResponse]; + for (const fn of t) { + data = fn.call(config, data, r.headers, r.status); + } + } + if (r.status === 200 && data.status) { + r.status = statusToCode(data.status); + } + settle(resolve, reject, r); + }) + .catch(reject); + }); +}); +//# sourceMappingURL=adapter.js.map \ No newline at end of file diff --git a/dist/adapter.js.map b/dist/adapter.js.map new file mode 100644 index 0000000000..5c579ed1fa --- /dev/null +++ b/dist/adapter.js.map @@ -0,0 +1 @@ +{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;AAEH,qCAAkC;AAElC,kDAA0B;AAG1B,SAAgB,YAAY,CAAC,MAAc;IACzC,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,eAAM,CAAC,EAAE,CAAC;QACf,KAAK,eAAM,CAAC,YAAY,CAAC,CAAC,CAAC;YACzB,OAAO,GAAG,CAAC;QACb,CAAC;QACD,KAAK,eAAM,CAAC,eAAe,CAAC;QAC5B,KAAK,eAAM,CAAC,yBAAyB,CAAC;QACtC,KAAK,eAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC;YACnC,OAAO,GAAG,CAAC;QACb,CAAC;QACD,KAAK,eAAM,CAA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IAE7C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,WAAW,CAAC,MAAM,CAAC;aAChB,IAAI,CAAC,CAAC,CAAgB,EAAE,EAAE;YACzB,sDAAsD;YACtD,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;YAClB,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;gBAC7B,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC;oBAC/C,CAAC,CAAC,MAAM,CAAC,iBAAiB;oBAC1B,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;gBAC/B,KAAK,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;oBACnB,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;gBACpD,CAAC;YACH,CAAC;YAED,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBACpC,CAAC,CAAC,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvC,CAAC;YAED,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QAC7B,CAAC,CAAC;aACD,KAAK,CAAC,MAAM,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/adapter.test.d.ts b/dist/adapter.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/adapter.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/adapter.test.js b/dist/adapter.test.js new file mode 100644 index 0000000000..0d409d95bf --- /dev/null +++ b/dist/adapter.test.js @@ -0,0 +1,84 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +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 }); +const nock_1 = __importDefault(require("nock")); +const client_1 = require("./client"); +const common_1 = require("./common"); +const adapter_1 = require("./adapter"); +beforeAll(() => { + nock_1.default.disableNetConnect(); +}); +afterAll(() => { + nock_1.default.cleanAll(); + nock_1.default.enableNetConnect(); +}); +test("httpadapter rejects Status.NOT_FOUND", () => __awaiter(void 0, void 0, void 0, function* () { + (0, nock_1.default)("https://maps.googleapis.com") + .get("/maps/api/place/details/json?fields=place_id,name&key=foo&place_id=notarealid") + .reply(200, JSON.stringify({ status: common_1.Status.NOT_FOUND }), { + "Content-Type": "application/json", + }); + const client = new client_1.Client(); + const params = { + place_id: "notarealid", + key: "foo", + fields: ["place_id", "name"], + }; + yield expect(client.placeDetails({ params: params })).rejects.toEqual(Error("Request failed with status code 404")); +})); +test("httpadapter resolves Status.OK", () => __awaiter(void 0, void 0, void 0, function* () { + const response = { status: common_1.Status.OK }; + (0, nock_1.default)("https://maps.googleapis.com") + .get("/maps/api/place/details/json?fields=place_id,name&key=foo&place_id=notarealid") + .reply(200, JSON.stringify(response), { + "Content-Type": "application/json", + }); + const client = new client_1.Client(); + const params = { + place_id: "notarealid", + key: "foo", + fields: ["place_id", "name"], + }; + const r = yield client.placeDetails({ params: params }); + expect(r.data).toEqual(response); +})); +test("statusToCode returns correct value", () => { + expect((0, adapter_1.statusToCode)(common_1.Status.OK)).toEqual(200); + expect((0, adapter_1.statusToCode)(common_1.Status.ZERO_RESULTS)).toEqual(200); + expect((0, adapter_1.statusToCode)(common_1.Status.INVALID_REQUEST)).toEqual(400); + expect((0, adapter_1.statusToCode)(common_1.Status.MAX_ROUTE_LENGTH_EXCEEDED)).toEqual(400); + expect((0, adapter_1.statusToCode)(common_1.Status.MAX_WAYPOINTS_EXCEEDED)).toEqual(400); + expect((0, adapter_1.statusToCode)(common_1.Status.REQUEST_DENIED)).toEqual(403); + expect((0, adapter_1.statusToCode)(common_1.Status.NOT_FOUND)).toEqual(404); + expect((0, adapter_1.statusToCode)(common_1.Status.OVER_DAILY_LIMIT)).toEqual(429); + expect((0, adapter_1.statusToCode)(common_1.Status.OVER_QUERY_LIMIT)).toEqual(429); + expect((0, adapter_1.statusToCode)(common_1.Status.UNKNOWN_ERROR)).toEqual(500); + expect((0, adapter_1.statusToCode)("foo")).toEqual(200); +}); +//# sourceMappingURL=adapter.test.js.map \ No newline at end of file diff --git a/dist/adapter.test.js.map b/dist/adapter.test.js.map new file mode 100644 index 0000000000..c9dd4f0a22 --- /dev/null +++ b/dist/adapter.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"adapter.test.js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,GAAG,CAAC,CAAC;IACpD,MAAM,CAAC,IAAA,sBAAY,EAAC,eAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3D,MAAM,CAAC,IAAA,sBAAY,EAAC,eAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3D,MAAM,CAAC,IAAA,sBAAY,EAAC,eAAM,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACxD,MAAM,CAAC,IAAA,sBAAY,EAAC,KAAe,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AACrD,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/client.d.ts b/dist/client.d.ts new file mode 100644 index 0000000000..0edcc100e0 --- /dev/null +++ b/dist/client.d.ts @@ -0,0 +1,115 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as rax from "retry-axios"; +import { DirectionsRequest, DirectionsResponse } from "./directions"; +import { DistanceMatrixRequest, DistanceMatrixResponse } from "./distance"; +import { ElevationRequest, ElevationResponse } from "./elevation"; +import { FindPlaceFromTextRequest, FindPlaceFromTextResponse } from "./places/findplacefromtext"; +import { GeocodeRequest, GeocodeResponse } from "./geocode/geocode"; +import { GeolocateRequest, GeolocateResponse } from "./geolocate"; +import { NearestRoadsRequest, NearestRoadsResponse } from "./roads/nearestroads"; +import { PlaceAutocompleteRequest, PlaceAutocompleteResponse } from "./places/autocomplete"; +import { PlaceDetailsRequest, PlaceDetailsResponse } from "./places/details"; +import { PlacePhotoRequest, PlacePhotoResponse } from "./places/photo"; +import { PlaceQueryAutocompleteRequest, PlaceQueryAutocompleteResponse } from "./places/queryautocomplete"; +import { PlacesNearbyRequest, PlacesNearbyResponse } from "./places/placesnearby"; +import { ReverseGeocodeRequest, ReverseGeocodeResponse } from "./geocode/reversegeocode"; +import { SnapToRoadsRequest, SnapToRoadsResponse } from "./roads/snaptoroads"; +import { TextSearchRequest, TextSearchResponse } from "./places/textsearch"; +import { TimeZoneRequest, TimeZoneResponse } from "./timezone"; +import { AxiosInstance, AxiosRequestConfig } from "axios"; +import { HttpsAgent } from "agentkeepalive"; +export declare const version: any; +export declare const defaultHttpsAgent: HttpsAgent; +export declare const defaultTimeout = 10000; +export declare const userAgent: string; +export declare const acceptEncoding = "gzip"; +export declare const X_GOOG_MAPS_EXPERIENCE_ID = "X-GOOG-MAPS-EXPERIENCE-ID"; +export declare const defaultAxiosInstance: AxiosInstance; +export type Config = { + raxConfig?: rax.RetryConfig; +} & AxiosRequestConfig; +export interface ClientOptions { + /** AxiosInstance to be used by client. Provide one of axiosInstance or config. */ + axiosInstance?: AxiosInstance; + /** Config used to create AxiosInstance. Provide one of axiosInstance or config. */ + config?: Config; + experienceId?: string[]; +} +/** + * Client is a light wrapper around API methods providing shared configuration for Axios + * settings such as retry logic using the default retry-axios settings and gzip encoding. + * + * ### Instantiate with defaults + * ``` + * const client = Client() + * ``` + * + * ### Instantiate with config + * ``` + * const client = Client({config}) + * ``` + * + * ### Instantiate with axiosInstance **Advanced** + * ``` + * const axiosInstance = axios.create(config) + * const client = Client({axiosInstance}) + * ``` + */ +export declare class Client { + private readonly axiosInstance; + private experienceId; + constructor({ axiosInstance, config, experienceId }?: ClientOptions); + setExperienceId(...ids: string[]): void; + clearExperienceId(): void; + getExperienceId(): string[]; + directions(request: DirectionsRequest): Promise; + distancematrix(request: DistanceMatrixRequest): Promise; + elevation(request: ElevationRequest): Promise; + timezone(request: TimeZoneRequest): Promise; + geolocate(request: GeolocateRequest): Promise; + /** + * An example use of this function. + * + * ```javascript + * import { Client } from '@googlemaps/google-maps-services-js'; + * + * const args = { + * params: { + * key: '', + * address: 'Perth 4WD & Commercial Centre', + * } + * }; + * const client = new Client(); + * client.geocode(args).then(gcResponse => { + * const str = JSON.stringify(gcResponse.data.results[0]); + * console.log(`First result is: ${str}`); + * }); + * ``` + */ + geocode(request: GeocodeRequest): Promise; + reverseGeocode(request: ReverseGeocodeRequest): Promise; + placeAutocomplete(request: PlaceAutocompleteRequest): Promise; + placeDetails(request: PlaceDetailsRequest): Promise; + findPlaceFromText(request: FindPlaceFromTextRequest): Promise; + placePhoto(request: PlacePhotoRequest): Promise; + placesNearby(request: PlacesNearbyRequest): Promise; + placeQueryAutocomplete(request: PlaceQueryAutocompleteRequest): Promise; + textSearch(request: TextSearchRequest): Promise; + nearestRoads(request: NearestRoadsRequest): Promise; + snapToRoads(request: SnapToRoadsRequest): Promise; +} +export { DirectionsRequest, DirectionsResponse, DistanceMatrixRequest, DistanceMatrixResponse, ElevationRequest, ElevationResponse, FindPlaceFromTextRequest, FindPlaceFromTextResponse, GeolocateRequest, GeocodeRequest, GeocodeResponse, GeolocateResponse, NearestRoadsRequest, NearestRoadsResponse, PlaceAutocompleteRequest, PlaceAutocompleteResponse, PlaceDetailsRequest, PlaceDetailsResponse, PlacePhotoRequest, PlacePhotoResponse, PlaceQueryAutocompleteRequest, PlaceQueryAutocompleteResponse, PlacesNearbyRequest, PlacesNearbyResponse, ReverseGeocodeRequest, ReverseGeocodeResponse, SnapToRoadsRequest, SnapToRoadsResponse, TextSearchRequest, TextSearchResponse, TimeZoneRequest, TimeZoneResponse, }; diff --git a/dist/client.js b/dist/client.js new file mode 100644 index 0000000000..7fa9b53f71 --- /dev/null +++ b/dist/client.js @@ -0,0 +1,206 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +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 __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Client = exports.defaultAxiosInstance = exports.X_GOOG_MAPS_EXPERIENCE_ID = exports.acceptEncoding = exports.userAgent = exports.defaultTimeout = exports.defaultHttpsAgent = exports.version = void 0; +const rax = __importStar(require("retry-axios")); +const directions_1 = require("./directions"); +const distance_1 = require("./distance"); +const elevation_1 = require("./elevation"); +const findplacefromtext_1 = require("./places/findplacefromtext"); +const geocode_1 = require("./geocode/geocode"); +const geolocate_1 = require("./geolocate"); +const nearestroads_1 = require("./roads/nearestroads"); +const autocomplete_1 = require("./places/autocomplete"); +const details_1 = require("./places/details"); +const photo_1 = require("./places/photo"); +const queryautocomplete_1 = require("./places/queryautocomplete"); +const placesnearby_1 = require("./places/placesnearby"); +const reversegeocode_1 = require("./geocode/reversegeocode"); +const snaptoroads_1 = require("./roads/snaptoroads"); +const textsearch_1 = require("./places/textsearch"); +const timezone_1 = require("./timezone"); +const axios_1 = __importDefault(require("axios")); +const agentkeepalive_1 = require("agentkeepalive"); +const adapter_1 = require("./adapter"); +// Cannot be `import` as it's not under TS root dir +exports.version = require("../package.json").version; +exports.defaultHttpsAgent = new agentkeepalive_1.HttpsAgent({ keepAlive: true }); +exports.defaultTimeout = 10000; +exports.userAgent = `google-maps-services-node-${exports.version}`; +exports.acceptEncoding = "gzip"; +exports.X_GOOG_MAPS_EXPERIENCE_ID = "X-GOOG-MAPS-EXPERIENCE-ID"; +const defaultConfig = { + timeout: exports.defaultTimeout, + httpsAgent: exports.defaultHttpsAgent, + adapter: adapter_1.customAdapter, + headers: { + "User-Agent": exports.userAgent, + "Accept-Encoding": exports.acceptEncoding, + }, +}; +exports.defaultAxiosInstance = axios_1.default.create(defaultConfig); +rax.attach(exports.defaultAxiosInstance); +/** + * Client is a light wrapper around API methods providing shared configuration for Axios + * settings such as retry logic using the default retry-axios settings and gzip encoding. + * + * ### Instantiate with defaults + * ``` + * const client = Client() + * ``` + * + * ### Instantiate with config + * ``` + * const client = Client({config}) + * ``` + * + * ### Instantiate with axiosInstance **Advanced** + * ``` + * const axiosInstance = axios.create(config) + * const client = Client({axiosInstance}) + * ``` + */ +class Client { + constructor({ axiosInstance, config, experienceId } = {}) { + if (axiosInstance && config) { + throw new Error("Provide one of axiosInstance or config."); + } + if (axiosInstance) { + this.axiosInstance = axiosInstance; + this.axiosInstance.defaults.headers = Object.assign(Object.assign({}, defaultConfig.headers), this.axiosInstance.defaults.headers); + } + else if (config) { + config = Object.assign(Object.assign({}, defaultConfig), config); + config.headers = Object.assign(Object.assign({}, defaultConfig.headers), (config.headers || {})); + this.axiosInstance = axios_1.default.create(config); + rax.attach(this.axiosInstance); + } + else { + this.axiosInstance = exports.defaultAxiosInstance; + } + if (experienceId) { + this.setExperienceId(...experienceId); + } + } + setExperienceId(...ids) { + this.experienceId = ids; + this.axiosInstance.defaults.headers[exports.X_GOOG_MAPS_EXPERIENCE_ID] = + ids.join(","); + } + clearExperienceId() { + this.experienceId = null; + delete this.axiosInstance.defaults.headers[exports.X_GOOG_MAPS_EXPERIENCE_ID]; + } + getExperienceId() { + return this.experienceId; + } + directions(request) { + return (0, directions_1.directions)(request, this.axiosInstance); + } + distancematrix(request) { + return (0, distance_1.distancematrix)(request, this.axiosInstance); + } + elevation(request) { + return (0, elevation_1.elevation)(request, this.axiosInstance); + } + timezone(request) { + return (0, timezone_1.timezone)(request, this.axiosInstance); + } + geolocate(request) { + return (0, geolocate_1.geolocate)(request, this.axiosInstance); + } + /** + * An example use of this function. + * + * ```javascript + * import { Client } from '@googlemaps/google-maps-services-js'; + * + * const args = { + * params: { + * key: '', + * address: 'Perth 4WD & Commercial Centre', + * } + * }; + * const client = new Client(); + * client.geocode(args).then(gcResponse => { + * const str = JSON.stringify(gcResponse.data.results[0]); + * console.log(`First result is: ${str}`); + * }); + * ``` + */ + geocode(request) { + return (0, geocode_1.geocode)(request, this.axiosInstance); + } + reverseGeocode(request) { + return (0, reversegeocode_1.reverseGeocode)(request, this.axiosInstance); + } + placeAutocomplete(request) { + return (0, autocomplete_1.placeAutocomplete)(request, this.axiosInstance); + } + placeDetails(request) { + return (0, details_1.placeDetails)(request, this.axiosInstance); + } + findPlaceFromText(request) { + return (0, findplacefromtext_1.findPlaceFromText)(request, this.axiosInstance); + } + placePhoto(request) { + return (0, photo_1.placePhoto)(request, this.axiosInstance); + } + placesNearby(request) { + return (0, placesnearby_1.placesNearby)(request, this.axiosInstance); + } + placeQueryAutocomplete(request) { + return (0, queryautocomplete_1.placeQueryAutocomplete)(request, this.axiosInstance); + } + textSearch(request) { + return (0, textsearch_1.textSearch)(request, this.axiosInstance); + } + nearestRoads(request) { + return (0, nearestroads_1.nearestRoads)(request, this.axiosInstance); + } + snapToRoads(request) { + return (0, snaptoroads_1.snapToRoads)(request, this.axiosInstance); + } +} +exports.Client = Client; +//# sourceMappingURL=client.js.map \ No newline at end of file diff --git a/dist/client.js.map b/dist/client.js.map new file mode 100644 index 0000000000..9de0d98cb7 --- /dev/null +++ b/dist/client.js.map @@ -0,0 +1 @@ +{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,iDAAmC;AAEnC,6CAIsB;AACtB,yCAIoB;AACpB,2CAA6E;AAC7E,kEAIoC;AACpC,+CAA6E;AAC7E,2CAA6E;AAC7E,uDAI8B;AAC9B,wDAI+B;AAC/B,8CAI0B;AAC1B,0CAIwB;AACxB,kEAIoC;AACpC,wDAI+B;AAC/B,6DAIkC;AAClC,qDAI6B;AAC7B,oDAI6B;AAC7B,yCAAyE;AACzE,kDAAiE;AAEjE,mDAA4C;AAC5C,uCAA0C;AAE1C,mDAAmD;AACtC,QAAA,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC;AAC7C,QAAA,iBAAiB,GAAG,IAAI,2BAAU,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACxD,QAAA,cAAc,GAAG,KAAK,CAAC;AACvB,QAAA,SAAS,GAAG,6BAA6B,eAAO,EAAE,CAAC;AACnD,QAAA,cAAc,GAAG,MAAM,CAAC;AACxB,QAAA,yBAAyB,GAAG,2BAA2B,CAAC;AAErE,MAAM,aAAa,GAAuB;IACxC,OAAO,EAAE,sBAAc;IACvB,UAAU,EAAE,yBAAiB;IAC7B,OAAO,EAAE,uBAAa;IACtB,OAAO,EAAE;QACP,YAAY,EAAE,iBAAS;QACvB,iBAAiB,EAAE,sBAAc;KAClC;CACF,CAAC;AAEW,QAAA,oBAAoB,GAAG,eAAK,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;AAChE,GAAG,CAAC,MAAM,CAAC,4BAAoB,CAAC,CAAC;AAajC;;;;;;;;;;;;;;;;;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CAAC;IACxD,CAAC;IAED,UAAU,CAAC,OAA0B;QACnC,OAAO,IAAA,kBAAU,EAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACjD,CAAC;IAED,YAAY,CAAC,OAA4B;QACvC,OAAO,IAAA,2BAAY,EAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACnD,CAAC;IAED,sBAAsB,CACpB,OAAsC;QAEtC,OAAO,IAAA,0CAAsB,EAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC7D,CAAC;IAED,UAAU,CAAC,OAA0B;QACnC,OAAO,IAAA,uBAAU,EAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACjD,CAAC;IACD,YAAY,CAAC,OAA4B;QACvC,OAAO,IAAA,2BAAY,EAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACnD,CAAC;IACD,WAAW,CAAC,OAA2B;QACrC,OAAO,IAAA,yBAAW,EAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAClD,CAAC;CACF;AApID,wBAoIC"} \ No newline at end of file diff --git a/dist/client.test.d.ts b/dist/client.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/client.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/client.test.js b/dist/client.test.js new file mode 100644 index 0000000000..12ab191dc2 --- /dev/null +++ b/dist/client.test.js @@ -0,0 +1,193 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const client_1 = require("./client"); +const axios_1 = __importDefault(require("axios")); +test("client can be instantiated", () => { + const client = new client_1.Client({}); + expect(client["axiosInstance"]).toBeDefined(); +}); +test("client can be instantiated with axiosInstance", () => { + const client = new client_1.Client({ axiosInstance: axios_1.default.create({}) }); + expect(client["axiosInstance"]).toBeDefined(); +}); +test("client can be instantiated with axiosInstance has correct defaults", () => { + const client = new client_1.Client({ axiosInstance: axios_1.default.create({}) }); + expect(client["axiosInstance"].defaults.headers["User-Agent"]).toEqual(client_1.userAgent); + expect(client["axiosInstance"].defaults.headers["Accept-Encoding"]).toBe(client_1.acceptEncoding); + expect(client["axiosInstance"].defaults.timeout).toEqual(axios_1.default.defaults.timeout); +}); +test("client instantiated with custom instance and config throws error", () => { + expect(() => { + new client_1.Client({ + axiosInstance: client_1.defaultAxiosInstance, + config: { timeout: 10000 }, + }); + }).toThrowError(); +}); +test("client can be instantiated with header options", () => { + const client = new client_1.Client({ config: { headers: { "x-foo": "bar" } } }); + expect(client["axiosInstance"]).toBeDefined(); + expect(client["axiosInstance"].defaults.headers["x-foo"]).toEqual("bar"); + expect(client["axiosInstance"].defaults.headers["User-Agent"]).toEqual(client_1.userAgent); + expect(client["axiosInstance"].defaults.headers["Accept-Encoding"]).toBe(client_1.acceptEncoding); +}); +test("client can be override Accept-Encoding with header options", () => { + const client = new client_1.Client({ + config: { headers: { "x-foo": "bar", "Accept-Encoding": "identity" } }, + }); + expect(client["axiosInstance"]).toBeDefined(); + expect(client["axiosInstance"].defaults.headers["x-foo"]).toEqual("bar"); + expect(client["axiosInstance"].defaults.headers["User-Agent"]).toEqual(client_1.userAgent); + expect(client["axiosInstance"].defaults.headers["Accept-Encoding"]).toBe("identity"); +}); +test("client can be instantiated without header options", () => { + const client = new client_1.Client({ config: { timeout: 1234 } }); + expect(client["axiosInstance"]).toBeDefined(); + expect(client["axiosInstance"].defaults.timeout).toEqual(1234); + expect(client["axiosInstance"].defaults.headers["User-Agent"]).toEqual(client_1.userAgent); + expect(client["axiosInstance"].defaults.headers["Accept-Encoding"]).toBe(client_1.acceptEncoding); +}); +test("client can be instantiated with experienceId", () => { + const client = new client_1.Client({ experienceId: ["foo", "bar"] }); + expect(client["axiosInstance"].defaults.headers[client_1.X_GOOG_MAPS_EXPERIENCE_ID]).toEqual("foo,bar"); +}); +test("getExperienceId returns correct value", () => { + const ids = ["foo", "bar"]; + const client = new client_1.Client({ experienceId: ids }); + expect(client.getExperienceId()).toEqual(ids); +}); +test("clearExperienceIdHeader removes value and header from defaults", () => { + const client = new client_1.Client({}); + client["axiosInstance"].defaults.headers[client_1.X_GOOG_MAPS_EXPERIENCE_ID] = "foo"; + client.clearExperienceId(); + expect(client["axiosInstance"].defaults.headers[client_1.X_GOOG_MAPS_EXPERIENCE_ID]).toBeUndefined(); + expect(client["experienceId"]).toBeNull(); +}); +test("setExperienceId sets value and header", () => { + const client = new client_1.Client({}); + const ids = ["foo", "bar"]; + client.setExperienceId(...ids); + expect(client["axiosInstance"].defaults.headers[client_1.X_GOOG_MAPS_EXPERIENCE_ID]).toEqual("foo,bar"); + expect(client["experienceId"]).toEqual(ids); +}); +describe("client wraps all functions correctly", () => { + const client = new client_1.Client({}); + afterEach(() => { + jest.clearAllMocks(); + }); + test("client wraps directions correctly", () => { + const directions = require("./directions"); + const mock = (directions.directions = jest.fn()); + client.directions({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps distancematrix correctly", () => { + const distance = require("./distance"); + const mock = (distance.distancematrix = jest.fn()); + client.distancematrix({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps elevation correctly", () => { + const elevation = require("./elevation"); + const mock = (elevation.elevation = jest.fn()); + client.elevation({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps timezone correctly", () => { + const timezone = require("./timezone"); + const mock = (timezone.timezone = jest.fn()); + client.timezone({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps geolocate correctly", () => { + const geolocate = require("./geolocate"); + const mock = (geolocate.geolocate = jest.fn()); + client.geolocate({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps geocode correctly", () => { + const geocode = require("./geocode/geocode"); + const mock = (geocode.geocode = jest.fn()); + client.geocode({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps reverseGeocode correctly", () => { + const reverseGeocode = require("./geocode/reversegeocode"); + const mock = (reverseGeocode.reverseGeocode = jest.fn()); + client.reverseGeocode({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps placeAutocomplete correctly", () => { + const placeAutocomplete = require("./places/autocomplete"); + const mock = (placeAutocomplete.placeAutocomplete = jest.fn()); + client.placeAutocomplete({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps placeDetails correctly", () => { + const placeDetails = require("./places/details"); + const mock = (placeDetails.placeDetails = jest.fn()); + client.placeDetails({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps findPlaceFromText correctly", () => { + const findPlaceFromText = require("./places/findplacefromtext"); + const mock = (findPlaceFromText.findPlaceFromText = jest.fn()); + client.findPlaceFromText({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps placePhoto correctly", () => { + const placePhoto = require("./places/photo"); + const mock = (placePhoto.placePhoto = jest.fn()); + client.placePhoto({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps placesNearby correctly", () => { + const placesNearby = require("./places/placesnearby"); + const mock = (placesNearby.placesNearby = jest.fn()); + client.placesNearby({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps placeQueryAutocomplete correctly", () => { + const placeQueryAutocomplete = require("./places/queryautocomplete"); + const mock = (placeQueryAutocomplete.placeQueryAutocomplete = jest.fn()); + client.placeQueryAutocomplete({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps textSearch correctly", () => { + const textSearch = require("./places/textsearch"); + const mock = (textSearch.textSearch = jest.fn()); + client.textSearch({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps nearestRoads correctly", () => { + const nearestRoads = require("./roads/nearestroads"); + const mock = (nearestRoads.nearestRoads = jest.fn()); + client.nearestRoads({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); + test("client wraps snapToRoads correctly", () => { + const snapToRoads = require("./roads/snaptoroads"); + const mock = (snapToRoads.snapToRoads = jest.fn()); + client.snapToRoads({}); + expect(mock).toBeCalledWith({}, client["axiosInstance"]); + }); +}); +//# sourceMappingURL=client.test.js.map \ No newline at end of file diff --git a/dist/client.test.js.map b/dist/client.test.js.map new file mode 100644 index 0000000000..a87000fd59 --- /dev/null +++ b/dist/client.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"client.test.js","sourceRoot":"","sources":["../src/client.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,qCAsBkB;AAElB,kDAA0B;AAE1B,IAAI,CAAC,4BAA4B,EAAE,GAAG,EAAE;IACtC,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,EAAE,CAAC,CAAC;IAC9B,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AAChD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,+CAA+C,EAAE,GAAG,EAAE;IACzD,MAAM,MAAM,GAAG,IAAI,eAA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AAE;QAC/C,MAAM,YAAY,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;QACrD,MAAM,IAAI,GAAG,CAAC,YAAY,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QACrD,MAAM,CAAC,YAAY,CAAC,EAAyB,CAAC,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC9C,MAAM,WAAW,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;QACnD,MAAM,IAAI,GAAG,CAAC,WAAW,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QACnD,MAAM,CAAC,WAAW,CAAC,EAAwB,CAAC,CAAC;QAC7C,MAAM,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/common.d.ts b/dist/common.d.ts new file mode 100644 index 0000000000..a1817c7336 --- /dev/null +++ b/dist/common.d.ts @@ -0,0 +1,1557 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export type RequestParams = ApiKeyParams | PremiumPlanParams; +export interface ApiKeyParams { + /** + * You must include an API key with every API request. We strongly recommend that you restrict your API key. + * Restrictions provide added security and help ensure only authorized requests are made with your API key. + * + * There are two restrictions. You should set both: + * + * Application restriction: Limits usage of the API key to either websites (HTTP referrers), + * web servers (IP addresses), or mobile apps (Android apps or iOS apps). You can select only one + * restriction from this category, based on the platform of the API or SDK (see GMP APIs by Platform). + * + * API restriction: Limits usage of the API key to one or more APIs or SDKs. Requests to an API or SDK + * associated with the API key will be processed. Requests to an API or SDK not associated with the API + * key will fail. + */ + key: string; +} +/** + * The Google Maps Platform Premium Plan is no longer available for sign up or new customers. This option is + * only provided for maintaining existing legacy applications that use client IDs. For new applications, + * please use API keys. + * @deprecated + */ +export interface PremiumPlanParams { + /** project client ID */ + client_id: string; + /** project URL signing secret. Used to create the request signature */ + client_secret: string; +} +export interface ResponseData { + /** contains metadata on the request. See Status Codes below. */ + status: Status; + /** + * When the top-level status code is other than `OK`, this field contains more detailed information + * about the reasons behind the given status code. + */ + error_message: string; + /** may contain a set of attributions about this listing which must be displayed to the user (some listings may not have attribution). */ + html_attributions?: string[]; + /** + * contains a token that can be used to return up to 20 additional results. + * A `next_page_token` will not be returned if there are no additional results to display. + * The maximum number of results that can be returned is 60. + * There is a short delay between when a `next_page_token` is issued, and when it will become valid. + */ + next_page_token?: string; +} +export declare enum Status { + /** indicates the response contains a valid result. */ + OK = "OK", + /** indicates that the provided request was invalid. */ + INVALID_REQUEST = "INVALID_REQUEST", + /** + * indicates that too many `waypoints` were provided in the request. For applications using the Directions API as a web service, + * or the [directions service in the Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/directions), + * the maximum allowed number of `waypoints` is 23, plus the origin and destination. + */ + MAX_WAYPOINTS_EXCEEDED = "MAX_WAYPOINTS_EXCEEDED", + /** + * indicates the requested route is too long and cannot be processed. + * This error occurs when more complex directions are returned. + * Try reducing the number of waypoints, turns, or instructions. + */ + MAX_ROUTE_LENGTH_EXCEEDED = "MAX_ROUTE_LENGTH_EXCEEDED", + /** + * indicates any of the following: + * - The API key is missing or invalid. + * - Billing has not been enabled on your account. + * - A self-imposed usage cap has been exceeded. + * - The provided method of payment is no longer valid (for example, a credit card has expired). + * See the [Maps FAQ](https://developers.google.com/maps/faq#over-limit-key-error) to learn how to fix this. + */ + OVER_DAILY_LIMIT = "OVER_DAILY_LIMIT", + /** indicates the service has received too many requests from your application within the allowed time period. */ + OVER_QUERY_LIMIT = "OVER_QUERY_LIMIT", + /** indicates that the service denied use of the Distance Matrix service by your application. */ + REQUEST_DENIED = "REQUEST_DENIED", + /** indicates a Distance Matrix request could not be processed due to a server error. The request may succeed if you try again. */ + UNKNOWN_ERROR = "UNKNOWN_ERROR", + /** indicates that the request was successful but returned no results. */ + ZERO_RESULTS = "ZERO_RESULTS", + /** indicates that the referenced location (place_id) was not found in the Places database. */ + NOT_FOUND = "NOT_FOUND" +} +export interface PlacePhoto { + /** a string used to identify the photo when you perform a Photo request. */ + photo_reference: string; + /** the maximum height of the image. */ + height: number; + /** the maximum width of the image. */ + width: number; + /** contains any required attributions. This field will always be present, but may be empty. */ + html_attributions: string[]; +} +export declare enum PlaceIdScope { + /** + * The place ID is recognised by your application only. + * This is because your application added the place, and the place has not yet passed the moderation process. + */ + APP = "APP", + /** The place ID is available to other applications and on Google Maps. */ + GOOGLE = "GOOGLE" +} +export interface AlternativePlaceId { + /** + * The most likely reason for a place to have an alternative place ID is if your application adds a place and receives + * an application-scoped place ID, then later receives a Google-scoped place ID after passing the moderation process. + */ + place_id: string; + /** + * The scope of an alternative place ID will always be `APP`, + * indicating that the alternative place ID is recognised by your application only. + */ + scope: "APP"; +} +export declare enum PlaceInputType { + textQuery = "textquery", + phoneNumber = "phonenumber" +} +/** + * Table 1: Types supported in place search and addition + * + * You can use the following values in the types filter for place searches and when adding a place. + * + * @see https://developers.google.com/places/web-service/supported_types#table1 + */ +export declare enum PlaceType1 { + accounting = "accounting", + /** indicates an airport. */ + airport = "airport", + amusement_park = "amusement_park", + aquarium = "aquarium", + art_gallery = "art_gallery", + atm = "atm", + bakery = "bakery", + bank = "bank", + bar = "bar", + beauty_salon = "beauty_salon", + bicycle_store = "bicycle_store", + book_store = "book_store", + bowling_alley = "bowling_alley", + bus_station = "bus_station", + cafe = "cafe", + campground = "campground", + car_dealer = "car_dealer", + car_rental = "car_rental", + car_repair = "car_repair", + car_wash = "car_wash", + casino = "casino", + cemetery = "cemetery", + church = "church", + city_hall = "city_hall", + clothing_store = "clothing_store", + convenience_store = "convenience_store", + courthouse = "courthouse", + dentist = "dentist", + department_store = "department_store", + doctor = "doctor", + drugstore = "drugstore", + electrician = "electrician", + electronics_store = "electronics_store", + embassy = "embassy", + fire_station = "fire_station", + florist = "florist", + funeral_home = "funeral_home", + furniture_store = "furniture_store", + gas_station = "gas_station", + gym = "gym", + hair_care = "hair_care", + hardware_store = "hardware_store", + hindu_temple = "hindu_temple", + home_goods_store = "home_goods_store", + hospital = "hospital", + insurance_agency = "insurance_agency", + jewelry_store = "jewelry_store", + laundry = "laundry", + lawyer = "lawyer", + library = "library", + light_rail_station = "light_rail_station", + liquor_store = "liquor_store", + local_government_office = "local_government_office", + locksmith = "locksmith", + lodging = "lodging", + meal_delivery = "meal_delivery", + meal_takeaway = "meal_takeaway", + mosque = "mosque", + movie_rental = "movie_rental", + movie_theater = "movie_theater", + moving_company = "moving_company", + museum = "museum", + night_club = "night_club", + painter = "painter", + /** indicates a named park. */ + park = "park", + parking = "parking", + pet_store = "pet_store", + pharmacy = "pharmacy", + physiotherapist = "physiotherapist", + plumber = "plumber", + police = "police", + post_office = "post_office", + real_estate_agency = "real_estate_agency", + restaurant = "restaurant", + roofing_contractor = "roofing_contractor", + rv_park = "rv_park", + school = "school", + secondary_school = "secondary_school", + shoe_store = "shoe_store", + shopping_mall = "shopping_mall", + spa = "spa", + stadium = "stadium", + storage = "storage", + store = "store", + subway_station = "subway_station", + supermarket = "supermarket", + synagogue = "synagogue", + taxi_stand = "taxi_stand", + tourist_attraction = "tourist_attraction", + train_station = "train_station", + transit_station = "transit_station", + travel_agency = "travel_agency", + university = "university", + veterinary_care = "veterinary_care", + zoo = "zoo" +} +/** + * Table 2: Additional types returned by the Places service + * + * The following types may be returned in the results of a place search, in addition to the types in table 1 above. + * For more details on these types, refer to [Address Types](https://developers.google.com/maps/documentation/geocoding/intro#Types) + * in Geocoding Responses. + * + * @see https://developers.google.com/places/web-service/supported_types#table2 + */ +export declare enum PlaceType2 { + /** + * indicates a first-order civil entity below the country level. Within the United States, these administrative levels are states. + * Not all nations exhibit these administrative levels. In most cases, `administrative_area_level_1` short names will closely match + * ISO 3166-2 subdivisions and other widely circulated lists; however this is not guaranteed as our geocoding results are based + * on a variety of signals and location data. + */ + administrative_area_level_1 = "administrative_area_level_1", + /** + * indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. + * Not all nations exhibit these administrative levels. + */ + administrative_area_level_2 = "administrative_area_level_2", + /** + * indicates a third-order civil entity below the country level. This type indicates a minor civil division. + * Not all nations exhibit these administrative levels. + */ + administrative_area_level_3 = "administrative_area_level_3", + /** + * indicates a fourth-order civil entity below the country level. This type indicates a minor civil division. + * Not all nations exhibit these administrative levels. + */ + administrative_area_level_4 = "administrative_area_level_4", + /** + * indicates a fifth-order civil entity below the country level. This type indicates a minor civil division. + * Not all nations exhibit these administrative levels. + */ + administrative_area_level_5 = "administrative_area_level_5", + archipelago = "archipelago", + /** indicates a commonly-used alternative name for the entity. */ + colloquial_area = "colloquial_area", + continent = "continent", + /** indicates the national political entity, and is typically the highest order type returned by the Geocoder. */ + country = "country", + establishment = "establishment", + finance = "finance", + floor = "floor", + food = "food", + general_contractor = "general_contractor", + geocode = "geocode", + health = "health", + /** indicates a major intersection, usually of two major roads. */ + intersection = "intersection", + landmark = "landmark", + /** indicates an incorporated city or town political entity. */ + locality = "locality", + /** indicates a prominent natural feature. */ + natural_feature = "natural_feature", + /** indicates a named neighborhood */ + neighborhood = "neighborhood", + place_of_worship = "place_of_worship", + plus_code = "plus_code", + point_of_interest = "point_of_interest", + /** indicates a political entity. Usually, this type indicates a polygon of some civil administration. */ + political = "political", + post_box = "post_box", + /** indicates a postal code as used to address postal mail within the country. */ + postal_code = "postal_code", + postal_code_prefix = "postal_code_prefix", + postal_code_suffix = "postal_code_suffix", + postal_town = "postal_town", + /** indicates a named location, usually a building or collection of buildings with a common name */ + premise = "premise", + room = "room", + /** indicates a named route (such as "US 101"). */ + route = "route", + street_address = "street_address", + street_number = "street_number", + /** + * indicates a first-order civil entity below a locality. For some locations may receive one of the additional types: + * `sublocality_level_1` to `sublocality_level_5`. Each sublocality level is a civil entity. Larger numbers indicate a smaller + * geographic area. + */ + sublocality = "sublocality", + sublocality_level_1 = "sublocality_level_1", + sublocality_level_2 = "sublocality_level_2", + sublocality_level_3 = "sublocality_level_3", + sublocality_level_4 = "sublocality_level_4", + sublocality_level_5 = "sublocality_level_5", + /** + * indicates a first-order entity below a named location, usually a singular building within a collection of buildings with a + * common name. + */ + subpremise = "subpremise", + town_square = "town_square" +} +export interface PlaceReview { + /** + * contains a collection of `AspectRating` objects, each of which provides a rating of a single attribute of the establishment. + * The first object in the collection is considered the primary aspect. + */ + aspects: AspectRating[]; + /** the name of the user who submitted the review. Anonymous reviews are attributed to "A Google user". */ + author_name: string; + /** the URL to the user's Google Maps Local Guides profile, if available. */ + author_url?: string; + /** + * an IETF language code indicating the language used in the user's review. + * This field contains the main language tag only, and not the secondary tag indicating country or region. + * For example, all the English reviews are tagged as 'en', and not 'en-AU' or 'en-UK' and so on. + */ + language: string; + /** the URL to the user's profile photo, if available. */ + profile_photo_url: string; + /** the user's overall rating for this place. This is a whole number, ranging from 1 to 5. */ + rating: number; + relative_time_description: string; + /** + * the user's review. When reviewing a location with Google Places, text reviews are considered optional. + * Therefore, this field may by empty. Note that this field may include simple HTML markup. + * For example, the entity reference `&` may represent an ampersand character. + */ + text: string; + /** the time that the review was submitted, measured in the number of seconds since since midnight, January 1, 1970 UTC. */ + time: string; +} +export interface AspectRating { + /** the name of the aspect that is being rated. */ + type: AspectRatingType; + /** the user's rating for this particular aspect, from 0 to 3. */ + rating: number; +} +export declare enum AspectRatingType { + appeal = "appeal", + atmosphere = "atmosphere", + decor = "decor", + facilities = "facilities", + food = "food", + overall = "overall", + quality = "quality", + service = "service" +} +export type Place = Partial; +export interface PlaceData { + /** + * is an array containing the separate components applicable to this address. + * + * Note the following facts about the `address_components[]` array: + * - The array of address components may contain more components than the `formatted_address`. + * - The array does not necessarily include all the political entities that contain an address, + * apart from those included in the `formatted_address`. To retrieve all the political entities + * that contain a specific address, you should use reverse geocoding, passing the latitude/longitude + * of the address as a parameter to the request. + * - The format of the response is not guaranteed to remain the same between requests. + * In particular, the number of `address_components` varies based on the address requested + * and can change over time for the same address. A component can change position in the array. + * The type of the component can change. A particular component may be missing in a later response. + */ + address_components: AddressComponent[]; + /** + * is a string containing the human-readable address of this place. + * + * Often this address is equivalent to the postal address. Note that some countries, such as the United Kingdom, + * do not allow distribution of true postal addresses due to licensing restrictions. + * + * The formatted address is logically composed of one or more address components. + * For example, the address "111 8th Avenue, New York, NY" consists of the following components: "111" + * (the street number), "8th Avenue" (the route), "New York" (the city) and "NY" (the US state). + * + * Do not parse the formatted address programmatically. Instead you should use the individual address components, + * which the API response includes in addition to the formatted address field. + */ + formatted_address: string; + /** + * contains the place's phone number in its local format. + * For example, the `formatted_phone_number` for Google's Sydney, Australia office is `(02) 9374 4000`. + */ + formatted_phone_number: string; + /** is a representation of the place's address in the [adr microformat](http://microformats.org/wiki/adr). */ + adr_address: string; + /** + * Contains a summary of the place. A summary is comprised of a textual overview, and also includes the language code + * for these if applicable. Summary text must be presented as-is and can not be modified or altered. + */ + editorial_summary: PlaceEditorialSummary; + /** + * contains the following information: + * - `location`: contains the geocoded latitude,longitude value for this place. + * - `viewport`: contains the preferred viewport when displaying this place on a map as a `LatLngBounds` if it is known. + */ + geometry: AddressGeometry; + /** + * is an encoded location reference, derived from latitude and longitude coordinates, that represents an area: + * 1/8000th of a degree by 1/8000th of a degree (about 14m x 14m at the equator) or smaller. + * Plus codes can be used as a replacement for street addresses in places where they do not exist + * (where buildings are not numbered or streets are not named). + * + * The plus code is formatted as a global code and a compound code: + * - `global_code` is a 4 character area code and 6 character or longer local code (849VCWC8+R9). + * - `compound_code` is a 6 character or longer local code with an explicit location (CWC8+R9, Mountain View, CA, USA). + * + * Typically, both the global code and compound code are returned. + * However, if the result is in a remote location (for example, an ocean or desert) only the global code may be returned. + * + * @see [Open Location Code](https://en.wikipedia.org/wiki/Open_Location_Code) + * @see [plus codes](https://plus.codes/) + */ + plus_code: PlusCode; + /** contains the URL of a suggested icon which may be displayed to the user when indicating this result on a map. */ + icon: string; + /** + * The default HEX color code for the place's category. + * @see https://developers.google.com/maps/documentation/places/web-service/icons + */ + icon_background_color: string; + /** + * The base URL for a non-colored icon, minus the file type extension (append `.svg` or `.png`). + * @see https://developers.google.com/maps/documentation/places/web-service/icons + */ + icon_mask_base_uri: string; + /** + * contains the place's phone number in international format. + * International format includes the country code, and is prefixed with the plus (+) sign. + * For example, the `international_phone_number` for Google's Sydney, Australia office is `+61 2 9374 4000`. + */ + international_phone_number: string; + /** + * contains the human-readable name for the returned result. + * For establishment results, this is usually the canonicalized business name. + */ + name: string; + /** place opening hours. */ + opening_hours: OpeningHours; + /** + * is a boolean flag indicating whether the place has permanently shut down (value `true`). + * If the place is not permanently closed, the flag is absent from the response. This field is deprecated in favor of `business_status`. + */ + permanently_closed: boolean; + /** + * is a string indicating the operational status of the place, if it is a business. + */ + business_status: string; + /** + * an array of photo objects, each containing a reference to an image. + * A Place Details request may return up to ten photos. + * More information about place photos and how you can use the images in your application can be found in the Place Photos documentation. + */ + photos: PlacePhoto[]; + /** + * A textual identifier that uniquely identifies a place. + * To retrieve information about the place, pass this identifier in the `placeId` field of a Places API request. + */ + place_id: string; + /** + * The price level of the place, on a scale of 0 to 4. + * The exact amount indicated by a specific value will vary from region to region. + * + * Price levels are interpreted as follows: + * - `0`: Free + * - `1`: Inexpensive + * - `2`: Moderate + * - `3`: Expensive + * - `4`: Very Expensive + */ + price_level: number; + /** contains the place's rating, from 1.0 to 5.0, based on aggregated user reviews. */ + rating: number; + /** The total number of ratings from users */ + user_ratings_total: number; + /** + * a JSON array of up to five reviews. If a `language` parameter was specified in the Place Details request, + * the Places Service will bias the results to prefer reviews written in that language. + */ + reviews: PlaceReview[]; + /** + * contains an array of feature types describing the given result. + * XML responses include multiple `` elements if more than one type is assigned to the result. + */ + types: AddressType[]; + /** + * contains the URL of the official Google page for this place. + * This will be the Google-owned page that contains the best available information about the place. + * Applications must link to or embed this page on any screen that shows detailed results about the place to the user. + */ + url: string; + /** + * contains the number of minutes this place’s current timezone is offset from UTC. + * For example, for places in Sydney, Australia during daylight saving time this would be 660 (+11 hours from UTC), + * and for places in California outside of daylight saving time this would be -480 (-8 hours from UTC). + */ + utc_offset: number; + /** + * lists a simplified address for the place, including the street name, street number, and locality, + * but not the province/state, postal code, or country. For example, Google's Sydney, Australia office + * has a `vicinity` value of `48 Pirrama Road, Pyrmont`. + */ + vicinity: string; + /** lists the authoritative website for this place, such as a business' homepage. */ + website: string; +} +export type LatLngArray = [number, number]; +export type LatLngString = string; +export interface LatLngLiteral { + lat: number; + lng: number; +} +export interface LatLngLiteralVerbose { + latitude: number; + longitude: number; +} +/** + * A latitude, longitude pair. The API methods accept either: + * - a two-item array of [latitude, longitude]; + * - a comma-separated string; + * - an object with 'lat', 'lng' properties; or + * - an object with 'latitude', 'longitude' properties. + */ +export type LatLng = LatLngArray | LatLngString | LatLngLiteral | LatLngLiteralVerbose; +/** The bounds parameter defines the latitude/longitude coordinates of the southwest and northeast corners of this bounding box. */ +export interface LatLngBounds { + northeast: LatLngLiteral; + southwest: LatLngLiteral; +} +/** + * By default the API will attempt to load the most appropriate language based on the users location or browser settings. + * Some APIs allow you to explicitly set a language when you make a request + * + * @see https://developers.google.com/maps/faq#languagesupport + */ +export declare enum Language { + /** Arabic */ + ar = "ar", + /** Belarusian */ + be = "be", + /** Bulgarian */ + bg = "bg", + /** Bengali */ + bn = "bn", + /** Catalan */ + ca = "ca", + /** Czech */ + cs = "cs", + /** Danish */ + da = "da", + /** German */ + de = "de", + /** Greek */ + el = "el", + /** English */ + en = "en", + /** English (Australian) */ + en_Au = "en-Au", + /** English (Great Britain) */ + en_GB = "en-GB", + /** Spanish */ + es = "es", + /** Basque */ + eu = "eu", + /** Farsi */ + fa = "fa", + /** Finnish */ + fi = "fi", + /** Filipino */ + fil = "fil", + /** French */ + fr = "fr", + /** Galician */ + gl = "gl", + /** Gujarati */ + gu = "gu", + /** Hindi */ + hi = "hi", + /** Croatian */ + hr = "hr", + /** Hungarian */ + hu = "hu", + /** Indonesian */ + id = "id", + /** Italian */ + it = "it", + /** Hebrew */ + iw = "iw", + /** Japanese */ + ja = "ja", + /** Kazakh */ + kk = "kk", + /** Kannada */ + kn = "kn", + /** Korean */ + ko = "ko", + /** Kyrgyz */ + ky = "ky", + /** Lithuanian */ + lt = "lt", + /** Latvian */ + lv = "lv", + /** Macedonian */ + mk = "mk", + /** Malayalam */ + ml = "ml", + /** Marathi */ + mr = "mr", + /** Burmese */ + my = "my", + /** Dutch */ + nl = "nl", + /** Norwegian */ + no = "no", + /** Punjabi */ + pa = "pa", + /** Polish */ + pl = "pl", + /** Portuguese */ + pt = "pt", + /** Portuguese (Brazil) */ + pt_BR = "pt-BR", + /** Portuguese (Portugal) */ + pt_PT = "pt-PT", + /** Romanian */ + ro = "ro", + /** Russian */ + ru = "ru", + /** Slovak */ + sk = "sk", + /** Slovenian */ + sl = "sl", + /** Albanian */ + sq = "sq", + /** Serbian */ + sr = "sr", + /** Swedish */ + sv = "sv", + /** Tamil */ + ta = "ta", + /** Telugu */ + te = "te", + /** Thai */ + th = "th", + /** Tagalog */ + tl = "tl", + /** Turkish */ + tr = "tr", + /** Ukrainian */ + uk = "uk", + /** Uzbek */ + uz = "uz", + /** Vietnamese */ + vi = "vi", + /** Chinese (Simlified) */ + zh_CN = "zh-CN", + /** Chinese (Traditional) */ + zh_TW = "zh-TW" +} +/** + * When you calculate directions, you may specify the transportation mode to use. + * By default, directions are calculated as `driving` directions. + * + * **Note:** Both walking and bicycling directions may sometimes not include clear pedestrian or bicycling paths, + * so these directions will return warnings in the returned result which you must display to the user. + */ +export declare enum TravelMode { + /** (default) indicates standard driving directions using the road network. */ + driving = "driving", + /** requests walking directions via pedestrian paths & sidewalks (where available). */ + walking = "walking", + /** requests bicycling directions via bicycle paths & preferred streets (where available). */ + bicycling = "bicycling", + /** + * requests directions via public transit routes (where available). + * If you set the mode to transit, you can optionally specify either a departure_time or an arrival_time. + * If neither time is specified, the departure_time defaults to now (that is, the departure time defaults to the current time). + * You can also optionally include a transit_mode and/or a transit_routing_preference. + */ + transit = "transit" +} +export declare enum TravelRestriction { + /** indicates that the calculated route should avoid toll roads/bridges. */ + tolls = "tolls", + /** indicates that the calculated route should avoid highways. */ + highways = "highways", + /** indicates that the calculated route should avoid ferries. */ + ferries = "ferries", + /** + * indicates that the calculated route should avoid indoor steps for walking and transit directions. + * Only requests that include an API key or a Google Maps APIs Premium Plan client ID will receive indoor steps by default. + */ + indoor = "indoor" +} +/** + * Directions results contain text within distance fields that may be displayed to the user to indicate the distance of + * a particular "step" of the route. By default, this text uses the unit system of the origin's country or region. + */ +export declare enum UnitSystem { + /** specifies usage of the metric system. Textual distances are returned using kilometers and meters. */ + metric = "metric", + /** specifies usage of the Imperial (English) system. Textual distances are returned using miles and feet. */ + imperial = "imperial" +} +export declare enum TrafficModel { + /** + * indicates that the returned `duration_in_traffic` should be the best estimate of travel time given what is known about + * both historical traffic conditions and live traffic. Live traffic becomes more important the closer the `departure_time` is to now. + */ + best_guess = "best_guess", + /** + * indicates that the returned `duration_in_traffic` should be longer than the actual travel time on most days, + * though occasional days with particularly bad traffic conditions may exceed this value. + */ + pessimistic = "pessimistic", + /** + * indicates that the returned `duration_in_traffic` should be shorter than the actual travel time on most days, + * though occasional days with particularly good traffic conditions may be faster than this value. + */ + optimistic = "optimistic" +} +export declare enum TransitMode { + /** indicates that the calculated route should prefer travel by bus. */ + bus = "bus", + /** indicates that the calculated route should prefer travel by subway. */ + subway = "subway", + /** indicates that the calculated route should prefer travel by train. */ + train = "train", + /** indicates that the calculated route should prefer travel by tram and light rail. */ + tram = "tram", + /** + * indicates that the calculated route should prefer travel by train, tram, light rail, and subway. + * This is equivalent to `transit_mode=train|tram|subway` + */ + rail = "rail" +} +export declare enum TransitRoutingPreference { + /** indicates that the calculated route should prefer limited amounts of walking. */ + less_walking = "less_walking", + /** indicates that the calculated route should prefer a limited number of transfers. */ + fewer_transfers = "fewer_transfers" +} +/** + * The `status` field within the Directions response object contains the status of the request, and may contain debugging information + * to help you track down why the Directions service failed. + */ +export declare enum DirectionsResponseStatus { + /** indicates the response contains a valid `result`. */ + OK = "OK", + /** indicates at least one of the locations specified in the request's origin, destination, or waypoints could not be geocoded. */ + NOT_FOUND = "NOT_FOUND", + /** indicates no route could be found between the origin and destination. */ + ZERO_RESULTS = "ZERO_RESULTS", + /** + * indicates that too many `waypoints` were provided in the request. For applications using the Directions API as a web service, + * or the [directions service in the Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/directions), + * the maximum allowed number of `waypoints` is 23, plus the origin and destination. + */ + MAX_WAYPOINTS_EXCEEDED = "MAX_WAYPOINTS_EXCEEDED", + /** + * indicates the requested route is too long and cannot be processed. + * This error occurs when more complex directions are returned. + * Try reducing the number of waypoints, turns, or instructions. + */ + MAX_ROUTE_LENGTH_EXCEEDED = "MAX_ROUTE_LENGTH_EXCEEDED", + /** indicates that the provided request was invalid. Common causes of this status include an invalid parameter or parameter value. */ + INVALID_REQUEST = "INVALID_REQUEST", + /** + * indicates any of the following: + * - The API key is missing or invalid. + * - Billing has not been enabled on your account. + * - A self-imposed usage cap has been exceeded. + * - The provided method of payment is no longer valid (for example, a credit card has expired). + * See the [Maps FAQ](https://developers.google.com/maps/faq#over-limit-key-error) to learn how to fix this. + */ + OVER_DAILY_LIMIT = "OVER_DAILY_LIMIT", + /** indicates the service has received too many requests from your application within the allowed time period. */ + OVER_QUERY_LIMIT = "OVER_QUERY_LIMIT", + /** indicates that the service denied use of the directions service by your application. */ + REQUEST_DENIED = "REQUEST_DENIED", + /** indicates a directions request could not be processed due to a server error. The request may succeed if you try again. */ + UNKNOWN_ERROR = "UNKNOWN_ERROR" +} +/** + * The `status` field within the Directions response object contains the status of the request, and may contain debugging information + * to help you track down why the Directions service failed. + * @deprecated + */ +export declare enum DirectionsReponseStatus { + /** indicates the response contains a valid `result`. */ + OK = "OK", + /** indicates at least one of the locations specified in the request's origin, destination, or waypoints could not be geocoded. */ + NOT_FOUND = "NOT_FOUND", + /** indicates no route could be found between the origin and destination. */ + ZERO_RESULTS = "ZERO_RESULTS", + /** + * indicates that too many `waypoints` were provided in the request. For applications using the Directions API as a web service, + * or the [directions service in the Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/directions), + * the maximum allowed number of `waypoints` is 23, plus the origin and destination. + */ + MAX_WAYPOINTS_EXCEEDED = "MAX_WAYPOINTS_EXCEEDED", + /** + * indicates the requested route is too long and cannot be processed. + * This error occurs when more complex directions are returned. + * Try reducing the number of waypoints, turns, or instructions. + */ + MAX_ROUTE_LENGTH_EXCEEDED = "MAX_ROUTE_LENGTH_EXCEEDED", + /** indicates that the provided request was invalid. Common causes of this status include an invalid parameter or parameter value. */ + INVALID_REQUEST = "INVALID_REQUEST", + /** + * indicates any of the following: + * - The API key is missing or invalid. + * - Billing has not been enabled on your account. + * - A self-imposed usage cap has been exceeded. + * - The provided method of payment is no longer valid (for example, a credit card has expired). + * See the [Maps FAQ](https://developers.google.com/maps/faq#over-limit-key-error) to learn how to fix this. + */ + OVER_DAILY_LIMIT = "OVER_DAILY_LIMIT", + /** indicates the service has received too many requests from your application within the allowed time period. */ + OVER_QUERY_LIMIT = "OVER_QUERY_LIMIT", + /** indicates that the service denied use of the directions service by your application. */ + REQUEST_DENIED = "REQUEST_DENIED", + /** indicates a directions request could not be processed due to a server error. The request may succeed if you try again. */ + UNKNOWN_ERROR = "UNKNOWN_ERROR" +} +/** + * Elements in the `geocoded_waypoints` array correspond, by their zero-based position, to the origin, + * the waypoints in the order they are specified, and the destination. + */ +export interface GeocodedWaypoint { + /** indicates the status code resulting from the geocoding operation. */ + geocoder_status: GeocodedWaypointStatus; + /** + * indicates that the geocoder did not return an exact match for the original request, though it was able to match part of the + * requested address. You may wish to examine the original request for misspellings and/or an incomplete address. + * + * Partial matches most often occur for street addresses that do not exist within the locality you pass in the request. + * Partial matches may also be returned when a request matches two or more locations in the same locality. + * For example, "21 Henr St, Bristol, UK" will return a partial match for both Henry Street and Henrietta Street. + * Note that if a request includes a misspelled address component, the geocoding service may suggest an alternative address. + * Suggestions triggered in this way will also be marked as a partial match. + */ + partial_match: boolean; + /** unique identifier that can be used with other Google APIs. */ + place_id: string; + /** + * indicates the *address type* of the geocoding result used for calculating directions. + * + * An empty list of types indicates there are no known types for the particular address component, for example, Lieu-dit in France. + */ + types: AddressType[]; +} +export declare enum GeocodedWaypointStatus { + /** indicates that no errors occurred; the address was successfully parsed and at least one geocode was returned. */ + OK = "OK", + /** + * indicates that the geocode was successful but returned no results. + * This may occur if the geocoder was passed a non-existent `address`. + */ + ZERO_RESULTS = "ZERO_RESULTS" +} +export declare const AddressType: typeof PlaceType1 & typeof PlaceType2; +export type AddressType = PlaceType1 | PlaceType2; +/** + * This route may consist of one or more `legs` depending on whether any waypoints were specified. As well, the route also contains + * copyright and warning information which must be displayed to the user in addition to the routing information. + */ +export interface DirectionsRoute { + /** contains a short textual description for the route, suitable for naming and disambiguating the route from alternatives. */ + summary: string; + /** + * contains an array which contains information about a leg of the route, between two locations within the given route. + * A separate leg will be present for each waypoint or destination specified. + * (A route with no waypoints will contain exactly one leg within the `legs` array.) + * Each leg consists of a series of `steps`. + */ + legs: RouteLeg[]; + /** + * contains an array indicating the order of any waypoints in the calculated route. + * This waypoints may be reordered if the request was passed `optimize:true` within its `waypoints` parameter. + */ + waypoint_order: number[]; + /** + * contains a single `points` object that holds an encoded polyline representation of the route. + * This polyline is an approximate (smoothed) path of the resulting directions. + */ + overview_polyline: { + points: string; + }; + /** contains the viewport bounding box of the `overview_polyline`. */ + bounds: LatLngBounds; + /** contains the copyrights text to be displayed for this route. You must handle and display this information yourself. */ + copyrights: string; + /** contains an array of warnings to be displayed when showing these directions. You must handle and display these warnings yourself. */ + warnings: string[]; + /** + * If present, contains the total fare (that is, the total ticket costs) on this route. + * This property is only returned for transit requests and only for routes where fare information is available for all transit legs. + * + * **Note:** The Directions API only returns fare information for requests that contain either an API key or a client ID + * and digital signature. + */ + fare: TransitFare; + /** + * An array of LatLngs representing the entire course of this route. The path is simplified in order to make + * it suitable in contexts where a small number of vertices is required (such as Static Maps API URLs). + */ + overview_path: LatLngLiteral[]; +} +export interface TransitFare { + /** An [ISO 4217 currency code](https://en.wikipedia.org/wiki/ISO_4217) indicating the currency that the amount is expressed in. */ + currency: string; + /** The total fare amount, in the currency specified above. */ + value: number; + /** The total fare amount, formatted in the requested language. */ + text: string; +} +/** + * A single leg of the journey from the origin to the destination in the calculated route. + * For routes that contain no waypoints, the route will consist of a single "leg," but for routes that define one or more waypoints, + * the route will consist of one or more legs, corresponding to the specific legs of the journey. + */ +export interface RouteLeg { + /** contains an array of steps denoting information about each separate step of the leg of the journey. */ + steps: DirectionsStep[]; + /** + * indicates the total distance covered by this leg, as a field with the following elements. + * + * This field may be absent if the distance is unknown. + */ + distance: Distance; + /** + * indicates the total duration of this leg. + * + * This field may be absent if the duration is unknown. + */ + duration: Duration; + /** + * indicates the total duration of this leg. + * This value is an estimate of the time in traffic based on current and historical traffic conditions. + * See the `traffic_model` request parameter for the options you can use to request that the returned value is optimistic, pessimistic, + * or a best-guess estimate. The duration in traffic is returned only if all of the following are true: + * + * - The request includes a valid API key, or a valid Google Maps APIs Premium Plan client ID and signature. + * - The request does not include stopover waypoints. If the request includes waypoints, they must be prefixed with `via:` + * to avoid stopovers. + * - The request is specifically for driving directions—the `mode` parameter is set to `driving`. + * - The request includes a `departure_time` parameter. + * - Traffic conditions are available for the requested route. + */ + duration_in_traffic?: Duration; + /** contains the estimated time of arrival for this leg. This property is only returned for transit directions. */ + arrival_time: Time; + /** + * contains the estimated time of departure for this leg, specified as a `Time` object. + * The `departure_time` is only available for transit directions. + */ + departure_time: Time; + /** + * contains the latitude/longitude coordinates of the origin of this leg. + * Because the Directions API calculates directions between locations by using the nearest transportation option (usually a road) + * at the start and end points, `start_location` may be different than the provided origin of this leg if, for example, + * a road is not near the origin. + */ + start_location: LatLngLiteral; + /** + * contains the latitude/longitude coordinates of the given destination of this leg. + * Because the Directions API calculates directions between locations by using the nearest transportation option (usually a road) + * at the start and end points, `end_location` may be different than the provided destination of this leg if, for example, + * a road is not near the destination. + */ + end_location: LatLngLiteral; + /** contains the human-readable address (typically a street address) resulting from reverse geocoding the `start_location` of this leg. */ + start_address: string; + /** contains the human-readable address (typically a street address) from reverse geocoding the `end_location` of this leg. */ + end_address: string; +} +/** + * A step is the most atomic unit of a direction's route, containing a single step describing a specific, single instruction on the journey. + * E.g. "Turn left at W. 4th St." The step not only describes the instruction but also contains distance and duration information relating to + * how this step relates to the following step. For example, a step denoted as "Merge onto I-80 West" may contain a duration of + * "37 miles" and "40 minutes," indicating that the next step is 37 miles/40 minutes from this step. + * + * When using the Directions API to search for transit directions, the steps array will include additional transit details in the form of + * a `transit_details` array. If the directions include multiple modes of transportation, detailed directions will be provided for walking or + * driving steps in an inner `steps` array. For example, a walking step will include directions from the start and end locations: + * "Walk to Innes Ave & Fitch St". That step will include detailed walking directions for that route in the inner `steps` array, such as: + * "Head north-west", "Turn left onto Arelious Walker", and "Turn left onto Innes Ave". + */ +export interface DirectionsStep { + /** contains formatted instructions for this step, presented as an HTML text string. */ + html_instructions: string; + /** + * contains the distance covered by this step until the next step. (See the discussion of this field in Directions Legs) + * + * This field may be undefined if the distance is unknown. + */ + distance: Distance; + /** + * contains the typical time required to perform the step, until the next step. (See the description in Directions Legs) + * + * This field may be undefined if the duration is unknown + */ + duration: Duration; + /** contains the location of the starting point of this step, as a single set of `lat` and `lng` fields. */ + start_location: LatLngLiteral; + /** contains the location of the last point of this step, as a single set of `lat` and `lng` fields. */ + end_location: LatLngLiteral; + /** + * contains the action to take for the current step (turn left, merge, straight, etc.). + * This field is used to determine which icon to display. + */ + maneuver: Maneuver; + /** + * contains a single points object that holds an encoded polyline representation of the step. + * This polyline is an approximate (smoothed) path of the step. + */ + polyline: { + points: string; + }; + /** + * contains detailed directions for walking or driving steps in transit directions. + * Substeps are only available when `travel_mode` is set to "transit". + * The inner `steps` array is of the same type as `steps`. + */ + steps: DirectionsStep; + /** contains transit specific information. This field is only returned with travel_mode is set to "transit". */ + transit_details: TransitDetails; + /** contains the type of travel mode used. */ + travel_mode: TravelMode; +} +export interface Distance { + /** indicates the distance in meters. */ + value: number; + /** + * contains a human-readable representation of the distance, displayed in units as used at the origin + * (or as overridden within the `units` parameter in the request). + * (For example, miles and feet will be used for any origin within the United States.) + */ + text: string; +} +export interface Duration { + /** indicates the duration in seconds. */ + value: number; + /** contains a human-readable representation of the duration. */ + text: string; +} +export interface Time { + /** the time specified as a JavaScript `Date` object. */ + value: Date; + /** the time specified as a string. The time is displayed in the time zone of the transit stop. */ + text: string; + /** + * contains the time zone of this station. The value is the name of the time zone as defined in the + * [IANA Time Zone Database](http://www.iana.org/time-zones), e.g. "America/New_York". + */ + time_zone: string; +} +export declare enum Maneuver { + turn_slight_left = "turn-slight-left", + turn_sharp_left = "turn-sharp-left", + uturn_left = "uturn-left", + turn_left = "turn-left", + turn_slight_right = "turn-slight-right", + turn_sharp_right = "turn-sharp-right", + uturn_right = "uturn-right", + turn_right = "turn-right", + straight = "straight", + ramp_left = "ramp-left", + ramp_right = "ramp-right", + merge = "merge", + fork_left = "fork-left", + fork_right = "fork-right", + ferry = "ferry", + ferry_train = "ferry-train", + roundabout_left = "roundabout-left", + roundabout_right = "roundabout-right" +} +/** + * Transit directions return additional information that is not relevant for other modes of transportation. + * These additional properties are exposed through the `transit_details` object, returned as a field of an element in the `steps[]` array. + * From the `TransitDetails` object you can access additional information about the transit stop, transit line and transit agency + */ +export interface TransitDetails { + /** contains information about the stop for this part of the trip. */ + arrival_stop: TransitStop; + /** contains information about the station for this part of the trip. */ + departure_stop: TransitStop; + /** contain the arrival time for this leg of the journey. */ + arrival_time: Time; + /** contain the departure time for this leg of the journey. */ + departure_time: Time; + /** + * specifies the direction in which to travel on this line, as it is marked on the vehicle or at the departure stop. + * This will often be the terminus station. + */ + headsign: string; + /** + * specifies the expected number of seconds between departures from the same stop at this time. + * For example, with a `headway` value of 600, you would expect a ten minute wait if you should miss your bus. + */ + headway: number; + /** + * contains the number of stops in this step, counting the arrival stop, but not the departure stop. + * For example, if your directions involve leaving from Stop A, passing through stops B and C, and arriving at stop D, + * `num_stops` will return 3. + */ + num_stops: number; + /** contains information about the transit line used in this step. */ + line: TransitLine; +} +export interface TransitStop { + /** the name of the transit station/stop. eg. "Union Square". */ + name: string; + /** the location of the transit station/stop, represented as a `lat` and `lng` field. */ + location: LatLngLiteral; +} +export interface TransitLine { + /** contains the full name of this transit line. eg. "7 Avenue Express". */ + name: string; + /** contains the short name of this transit line. This will normally be a line number, such as "M7" or "355". */ + short_name: string; + /** contains the color commonly used in signage for this transit line. The color will be specified as a hex string such as: #FF0033. */ + color: string; + /** + * is an array containing a single `TransitAgency` object. + * The `TransitAgency` object provides information about the operator of the line + */ + agencies: TransitAgency[]; + /** contains the URL for this transit line as provided by the transit agency. */ + url: string; + /** contains the URL for the icon associated with this line. */ + icon: string; + /** contains the color of text commonly used for signage of this line. The color will be specified as a hex string. */ + text_color: string; + /** contains the type of vehicle used on this line. */ + vehicle: TransitVehicle; +} +/** You must display the names and URLs of the transit agencies servicing the trip results. */ +export interface TransitAgency { + /** contains the name of the transit agency. */ + name: string; + /** contains the phone number of the transit agency. */ + phone: string; + /** contains the URL for the transit agency. */ + url: string; +} +export interface TransitVehicle { + /** contains the name of the vehicle on this line. eg. "Subway.". */ + name: string; + /** contains the type of vehicle that runs on this line. */ + type: VehicleType; + /** contains the URL for an icon associated with this vehicle type. */ + icon: string; + /** contains the URL for the icon associated with this vehicle type, based on the local transport signage. */ + local_icon: string; +} +/** @see https://developers.google.com/maps/documentation/directions/intro#VehicleType. */ +export declare enum VehicleType { + /** Rail. */ + RAIL = "RAIL", + /** Light rail transit. */ + METRO_RAIL = "METRO_RAIL", + /** Underground light rail. */ + SUBWAY = "SUBWAY", + /** Above ground light rail. */ + TRAM = "TRAM", + /** Monorail. */ + MONORAIL = "MONORAIL", + /** Heavy rail. */ + HEAVY_RAIL = "HEAVY_RAIL", + /** Commuter rail. */ + COMMUTER_TRAIN = "COMMUTER_TRAIN", + /** High speed train. */ + HIGH_SPEED_TRAIN = "HIGH_SPEED_TRAIN", + /** Bus. */ + BUS = "BUS", + /** Intercity bus. */ + INTERCITY_BUS = "INTERCITY_BUS", + /** Trolleybus. */ + TROLLEYBUS = "TROLLEYBUS", + /** Share taxi is a kind of bus with the ability to drop off and pick up passengers anywhere on its route. */ + SHARE_TAXI = "SHARE_TAXI", + /** Ferry. */ + FERRY = "FERRY", + /** A vehicle that operates on a cable, usually on the ground. Aerial cable cars may be of the type `GONDOLA_LIFT`. */ + CABLE_CAR = "CABLE_CAR", + /** An aerial cable car. */ + GONDOLA_LIFT = "GONDOLA_LIFT", + /** + * A vehicle that is pulled up a steep incline by a cable. + * A Funicular typically consists of two cars, with each car acting as a counterweight for the other. + */ + FUNICULAR = "FUNICULAR", + /** All other vehicles will return this type. */ + OTHER = "OTHER" +} +/** + * When the Distance Matrix API returns results, it places them within a JSON `rows` array. + * Even if no results are returned (such as when the origins and/or destinations don't exist), it still returns an empty array. + * XML responses consist of zero or more `` elements. + * + * Rows are ordered according to the values in the `origin` parameter of the request. + * Each row corresponds to an origin, and each `element` within that row corresponds to a pairing of the origin with a `destination` value. + * + * Each `row` array contains one or more `element` entries, which in turn contain the information about a single origin-destination pairing. + */ +export interface DistanceMatrixRow { + elements: DistanceMatrixRowElement[]; +} +/** The information about each origin-destination pairing is returned in an `element` entry. */ +export interface DistanceMatrixRowElement { + /** possible status codes */ + status: Status; + /** + * The length of time it takes to travel this route, expressed in seconds (the `value` field) and as `text`. + * The textual representation is localized according to the query's `language` parameter. + */ + duration: Duration; + /** + * The length of time it takes to travel this route, based on current and historical traffic conditions. + * See the `traffic_model` request parameter for the options you can use to request that the returned value is + * `optimistic`, `pessimistic`, or a `best-guess` estimate. The duration is expressed in seconds (the `value` field) and as `text`. + * The textual representation is localized according to the query's `language` parameter. + * The duration in traffic is returned only if all of the following are true: + * - The request includes a `departure_time` parameter. + * - The request includes a valid API key, or a valid Google Maps APIs Premium Plan client ID and signature. + * - Traffic conditions are available for the requested route. + * - The `mode` parameter is set to `driving`. + */ + duration_in_traffic: Duration; + /** + * The total distance of this route, expressed in meters (`value`) and as `text`. + * The textual value uses the `unit` system specified with the unit parameter of the original request, or the origin's region. + */ + distance: Distance; + /** + * If present, contains the total fare (that is, the total ticket costs) on this route. + * This property is only returned for transit requests and only for transit providers where fare information is available. + */ + fare: TransitFare; +} +export interface OpeningHours { + /** is a boolean value indicating if the place is open at the current time. */ + open_now: boolean; + /** is an array of opening periods covering seven days, starting from Sunday, in chronological order. */ + periods: OpeningPeriod[]; + /** + * is an array of seven strings representing the formatted opening hours for each day of the week. + * If a `language` parameter was specified in the Place Details request, the Places Service will format + * and localize the opening hours appropriately for that language. The ordering of the elements in this array + * depends on the `language` parameter. Some languages start the week on Monday while others start on Sunday. + */ + weekday_text: string[]; +} +export interface OpeningPeriod { + /** contains a pair of day and time objects describing when the place opens. */ + open: OpeningHoursTime; + /** + * may contain a pair of day and time objects describing when the place closes. + * **Note:** If a place is **always open**, the `close` section will be missing from the response. + * Clients can rely on always-open being represented as an `open` period containing `day` with value 0 + * and `time` with value 0000, and no `close`. + */ + close?: OpeningHoursTime; +} +export interface OpeningHoursTime { + /** a number from 0–6, corresponding to the days of the week, starting on Sunday. For example, 2 means Tuesday. */ + day: number; + /** + * may contain a time of day in 24-hour hhmm format. Values are in the range 0000–2359. The `time` + * will be reported in the place's time zone. + */ + time?: string; +} +export interface GeocodeResult { + /** + * array indicates the type of the returned result. + * This array contains a set of zero or more tags identifying the type of feature returned in the result. + * For example, a geocode of "Chicago" returns "locality" which indicates that "Chicago" is a city, + * and also returns "political" which indicates it is a political entity. + */ + types: AddressType[]; + /** + * is a string containing the human-readable address of this location. + * + * Often this address is equivalent to the postal address. Note that some countries, such as the United Kingdom, + * do not allow distribution of true postal addresses due to licensing restrictions. + * + * The formatted address is logically composed of one or more address components. + * For example, the address "111 8th Avenue, New York, NY" consists of the following components: "111" (the street number), + * "8th Avenue" (the route), "New York" (the city) and "NY" (the US state). + * + * Do not parse the formatted address programmatically. Instead you should use the individual address components, + * which the API response includes in addition to the formatted address field. + */ + formatted_address: string; + /** + * is an array containing the separate components applicable to this address. + * + * Note the following facts about the `address_components[]` array: + * - The array of address components may contain more components than the `formatted_address`. + * - The array does not necessarily include all the political entities that contain an address, + * apart from those included in the `formatted_address`. To retrieve all the political entities that contain a specific address, + * you should use reverse geocoding, passing the latitude/longitude of the address as a parameter to the request. + * - The format of the response is not guaranteed to remain the same between requests. + * In particular, the number of `address_components` varies based on the address requested and can change + * over time for the same address. A component can change position in the array. + * The type of the component can change. A particular component may be missing in a later response. + */ + address_components: AddressComponent[]; + /** + * is an array denoting all the localities contained in a postal code. + * This is only present when the result is a postal code that contains multiple localities. + */ + postcode_localities: string[]; + /** address geometry. */ + geometry: AddressGeometry; + /** + * is an encoded location reference, derived from latitude and longitude coordinates, + * that represents an area: 1/8000th of a degree by 1/8000th of a degree (about 14m x 14m at the equator) or smaller. + * Plus codes can be used as a replacement for street addresses in places where they do not exist + * (where buildings are not numbered or streets are not named). + * + * The plus code is formatted as a global code and a compound code: + * - `global_code` is a 4 character area code and 6 character or longer local code (849VCWC8+R9). + * - `compound_code` is a 6 character or longer local code with an explicit location (CWC8+R9, Mountain View, CA, USA). + * Typically, both the global code and compound code are returned. However, if the result is in a remote location + * (for example, an ocean or desert) only the global code may be returned. + * + * @see [Open Location Code](https://en.wikipedia.org/wiki/Open_Location_Code) + * @see [plus codes](https://plus.codes/) + */ + plus_code: PlusCode; + /** + * indicates that the geocoder did not return an exact match for the original request, + * though it was able to match part of the requested address. + * You may wish to examine the original request for misspellings and/or an incomplete address. + * + * Partial matches most often occur for street addresses that do not exist within the locality you pass in the request. + * Partial matches may also be returned when a request matches two or more locations in the same locality. + * For example, "21 Henr St, Bristol, UK" will return a partial match for both Henry Street and Henrietta Street. + * Note that if a request includes a misspelled address component, the geocoding service may suggest an alternative address. + * Suggestions triggered in this way will also be marked as a partial match. + */ + partial_match: boolean; + /** is a unique identifier that can be used with other Google APIs. */ + place_id: string; +} +export declare enum GeocodingAddressComponentType { + /** indicates the floor of a building address. */ + floor = "floor", + /** typically indicates a place that has not yet been categorized. */ + establishment = "establishment", + /** indicates a named point of interest. */ + point_of_interest = "point_of_interest", + /** indicates a parking lot or parking structure. */ + parking = "parking", + /** indicates a specific postal box. */ + post_box = "post_box", + /** indicates a grouping of geographic areas, such as locality and sublocality, used for mailing addresses in some countries. */ + postal_town = "postal_town", + /** indicates the room of a building address. */ + room = "room", + /** indicates the precise street number. */ + street_number = "street_number", + /** indicate the location of a bus. */ + bus_station = "bus_station", + /** indicate the location of a train. */ + train_station = "train_station", + /** indicate the location of a public transit stop. */ + transit_station = "transit_station" +} +export interface AddressComponent { + /** is an array indicating the *type* of the address component. */ + types: Array; + /** is the full text description or name of the address component as returned by the Geocoder. */ + long_name: string; + /** + * is an abbreviated textual name for the address component, if available. + * For example, an address component for the state of Alaska may have a `long_name` of "Alaska" and a `short_name` of "AK" + * using the 2-letter postal abbreviation. + */ + short_name: string; +} +export interface AddressGeometry { + /** contains the geocoded latitude, longitude value. For normal address lookups, this field is typically the most important. */ + location: LatLngLiteral; + /** stores additional data about the specified location. */ + location_type?: LocationType; + /** + * contains the recommended viewport for displaying the returned result, specified as two latitude, longitude values + * defining the `southwest` and `northeast` corner of the viewport bounding box. + * Generally the viewport is used to frame a result when displaying it to a user. + */ + viewport: LatLngBounds; + /** + * (optionally returned) stores the bounding box which can fully contain the returned result. + * Note that these bounds may not match the recommended viewport. + * (For example, San Francisco includes the [Farallon islands](https://en.wikipedia.org/wiki/Farallon_Islands), + * which are technically part of the city, but probably should not be returned in the viewport.) + */ + bounds?: LatLngBounds; +} +export declare enum LocationType { + /** + * indicates that the returned result is a precise geocode for which we have location information + * accurate down to street address precision + */ + ROOFTOP = "ROOFTOP", + /** + * indicates that the returned result reflects an approximation (usually on a road) interpolated between two precise points + * (such as intersections). Interpolated results are generally returned when rooftop geocodes are unavailable for a street address. + */ + RANGE_INTERPOLATED = "RANGE_INTERPOLATED", + /** + * indicates that the returned result is the geometric center of a result such as a polyline + * (for example, a street) or polygon (region). + */ + GEOMETRIC_CENTER = "GEOMETRIC_CENTER", + /** indicates that the returned result is approximate. */ + APPROXIMATE = "APPROXIMATE" +} +export interface PlaceEditorialSummary { + /** The language of the previous fields. May not always be present. */ + language?: string; + /** A medium-length textual summary of the place. */ + overview?: string; +} +export interface PlusCode { + /** is a 4 character area code and 6 character or longer local code (849VCWC8+R9). */ + global_code: string; + /** is a 6 character or longer local code with an explicit location (CWC8+R9, Mountain View, CA, USA). */ + compound_code: string; +} +export declare enum RadioType { + lte = "lte", + gsm = "gsm", + cdma = "cdma", + wcdma = "wcdma" +} +export interface CellTower { + /** + * Unique identifier of the cell. + * On GSM, this is the Cell ID (CID); + * CDMA networks use the Base Station ID (BID). + * WCDMA networks use the UTRAN/GERAN Cell Identity (UC-Id), which is a 32-bit value concatenating the Radio Network Controller (RNC) + * and Cell ID. Specifying only the 16-bit Cell ID value in WCDMA networks may return inaccurate results. + */ + cellId: number; + /** The Location Area Code (LAC) for GSM and WCDMA networks. The Network ID (NID) for CDMA networks. */ + locationAreaCode: number; + /** The cell tower's Mobile Country Code (MCC). */ + mobileCountryCode: number; + /** The cell tower's Mobile Network Code. This is the MNC for GSM and WCDMA; CDMA uses the System ID (SID). */ + mobileNetworkCode: number; + /** The number of milliseconds since this cell was primary. If age is 0, the `cellId` represents a current measurement. */ + age?: number; + /** Radio signal strength measured in dBm. */ + signalStrength?: number; + /** The [timing advance](https://en.wikipedia.org/wiki/Timing_advance) value. */ + timingAdvance?: number; +} +export interface WifiAccessPoint { + /** The MAC address of the WiFi node. It's typically called a BSS, BSSID or MAC address. Separators must be `:` (colon). */ + macAddress: string; + /** The current signal strength measured in dBm. */ + signalStrength?: number; + /** The number of milliseconds since this access point was detected. */ + age?: number; + /** The channel over which the client is communicating with the acces. */ + channel?: number; + /** The current signal to noise ratio measured in dB. */ + signalToNoiseRatio?: number; +} +export interface PredictionTerm { + /** containing the text of the term. */ + value: string; + /** start position of this term in the description, measured in Unicode characters. */ + offset: number; +} +export interface PredictionSubstring { + /** location of the entered term. */ + offset: number; + /** length of the entered term. */ + length: number; +} +export interface StructuredFormatting { + /** contains the main text of a prediction, usually the name of the place. */ + main_text: string; + /** + * contains an array with `offset` value and `length`. These describe the location of + * the entered term in the prediction result text, so that the term can be highlighted if desired. + */ + main_text_matched_substrings: PredictionSubstring[]; + /** contains the secondary text of a prediction, usually the location of the place. */ + secondary_text: string; + /** + * contains an array with `offset` value and `length`. These describe the location of + * the entered term in the prediction result secondary text, so that the term can be highlighted if desired. + */ + secondary_text_matched_substrings: PredictionSubstring[]; +} +export interface SnappedPoint { + /** Contains a `latitude` and `longitude` value. */ + location: LatLngLiteralVerbose; + /** + * An integer that indicates the corresponding value in the original request. + * Each point in the request maps to at most two segmentsin the response: + * - If there are no nearby roads, no segment is returned. + * - If the nearest road is one-way, one segment is returned. + * - If the nearest road is bidirectional, two segments are returned. + */ + originalIndex: number; + /** + * A unique identifier for a place. All place IDs returned by the Roads API correspond to road segments. + * Place IDs can be used with other Google APIs, including the Places SDK and the Maps JavaScript API. + * For example, if you need to get road names for the snapped points returned by the Roads API, + * you can pass the `placeId` to the Places SDK or the Geocoding API. Within the Roads API, + * you can pass the `placeId` in a speed limits request to determine the speed limit along that road segment. + */ + placeId: string; +} diff --git a/dist/common.js b/dist/common.js new file mode 100644 index 0000000000..879a0029cf --- /dev/null +++ b/dist/common.js @@ -0,0 +1,716 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.RadioType = exports.LocationType = exports.GeocodingAddressComponentType = exports.VehicleType = exports.Maneuver = exports.AddressType = exports.GeocodedWaypointStatus = exports.DirectionsReponseStatus = exports.DirectionsResponseStatus = exports.TransitRoutingPreference = exports.TransitMode = exports.TrafficModel = exports.UnitSystem = exports.TravelRestriction = exports.TravelMode = exports.Language = exports.AspectRatingType = exports.PlaceType2 = exports.PlaceType1 = exports.PlaceInputType = exports.PlaceIdScope = exports.Status = void 0; +var Status; +(function (Status) { + /** indicates the response contains a valid result. */ + Status["OK"] = "OK"; + /** indicates that the provided request was invalid. */ + Status["INVALID_REQUEST"] = "INVALID_REQUEST"; + /** + * indicates that too many `waypoints` were provided in the request. For applications using the Directions API as a web service, + * or the [directions service in the Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/directions), + * the maximum allowed number of `waypoints` is 23, plus the origin and destination. + */ + Status["MAX_WAYPOINTS_EXCEEDED"] = "MAX_WAYPOINTS_EXCEEDED"; + /** + * indicates the requested route is too long and cannot be processed. + * This error occurs when more complex directions are returned. + * Try reducing the number of waypoints, turns, or instructions. + */ + Status["MAX_ROUTE_LENGTH_EXCEEDED"] = "MAX_ROUTE_LENGTH_EXCEEDED"; + /** + * indicates any of the following: + * - The API key is missing or invalid. + * - Billing has not been enabled on your account. + * - A self-imposed usage cap has been exceeded. + * - The provided method of payment is no longer valid (for example, a credit card has expired). + * See the [Maps FAQ](https://developers.google.com/maps/faq#over-limit-key-error) to learn how to fix this. + */ + Status["OVER_DAILY_LIMIT"] = "OVER_DAILY_LIMIT"; + /** indicates the service has received too many requests from your application within the allowed time period. */ + Status["OVER_QUERY_LIMIT"] = "OVER_QUERY_LIMIT"; + /** indicates that the service denied use of the Distance Matrix service by your application. */ + Status["REQUEST_DENIED"] = "REQUEST_DENIED"; + /** indicates a Distance Matrix request could not be processed due to a server error. The request may succeed if you try again. */ + Status["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; + /** indicates that the request was successful but returned no results. */ + Status["ZERO_RESULTS"] = "ZERO_RESULTS"; + /** indicates that the referenced location (place_id) was not found in the Places database. */ + Status["NOT_FOUND"] = "NOT_FOUND"; +})(Status || (exports.Status = Status = {})); +var PlaceIdScope; +(function (PlaceIdScope) { + /** + * The place ID is recognised by your application only. + * This is because your application added the place, and the place has not yet passed the moderation process. + */ + PlaceIdScope["APP"] = "APP"; + /** The place ID is available to other applications and on Google Maps. */ + PlaceIdScope["GOOGLE"] = "GOOGLE"; +})(PlaceIdScope || (exports.PlaceIdScope = PlaceIdScope = {})); +var PlaceInputType; +(function (PlaceInputType) { + PlaceInputType["textQuery"] = "textquery"; + PlaceInputType["phoneNumber"] = "phonenumber"; +})(PlaceInputType || (exports.PlaceInputType = PlaceInputType = {})); +/** + * Table 1: Types supported in place search and addition + * + * You can use the following values in the types filter for place searches and when adding a place. + * + * @see https://developers.google.com/places/web-service/supported_types#table1 + */ +var PlaceType1; +(function (PlaceType1) { + PlaceType1["accounting"] = "accounting"; + /** indicates an airport. */ + PlaceType1["airport"] = "airport"; + PlaceType1["amusement_park"] = "amusement_park"; + PlaceType1["aquarium"] = "aquarium"; + PlaceType1["art_gallery"] = "art_gallery"; + PlaceType1["atm"] = "atm"; + PlaceType1["bakery"] = "bakery"; + PlaceType1["bank"] = "bank"; + PlaceType1["bar"] = "bar"; + PlaceType1["beauty_salon"] = "beauty_salon"; + PlaceType1["bicycle_store"] = "bicycle_store"; + PlaceType1["book_store"] = "book_store"; + PlaceType1["bowling_alley"] = "bowling_alley"; + PlaceType1["bus_station"] = "bus_station"; + PlaceType1["cafe"] = "cafe"; + PlaceType1["campground"] = "campground"; + PlaceType1["car_dealer"] = "car_dealer"; + PlaceType1["car_rental"] = "car_rental"; + PlaceType1["car_repair"] = "car_repair"; + PlaceType1["car_wash"] = "car_wash"; + PlaceType1["casino"] = "casino"; + PlaceType1["cemetery"] = "cemetery"; + PlaceType1["church"] = "church"; + PlaceType1["city_hall"] = "city_hall"; + PlaceType1["clothing_store"] = "clothing_store"; + PlaceType1["convenience_store"] = "convenience_store"; + PlaceType1["courthouse"] = "courthouse"; + PlaceType1["dentist"] = "dentist"; + PlaceType1["department_store"] = "department_store"; + PlaceType1["doctor"] = "doctor"; + PlaceType1["drugstore"] = "drugstore"; + PlaceType1["electrician"] = "electrician"; + PlaceType1["electronics_store"] = "electronics_store"; + PlaceType1["embassy"] = "embassy"; + PlaceType1["fire_station"] = "fire_station"; + PlaceType1["florist"] = "florist"; + PlaceType1["funeral_home"] = "funeral_home"; + PlaceType1["furniture_store"] = "furniture_store"; + PlaceType1["gas_station"] = "gas_station"; + PlaceType1["gym"] = "gym"; + PlaceType1["hair_care"] = "hair_care"; + PlaceType1["hardware_store"] = "hardware_store"; + PlaceType1["hindu_temple"] = "hindu_temple"; + PlaceType1["home_goods_store"] = "home_goods_store"; + PlaceType1["hospital"] = "hospital"; + PlaceType1["insurance_agency"] = "insurance_agency"; + PlaceType1["jewelry_store"] = "jewelry_store"; + PlaceType1["laundry"] = "laundry"; + PlaceType1["lawyer"] = "lawyer"; + PlaceType1["library"] = "library"; + PlaceType1["light_rail_station"] = "light_rail_station"; + PlaceType1["liquor_store"] = "liquor_store"; + PlaceType1["local_government_office"] = "local_government_office"; + PlaceType1["locksmith"] = "locksmith"; + PlaceType1["lodging"] = "lodging"; + PlaceType1["meal_delivery"] = "meal_delivery"; + PlaceType1["meal_takeaway"] = "meal_takeaway"; + PlaceType1["mosque"] = "mosque"; + PlaceType1["movie_rental"] = "movie_rental"; + PlaceType1["movie_theater"] = "movie_theater"; + PlaceType1["moving_company"] = "moving_company"; + PlaceType1["museum"] = "museum"; + PlaceType1["night_club"] = "night_club"; + PlaceType1["painter"] = "painter"; + /** indicates a named park. */ + PlaceType1["park"] = "park"; + PlaceType1["parking"] = "parking"; + PlaceType1["pet_store"] = "pet_store"; + PlaceType1["pharmacy"] = "pharmacy"; + PlaceType1["physiotherapist"] = "physiotherapist"; + PlaceType1["plumber"] = "plumber"; + PlaceType1["police"] = "police"; + PlaceType1["post_office"] = "post_office"; + PlaceType1["real_estate_agency"] = "real_estate_agency"; + PlaceType1["restaurant"] = "restaurant"; + PlaceType1["roofing_contractor"] = "roofing_contractor"; + PlaceType1["rv_park"] = "rv_park"; + PlaceType1["school"] = "school"; + PlaceType1["secondary_school"] = "secondary_school"; + PlaceType1["shoe_store"] = "shoe_store"; + PlaceType1["shopping_mall"] = "shopping_mall"; + PlaceType1["spa"] = "spa"; + PlaceType1["stadium"] = "stadium"; + PlaceType1["storage"] = "storage"; + PlaceType1["store"] = "store"; + PlaceType1["subway_station"] = "subway_station"; + PlaceType1["supermarket"] = "supermarket"; + PlaceType1["synagogue"] = "synagogue"; + PlaceType1["taxi_stand"] = "taxi_stand"; + PlaceType1["tourist_attraction"] = "tourist_attraction"; + PlaceType1["train_station"] = "train_station"; + PlaceType1["transit_station"] = "transit_station"; + PlaceType1["travel_agency"] = "travel_agency"; + PlaceType1["university"] = "university"; + PlaceType1["veterinary_care"] = "veterinary_care"; + PlaceType1["zoo"] = "zoo"; +})(PlaceType1 || (exports.PlaceType1 = PlaceType1 = {})); +/** + * Table 2: Additional types returned by the Places service + * + * The following types may be returned in the results of a place search, in addition to the types in table 1 above. + * For more details on these types, refer to [Address Types](https://developers.google.com/maps/documentation/geocoding/intro#Types) + * in Geocoding Responses. + * + * @see https://developers.google.com/places/web-service/supported_types#table2 + */ +var PlaceType2; +(function (PlaceType2) { + /** + * indicates a first-order civil entity below the country level. Within the United States, these administrative levels are states. + * Not all nations exhibit these administrative levels. In most cases, `administrative_area_level_1` short names will closely match + * ISO 3166-2 subdivisions and other widely circulated lists; however this is not guaranteed as our geocoding results are based + * on a variety of signals and location data. + */ + PlaceType2["administrative_area_level_1"] = "administrative_area_level_1"; + /** + * indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. + * Not all nations exhibit these administrative levels. + */ + PlaceType2["administrative_area_level_2"] = "administrative_area_level_2"; + /** + * indicates a third-order civil entity below the country level. This type indicates a minor civil division. + * Not all nations exhibit these administrative levels. + */ + PlaceType2["administrative_area_level_3"] = "administrative_area_level_3"; + /** + * indicates a fourth-order civil entity below the country level. This type indicates a minor civil division. + * Not all nations exhibit these administrative levels. + */ + PlaceType2["administrative_area_level_4"] = "administrative_area_level_4"; + /** + * indicates a fifth-order civil entity below the country level. This type indicates a minor civil division. + * Not all nations exhibit these administrative levels. + */ + PlaceType2["administrative_area_level_5"] = "administrative_area_level_5"; + PlaceType2["archipelago"] = "archipelago"; + /** indicates a commonly-used alternative name for the entity. */ + PlaceType2["colloquial_area"] = "colloquial_area"; + PlaceType2["continent"] = "continent"; + /** indicates the national political entity, and is typically the highest order type returned by the Geocoder. */ + PlaceType2["country"] = "country"; + PlaceType2["establishment"] = "establishment"; + PlaceType2["finance"] = "finance"; + PlaceType2["floor"] = "floor"; + PlaceType2["food"] = "food"; + PlaceType2["general_contractor"] = "general_contractor"; + PlaceType2["geocode"] = "geocode"; + PlaceType2["health"] = "health"; + /** indicates a major intersection, usually of two major roads. */ + PlaceType2["intersection"] = "intersection"; + PlaceType2["landmark"] = "landmark"; + /** indicates an incorporated city or town political entity. */ + PlaceType2["locality"] = "locality"; + /** indicates a prominent natural feature. */ + PlaceType2["natural_feature"] = "natural_feature"; + /** indicates a named neighborhood */ + PlaceType2["neighborhood"] = "neighborhood"; + PlaceType2["place_of_worship"] = "place_of_worship"; + PlaceType2["plus_code"] = "plus_code"; + PlaceType2["point_of_interest"] = "point_of_interest"; + /** indicates a political entity. Usually, this type indicates a polygon of some civil administration. */ + PlaceType2["political"] = "political"; + PlaceType2["post_box"] = "post_box"; + /** indicates a postal code as used to address postal mail within the country. */ + PlaceType2["postal_code"] = "postal_code"; + PlaceType2["postal_code_prefix"] = "postal_code_prefix"; + PlaceType2["postal_code_suffix"] = "postal_code_suffix"; + PlaceType2["postal_town"] = "postal_town"; + /** indicates a named location, usually a building or collection of buildings with a common name */ + PlaceType2["premise"] = "premise"; + PlaceType2["room"] = "room"; + /** indicates a named route (such as "US 101"). */ + PlaceType2["route"] = "route"; + PlaceType2["street_address"] = "street_address"; + PlaceType2["street_number"] = "street_number"; + /** + * indicates a first-order civil entity below a locality. For some locations may receive one of the additional types: + * `sublocality_level_1` to `sublocality_level_5`. Each sublocality level is a civil entity. Larger numbers indicate a smaller + * geographic area. + */ + PlaceType2["sublocality"] = "sublocality"; + PlaceType2["sublocality_level_1"] = "sublocality_level_1"; + PlaceType2["sublocality_level_2"] = "sublocality_level_2"; + PlaceType2["sublocality_level_3"] = "sublocality_level_3"; + PlaceType2["sublocality_level_4"] = "sublocality_level_4"; + PlaceType2["sublocality_level_5"] = "sublocality_level_5"; + /** + * indicates a first-order entity below a named location, usually a singular building within a collection of buildings with a + * common name. + */ + PlaceType2["subpremise"] = "subpremise"; + PlaceType2["town_square"] = "town_square"; +})(PlaceType2 || (exports.PlaceType2 = PlaceType2 = {})); +var AspectRatingType; +(function (AspectRatingType) { + AspectRatingType["appeal"] = "appeal"; + AspectRatingType["atmosphere"] = "atmosphere"; + AspectRatingType["decor"] = "decor"; + AspectRatingType["facilities"] = "facilities"; + AspectRatingType["food"] = "food"; + AspectRatingType["overall"] = "overall"; + AspectRatingType["quality"] = "quality"; + AspectRatingType["service"] = "service"; +})(AspectRatingType || (exports.AspectRatingType = AspectRatingType = {})); +/** + * By default the API will attempt to load the most appropriate language based on the users location or browser settings. + * Some APIs allow you to explicitly set a language when you make a request + * + * @see https://developers.google.com/maps/faq#languagesupport + */ +var Language; +(function (Language) { + /** Arabic */ + Language["ar"] = "ar"; + /** Belarusian */ + Language["be"] = "be"; + /** Bulgarian */ + Language["bg"] = "bg"; + /** Bengali */ + Language["bn"] = "bn"; + /** Catalan */ + Language["ca"] = "ca"; + /** Czech */ + Language["cs"] = "cs"; + /** Danish */ + Language["da"] = "da"; + /** German */ + Language["de"] = "de"; + /** Greek */ + Language["el"] = "el"; + /** English */ + Language["en"] = "en"; + /** English (Australian) */ + Language["en_Au"] = "en-Au"; + /** English (Great Britain) */ + Language["en_GB"] = "en-GB"; + /** Spanish */ + Language["es"] = "es"; + /** Basque */ + Language["eu"] = "eu"; + /** Farsi */ + Language["fa"] = "fa"; + /** Finnish */ + Language["fi"] = "fi"; + /** Filipino */ + Language["fil"] = "fil"; + /** French */ + Language["fr"] = "fr"; + /** Galician */ + Language["gl"] = "gl"; + /** Gujarati */ + Language["gu"] = "gu"; + /** Hindi */ + Language["hi"] = "hi"; + /** Croatian */ + Language["hr"] = "hr"; + /** Hungarian */ + Language["hu"] = "hu"; + /** Indonesian */ + Language["id"] = "id"; + /** Italian */ + Language["it"] = "it"; + /** Hebrew */ + Language["iw"] = "iw"; + /** Japanese */ + Language["ja"] = "ja"; + /** Kazakh */ + Language["kk"] = "kk"; + /** Kannada */ + Language["kn"] = "kn"; + /** Korean */ + Language["ko"] = "ko"; + /** Kyrgyz */ + Language["ky"] = "ky"; + /** Lithuanian */ + Language["lt"] = "lt"; + /** Latvian */ + Language["lv"] = "lv"; + /** Macedonian */ + Language["mk"] = "mk"; + /** Malayalam */ + Language["ml"] = "ml"; + /** Marathi */ + Language["mr"] = "mr"; + /** Burmese */ + Language["my"] = "my"; + /** Dutch */ + Language["nl"] = "nl"; + /** Norwegian */ + Language["no"] = "no"; + /** Punjabi */ + Language["pa"] = "pa"; + /** Polish */ + Language["pl"] = "pl"; + /** Portuguese */ + Language["pt"] = "pt"; + /** Portuguese (Brazil) */ + Language["pt_BR"] = "pt-BR"; + /** Portuguese (Portugal) */ + Language["pt_PT"] = "pt-PT"; + /** Romanian */ + Language["ro"] = "ro"; + /** Russian */ + Language["ru"] = "ru"; + /** Slovak */ + Language["sk"] = "sk"; + /** Slovenian */ + Language["sl"] = "sl"; + /** Albanian */ + Language["sq"] = "sq"; + /** Serbian */ + Language["sr"] = "sr"; + /** Swedish */ + Language["sv"] = "sv"; + /** Tamil */ + Language["ta"] = "ta"; + /** Telugu */ + Language["te"] = "te"; + /** Thai */ + Language["th"] = "th"; + /** Tagalog */ + Language["tl"] = "tl"; + /** Turkish */ + Language["tr"] = "tr"; + /** Ukrainian */ + Language["uk"] = "uk"; + /** Uzbek */ + Language["uz"] = "uz"; + /** Vietnamese */ + Language["vi"] = "vi"; + /** Chinese (Simlified) */ + Language["zh_CN"] = "zh-CN"; + /** Chinese (Traditional) */ + Language["zh_TW"] = "zh-TW"; +})(Language || (exports.Language = Language = {})); +/** + * When you calculate directions, you may specify the transportation mode to use. + * By default, directions are calculated as `driving` directions. + * + * **Note:** Both walking and bicycling directions may sometimes not include clear pedestrian or bicycling paths, + * so these directions will return warnings in the returned result which you must display to the user. + */ +var TravelMode; +(function (TravelMode) { + /** (default) indicates standard driving directions using the road network. */ + TravelMode["driving"] = "driving"; + /** requests walking directions via pedestrian paths & sidewalks (where available). */ + TravelMode["walking"] = "walking"; + /** requests bicycling directions via bicycle paths & preferred streets (where available). */ + TravelMode["bicycling"] = "bicycling"; + /** + * requests directions via public transit routes (where available). + * If you set the mode to transit, you can optionally specify either a departure_time or an arrival_time. + * If neither time is specified, the departure_time defaults to now (that is, the departure time defaults to the current time). + * You can also optionally include a transit_mode and/or a transit_routing_preference. + */ + TravelMode["transit"] = "transit"; +})(TravelMode || (exports.TravelMode = TravelMode = {})); +var TravelRestriction; +(function (TravelRestriction) { + /** indicates that the calculated route should avoid toll roads/bridges. */ + TravelRestriction["tolls"] = "tolls"; + /** indicates that the calculated route should avoid highways. */ + TravelRestriction["highways"] = "highways"; + /** indicates that the calculated route should avoid ferries. */ + TravelRestriction["ferries"] = "ferries"; + /** + * indicates that the calculated route should avoid indoor steps for walking and transit directions. + * Only requests that include an API key or a Google Maps APIs Premium Plan client ID will receive indoor steps by default. + */ + TravelRestriction["indoor"] = "indoor"; +})(TravelRestriction || (exports.TravelRestriction = TravelRestriction = {})); +/** + * Directions results contain text within distance fields that may be displayed to the user to indicate the distance of + * a particular "step" of the route. By default, this text uses the unit system of the origin's country or region. + */ +var UnitSystem; +(function (UnitSystem) { + /** specifies usage of the metric system. Textual distances are returned using kilometers and meters. */ + UnitSystem["metric"] = "metric"; + /** specifies usage of the Imperial (English) system. Textual distances are returned using miles and feet. */ + UnitSystem["imperial"] = "imperial"; +})(UnitSystem || (exports.UnitSystem = UnitSystem = {})); +var TrafficModel; +(function (TrafficModel) { + /** + * indicates that the returned `duration_in_traffic` should be the best estimate of travel time given what is known about + * both historical traffic conditions and live traffic. Live traffic becomes more important the closer the `departure_time` is to now. + */ + TrafficModel["best_guess"] = "best_guess"; + /** + * indicates that the returned `duration_in_traffic` should be longer than the actual travel time on most days, + * though occasional days with particularly bad traffic conditions may exceed this value. + */ + TrafficModel["pessimistic"] = "pessimistic"; + /** + * indicates that the returned `duration_in_traffic` should be shorter than the actual travel time on most days, + * though occasional days with particularly good traffic conditions may be faster than this value. + */ + TrafficModel["optimistic"] = "optimistic"; +})(TrafficModel || (exports.TrafficModel = TrafficModel = {})); +var TransitMode; +(function (TransitMode) { + /** indicates that the calculated route should prefer travel by bus. */ + TransitMode["bus"] = "bus"; + /** indicates that the calculated route should prefer travel by subway. */ + TransitMode["subway"] = "subway"; + /** indicates that the calculated route should prefer travel by train. */ + TransitMode["train"] = "train"; + /** indicates that the calculated route should prefer travel by tram and light rail. */ + TransitMode["tram"] = "tram"; + /** + * indicates that the calculated route should prefer travel by train, tram, light rail, and subway. + * This is equivalent to `transit_mode=train|tram|subway` + */ + TransitMode["rail"] = "rail"; +})(TransitMode || (exports.TransitMode = TransitMode = {})); +var TransitRoutingPreference; +(function (TransitRoutingPreference) { + /** indicates that the calculated route should prefer limited amounts of walking. */ + TransitRoutingPreference["less_walking"] = "less_walking"; + /** indicates that the calculated route should prefer a limited number of transfers. */ + TransitRoutingPreference["fewer_transfers"] = "fewer_transfers"; +})(TransitRoutingPreference || (exports.TransitRoutingPreference = TransitRoutingPreference = {})); +/** + * The `status` field within the Directions response object contains the status of the request, and may contain debugging information + * to help you track down why the Directions service failed. + */ +var DirectionsResponseStatus; +(function (DirectionsResponseStatus) { + /** indicates the response contains a valid `result`. */ + DirectionsResponseStatus["OK"] = "OK"; + /** indicates at least one of the locations specified in the request's origin, destination, or waypoints could not be geocoded. */ + DirectionsResponseStatus["NOT_FOUND"] = "NOT_FOUND"; + /** indicates no route could be found between the origin and destination. */ + DirectionsResponseStatus["ZERO_RESULTS"] = "ZERO_RESULTS"; + /** + * indicates that too many `waypoints` were provided in the request. For applications using the Directions API as a web service, + * or the [directions service in the Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/directions), + * the maximum allowed number of `waypoints` is 23, plus the origin and destination. + */ + DirectionsResponseStatus["MAX_WAYPOINTS_EXCEEDED"] = "MAX_WAYPOINTS_EXCEEDED"; + /** + * indicates the requested route is too long and cannot be processed. + * This error occurs when more complex directions are returned. + * Try reducing the number of waypoints, turns, or instructions. + */ + DirectionsResponseStatus["MAX_ROUTE_LENGTH_EXCEEDED"] = "MAX_ROUTE_LENGTH_EXCEEDED"; + /** indicates that the provided request was invalid. Common causes of this status include an invalid parameter or parameter value. */ + DirectionsResponseStatus["INVALID_REQUEST"] = "INVALID_REQUEST"; + /** + * indicates any of the following: + * - The API key is missing or invalid. + * - Billing has not been enabled on your account. + * - A self-imposed usage cap has been exceeded. + * - The provided method of payment is no longer valid (for example, a credit card has expired). + * See the [Maps FAQ](https://developers.google.com/maps/faq#over-limit-key-error) to learn how to fix this. + */ + DirectionsResponseStatus["OVER_DAILY_LIMIT"] = "OVER_DAILY_LIMIT"; + /** indicates the service has received too many requests from your application within the allowed time period. */ + DirectionsResponseStatus["OVER_QUERY_LIMIT"] = "OVER_QUERY_LIMIT"; + /** indicates that the service denied use of the directions service by your application. */ + DirectionsResponseStatus["REQUEST_DENIED"] = "REQUEST_DENIED"; + /** indicates a directions request could not be processed due to a server error. The request may succeed if you try again. */ + DirectionsResponseStatus["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; +})(DirectionsResponseStatus || (exports.DirectionsResponseStatus = DirectionsResponseStatus = {})); +/** + * The `status` field within the Directions response object contains the status of the request, and may contain debugging information + * to help you track down why the Directions service failed. + * @deprecated + */ +var DirectionsReponseStatus; +(function (DirectionsReponseStatus) { + /** indicates the response contains a valid `result`. */ + DirectionsReponseStatus["OK"] = "OK"; + /** indicates at least one of the locations specified in the request's origin, destination, or waypoints could not be geocoded. */ + DirectionsReponseStatus["NOT_FOUND"] = "NOT_FOUND"; + /** indicates no route could be found between the origin and destination. */ + DirectionsReponseStatus["ZERO_RESULTS"] = "ZERO_RESULTS"; + /** + * indicates that too many `waypoints` were provided in the request. For applications using the Directions API as a web service, + * or the [directions service in the Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/directions), + * the maximum allowed number of `waypoints` is 23, plus the origin and destination. + */ + DirectionsReponseStatus["MAX_WAYPOINTS_EXCEEDED"] = "MAX_WAYPOINTS_EXCEEDED"; + /** + * indicates the requested route is too long and cannot be processed. + * This error occurs when more complex directions are returned. + * Try reducing the number of waypoints, turns, or instructions. + */ + DirectionsReponseStatus["MAX_ROUTE_LENGTH_EXCEEDED"] = "MAX_ROUTE_LENGTH_EXCEEDED"; + /** indicates that the provided request was invalid. Common causes of this status include an invalid parameter or parameter value. */ + DirectionsReponseStatus["INVALID_REQUEST"] = "INVALID_REQUEST"; + /** + * indicates any of the following: + * - The API key is missing or invalid. + * - Billing has not been enabled on your account. + * - A self-imposed usage cap has been exceeded. + * - The provided method of payment is no longer valid (for example, a credit card has expired). + * See the [Maps FAQ](https://developers.google.com/maps/faq#over-limit-key-error) to learn how to fix this. + */ + DirectionsReponseStatus["OVER_DAILY_LIMIT"] = "OVER_DAILY_LIMIT"; + /** indicates the service has received too many requests from your application within the allowed time period. */ + DirectionsReponseStatus["OVER_QUERY_LIMIT"] = "OVER_QUERY_LIMIT"; + /** indicates that the service denied use of the directions service by your application. */ + DirectionsReponseStatus["REQUEST_DENIED"] = "REQUEST_DENIED"; + /** indicates a directions request could not be processed due to a server error. The request may succeed if you try again. */ + DirectionsReponseStatus["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; +})(DirectionsReponseStatus || (exports.DirectionsReponseStatus = DirectionsReponseStatus = {})); +var GeocodedWaypointStatus; +(function (GeocodedWaypointStatus) { + /** indicates that no errors occurred; the address was successfully parsed and at least one geocode was returned. */ + GeocodedWaypointStatus["OK"] = "OK"; + /** + * indicates that the geocode was successful but returned no results. + * This may occur if the geocoder was passed a non-existent `address`. + */ + GeocodedWaypointStatus["ZERO_RESULTS"] = "ZERO_RESULTS"; +})(GeocodedWaypointStatus || (exports.GeocodedWaypointStatus = GeocodedWaypointStatus = {})); +exports.AddressType = Object.assign({}, PlaceType1, PlaceType2); +var Maneuver; +(function (Maneuver) { + Maneuver["turn_slight_left"] = "turn-slight-left"; + Maneuver["turn_sharp_left"] = "turn-sharp-left"; + Maneuver["uturn_left"] = "uturn-left"; + Maneuver["turn_left"] = "turn-left"; + Maneuver["turn_slight_right"] = "turn-slight-right"; + Maneuver["turn_sharp_right"] = "turn-sharp-right"; + Maneuver["uturn_right"] = "uturn-right"; + Maneuver["turn_right"] = "turn-right"; + Maneuver["straight"] = "straight"; + Maneuver["ramp_left"] = "ramp-left"; + Maneuver["ramp_right"] = "ramp-right"; + Maneuver["merge"] = "merge"; + Maneuver["fork_left"] = "fork-left"; + Maneuver["fork_right"] = "fork-right"; + Maneuver["ferry"] = "ferry"; + Maneuver["ferry_train"] = "ferry-train"; + Maneuver["roundabout_left"] = "roundabout-left"; + Maneuver["roundabout_right"] = "roundabout-right"; +})(Maneuver || (exports.Maneuver = Maneuver = {})); +/** @see https://developers.google.com/maps/documentation/directions/intro#VehicleType. */ +var VehicleType; +(function (VehicleType) { + /** Rail. */ + VehicleType["RAIL"] = "RAIL"; + /** Light rail transit. */ + VehicleType["METRO_RAIL"] = "METRO_RAIL"; + /** Underground light rail. */ + VehicleType["SUBWAY"] = "SUBWAY"; + /** Above ground light rail. */ + VehicleType["TRAM"] = "TRAM"; + /** Monorail. */ + VehicleType["MONORAIL"] = "MONORAIL"; + /** Heavy rail. */ + VehicleType["HEAVY_RAIL"] = "HEAVY_RAIL"; + /** Commuter rail. */ + VehicleType["COMMUTER_TRAIN"] = "COMMUTER_TRAIN"; + /** High speed train. */ + VehicleType["HIGH_SPEED_TRAIN"] = "HIGH_SPEED_TRAIN"; + /** Bus. */ + VehicleType["BUS"] = "BUS"; + /** Intercity bus. */ + VehicleType["INTERCITY_BUS"] = "INTERCITY_BUS"; + /** Trolleybus. */ + VehicleType["TROLLEYBUS"] = "TROLLEYBUS"; + /** Share taxi is a kind of bus with the ability to drop off and pick up passengers anywhere on its route. */ + VehicleType["SHARE_TAXI"] = "SHARE_TAXI"; + /** Ferry. */ + VehicleType["FERRY"] = "FERRY"; + /** A vehicle that operates on a cable, usually on the ground. Aerial cable cars may be of the type `GONDOLA_LIFT`. */ + VehicleType["CABLE_CAR"] = "CABLE_CAR"; + /** An aerial cable car. */ + VehicleType["GONDOLA_LIFT"] = "GONDOLA_LIFT"; + /** + * A vehicle that is pulled up a steep incline by a cable. + * A Funicular typically consists of two cars, with each car acting as a counterweight for the other. + */ + VehicleType["FUNICULAR"] = "FUNICULAR"; + /** All other vehicles will return this type. */ + VehicleType["OTHER"] = "OTHER"; +})(VehicleType || (exports.VehicleType = VehicleType = {})); +var GeocodingAddressComponentType; +(function (GeocodingAddressComponentType) { + /** indicates the floor of a building address. */ + GeocodingAddressComponentType["floor"] = "floor"; + /** typically indicates a place that has not yet been categorized. */ + GeocodingAddressComponentType["establishment"] = "establishment"; + /** indicates a named point of interest. */ + GeocodingAddressComponentType["point_of_interest"] = "point_of_interest"; + /** indicates a parking lot or parking structure. */ + GeocodingAddressComponentType["parking"] = "parking"; + /** indicates a specific postal box. */ + GeocodingAddressComponentType["post_box"] = "post_box"; + /** indicates a grouping of geographic areas, such as locality and sublocality, used for mailing addresses in some countries. */ + GeocodingAddressComponentType["postal_town"] = "postal_town"; + /** indicates the room of a building address. */ + GeocodingAddressComponentType["room"] = "room"; + /** indicates the precise street number. */ + GeocodingAddressComponentType["street_number"] = "street_number"; + /** indicate the location of a bus. */ + GeocodingAddressComponentType["bus_station"] = "bus_station"; + /** indicate the location of a train. */ + GeocodingAddressComponentType["train_station"] = "train_station"; + /** indicate the location of a public transit stop. */ + GeocodingAddressComponentType["transit_station"] = "transit_station"; +})(GeocodingAddressComponentType || (exports.GeocodingAddressComponentType = GeocodingAddressComponentType = {})); +var LocationType; +(function (LocationType) { + /** + * indicates that the returned result is a precise geocode for which we have location information + * accurate down to street address precision + */ + LocationType["ROOFTOP"] = "ROOFTOP"; + /** + * indicates that the returned result reflects an approximation (usually on a road) interpolated between two precise points + * (such as intersections). Interpolated results are generally returned when rooftop geocodes are unavailable for a street address. + */ + LocationType["RANGE_INTERPOLATED"] = "RANGE_INTERPOLATED"; + /** + * indicates that the returned result is the geometric center of a result such as a polyline + * (for example, a street) or polygon (region). + */ + LocationType["GEOMETRIC_CENTER"] = "GEOMETRIC_CENTER"; + /** indicates that the returned result is approximate. */ + LocationType["APPROXIMATE"] = "APPROXIMATE"; +})(LocationType || (exports.LocationType = LocationType = {})); +var RadioType; +(function (RadioType) { + RadioType["lte"] = "lte"; + RadioType["gsm"] = "gsm"; + RadioType["cdma"] = "cdma"; + RadioType["wcdma"] = "wcdma"; +})(RadioType || (exports.RadioType = RadioType = {})); +//# sourceMappingURL=common.js.map \ No newline at end of file diff --git a/dist/common.js.map b/dist/common.js.map new file mode 100644 index 0000000000..6a7b3e0bd9 --- /dev/null +++ b/dist/common.js.map @@ -0,0 +1 @@ +{"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"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ACf,qEAAqE;IACrE,gEAA+B,CAAA;IAC/B,2CAA2C;IAC3C,wEAAuC,CAAA;IACvC,oDAAoD;IACpD,oDAAmB,CAAA;IACnB,uCAAuC;IACvC,sDAAqB,CAAA;IACrB,gIAAgI;IAChI,4DAA2B,CAAA;IAC3B,gDAAgD;IAChD,8CAAa,CAAA;IACb,2CAA2C;IAC3C,gEAA+B,CAAA;IAC/B,uCAAuC;IACvC,4DAA2B,CAAA;IAC3B,yCAAyC;IACzC,gEAA+B,CAAA;IAC/B,uDAAuD;IACvD,oEAAmC,CAAA;AACrC,CAAC,EAvBW,6BAA6B,6CAA7B,6BAA6B,QAuBxC;AAmCD,IAAY,YAkBX;AAlBD,WAAY,YAAY;IACtB;;;OAGG;IACH,mCAAmB,CAAA;IACnB;;;OAGG;IACH,yDAAyC,CAAA;IACzC;;;OAGG;IACH,qDAAqC,CAAA;IACrC,yDAAyD;IACzD,2CAA2B,CAAA;AAC7B,CAAC,EAlBW,YAAY,4BAAZ,YAAY,QAkBvB;AAgBD,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,wBAAW,CAAA;IACX,0BAAa,CAAA;IACb,4BAAe,CAAA;AACjB,CAAC,EALW,SAAS,yBAAT,SAAS,QAKpB"} \ No newline at end of file diff --git a/dist/directions.d.ts b/dist/directions.d.ts new file mode 100644 index 0000000000..d5bd9d6658 --- /dev/null +++ b/dist/directions.d.ts @@ -0,0 +1,171 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +import { DirectionsRoute, GeocodedWaypoint, Language, LatLng, RequestParams, ResponseData, TrafficModel, TransitMode, TransitRoutingPreference, TravelMode, TravelRestriction, UnitSystem } from "./common"; +export interface DirectionsRequest extends Partial { + params: { + /** + * The address, textual latitude/longitude value, or place ID from which you wish to calculate directions. + * - If you pass an address, the Directions service geocodes the string and converts it to a latitude/longitude coordinate + * to calculate directions. This coordinate may be different from that returned by the Geocoding API, for example a building + * entrance rather than its center. + * + * `origin=24+Sussex+Drive+Ottawa+ON` + * + * - If you pass coordinates, they are used unchanged to calculate directions. Ensure that no space exists between the latitude + * and longitude values. + * + * `origin=41.43206,-81.38992` + * + * - Place IDs must be prefixed with `place_id:`. The place ID may only be specified if the request includes an API key or a + * Google Maps APIs Premium Plan client ID. You can retrieve place IDs from the Geocoding API and the Places SDK + * (including Place Autocomplete). For an example using place IDs from Place Autocomplete, see [Place Autocomplete and + * Directions](https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-directions). + * + * `origin=place_id:ChIJ3S-JXmauEmsRUcIaWtf4MzE` + */ + origin: LatLng; + /** + * The address, textual latitude/longitude value, or place ID to which you wish to calculate directions. + * The options for the `destination` parameter are the same as for the `origin` parameter, described above + */ + destination: LatLng; + /** + * Specifies the mode of transport to use when calculating directions + * + * @default TravelMode.driving + */ + mode?: TravelMode; + /** + * Specifies an array of waypoints. + * Waypoints alter a route by routing it through the specified location(s). + * A waypoint is specified as a latitude/longitude coordinate, an encoded polyline, a place ID, or an address which will be geocoded. + * Encoded polylines must be prefixed with `enc:` and followed by a colon (`:`). Place IDs must be prefixed with `place_id:`. + * The place ID may only be specified if the request includes an API key or a Google Maps APIs Premium Plan client ID. + * Waypoints are only supported for driving, walking and bicycling directions. + */ + waypoints?: (string | LatLng)[]; + /** + * If set to `true`, specifies that the Directions service may provide more than one route alternative in the response. + * Note that providing route alternatives may increase the response time from the server. + */ + alternatives?: boolean; + /** Indicates that the calculated route(s) should avoid the indicated features. */ + avoid?: TravelRestriction[]; + /** + * The language in which to return results. + * + * - If `language` is not supplied, the API attempts to use the preferred language as specified in the `Accept-Language` header, + * or the native language of the domain from which the request is sent. + * - The API does its best to provide a street address that is readable for both the user and locals. To achieve that goal, + * it returns street addresses in the local language, transliterated to a script readable by the user if necessary, + * observing the preferred language. All other addresses are returned in the preferred language. + * Address components are all returned in the same language, which is chosen from the first component. + * - If a name is not available in the preferred language, the API uses the closest match. + * - The preferred language has a small influence on the set of results that the API chooses to return, + * and the order in which they are returned. The geocoder interprets abbreviations differently depending on language, + * such as the abbreviations for street types, or synonyms that may be valid in one language but not in another. + * For example, utca and tér are synonyms for street in Hungarian. + */ + language?: Language; + /** Specifies the unit system to use when displaying results. */ + units?: UnitSystem; + /** Specifies the region code, specified as a ccTLD ("top-level domain") two-character value. */ + region?: string; + /** + * Specifies the desired time of arrival for transit directions, in seconds since midnight, January 1, 1970 UTC. + * You can specify either `departure_time` or `arrival_time`, but not both. + * Note that `arrival_time` must be specified as an integer. + */ + arrival_time?: Date | number; + /** + * Specifies the desired time of departure. You can specify the time as an integer in seconds since midnight, January 1, 1970 UTC. + * Alternatively, you can specify a value of `now`, which sets the departure time to the current time (correct to the nearest second). + * + * The departure time may be specified in two cases: + * - For requests where the travel mode is transit: You can optionally specify one of `departure_time` or `arrival_time`. + * If neither time is specified, the `departure_time` defaults to now (that is, the departure time defaults to the current time). + * - For requests where the travel mode is driving: You can specify the `departure_time` to receive a route and trip duration + * (response field: `duration_in_traffic`) that take traffic conditions into account. + * This option is only available if the request contains a valid API key, or a valid Google Maps APIs Premium Plan client ID + * and signature. The `departure_time` must be set to the current time or some time in the future. It cannot be in the past. + */ + departure_time?: Date | number | "now"; + /** + * Specifies the assumptions to use when calculating time in traffic. + * This setting affects the value returned in the `duration_in_traffic` field in the response, which contains the predicted time + * in traffic based on historical averages. The `traffic_model` parameter may only be specified for driving directions + * where the request includes a `departure_time`, and only if the request includes an API key or a Google Maps APIs Premium Plan client ID. + * + * The default value of `best_guess` will give the most useful predictions for the vast majority of use cases. + * It is possible the `best_guess` travel time prediction may be *shorter* than `optimistic`, or alternatively, + * *longer* than `pessimistic`, due to the way the `best_guess` prediction model integrates live traffic information. + * + * @default TrafficModel.best_guess + */ + traffic_model?: TrafficModel; + /** + * Specifies one or more preferred modes of transit. + * This parameter may only be specified for transit directions, and only if the request includes an API key or + * a Google Maps APIs Premium Plan client ID. + */ + transit_mode?: TransitMode[]; + /** + * Specifies preferences for transit routes. + * Using this parameter, you can bias the options returned, rather than accepting the default best route chosen by the API. + * This parameter may only be specified for transit directions, and only if the request includes an API key or + * a Google Maps APIs Premium Plan client ID. + */ + transit_routing_preference?: TransitRoutingPreference; + /** Wherever to optimize the provided route by rearranging the waypoints in a more efficient order. */ + optimize?: boolean; + } & RequestParams; +} +export interface DirectionsResponseData extends ResponseData { + /** + * contains an array with details about the geocoding of origin, destination and waypoints. + * + * These details will not be present for waypoints specified as textual latitude/longitude values if the service returns no results. + * This is because such waypoints are only reverse geocoded to obtain their representative address after a route has been found. + * An empty JSON object will occupy the corresponding places in the `geocoded_waypoints` array. + */ + geocoded_waypoints: GeocodedWaypoint[]; + /** + * contains an array of routes from the origin to the destination. + * + * When the Directions API returns results, it places them within a (JSON) `routes` array. Even if the service returns no results + * (such as if the origin and/or destination doesn't exist) it still returns an empty `routes` array. + * (XML responses consist of zero or more `` elements.) + * + * Each element of the `routes` array contains a single result from the specified origin and destination. + * This route may consist of one or more `legs` depending on whether any waypoints were specified. + * As well, the route also contains copyright and warning information which must be displayed to the user in addition to the + * routing information. + */ + routes: DirectionsRoute[]; + /** + * contains an array of available travel modes. This field is returned when a request specifies a travel `mode` and gets no results. + * The array contains the available travel modes in the countries of the given set of waypoints. + * This field is not returned if one or more of the waypoints are `via:` waypoints. + */ + available_travel_modes: string[]; +} +export interface DirectionsResponse extends AxiosResponse { + data: DirectionsResponseData; +} +export declare const defaultUrl = "https://maps.googleapis.com/maps/api/directions/json"; +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function directions({ params, method, url, paramsSerializer, ...config }: DirectionsRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/directions.js b/dist/directions.js new file mode 100644 index 0000000000..ce4d569708 --- /dev/null +++ b/dist/directions.js @@ -0,0 +1,56 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.directions = exports.defaultParamsSerializer = exports.defaultUrl = void 0; +const serialize_1 = require("./serialize"); +const client_1 = require("./client"); +exports.defaultUrl = "https://maps.googleapis.com/maps/api/directions/json"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({ + origin: serialize_1.latLngToString, + destination: serialize_1.latLngToString, + waypoints: (o) => o.map(serialize_1.latLngToString), + arrival_time: serialize_1.toTimestamp, + departure_time: serialize_1.toTimestamp, +}, exports.defaultUrl); +function directions(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + const { optimize } = params; + // optimize is passed as the first of the waypoint pipe array + // &waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA + if (optimize) { + params.waypoints = ["optimize:true", ...params.waypoints]; + } + delete params.optimize; + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.directions = directions; +//# sourceMappingURL=directions.js.map \ No newline at end of file diff --git a/dist/directions.js.map b/dist/directions.js.map new file mode 100644 index 0000000000..ad63ab6b5e --- /dev/null +++ b/dist/directions.js.map @@ -0,0 +1 @@ +{"version":3,"file":"directions.js","sourceRoot":"","sources":["../src/directions.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAiBH,2CAAsE;AAEtE,qCAAgD;AA2JnC,QAAA,UAAU,GACrB,sDAAsD,CAAC;AAE5C,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAC/C;IACE,MAAM,EAAE,0BAAc;IACtB,WAAW,EAAE,0BAAc;IAC3B,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,0BAAc,CAAC;IACvC,YAAY,EAAE,uBAAW;IACzB,cAAc,EAAE,uBAAW;CAC5B,EACD,kBAAU,CACX,CAAC;AAEF,SAAgB,UAAU,CACxB,EAMoB,EACpB,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAExB,EADf,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAE5B,6DAA6D;IAC7D,oFAAoF;IACpF,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,CAAC,SAAS,GAAG,CAAC,eAAe,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,MAAM,CAAC,QAAQ,CAAC;IAEvB,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EACsB,CAAC;AACpC,CAAC;AA3BD,gCA2BC"} \ No newline at end of file diff --git a/dist/directions.test.d.ts b/dist/directions.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/directions.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/directions.test.js b/dist/directions.test.js new file mode 100644 index 0000000000..c7c2d2a0f3 --- /dev/null +++ b/dist/directions.test.js @@ -0,0 +1,51 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const directions_1 = require("./directions"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("elevation should call axios correctly", () => { + const params = { + origin: "Seattle, WA", + destination: "San Francisco, CA", + key: "foo", + }; + (0, directions_1.directions)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: directions_1.defaultParamsSerializer, + url: directions_1.defaultUrl, + }); +}); +test("serializer should transform correctly", () => { + const params = { + origin: "Seattle, WA", + destination: "San Francisco, CA", + key: "foo", + }; + expect((0, directions_1.defaultParamsSerializer)(params)).toEqual("destination=San%20Francisco%2C%20CA&key=foo&origin=Seattle%2C%20WA"); +}); +//# sourceMappingURL=directions.test.js.map \ No newline at end of file diff --git a/dist/directions.test.js.map b/dist/directions.test.js.map new file mode 100644 index 0000000000..7927b91541 --- /dev/null +++ b/dist/directions.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"directions.test.js","sourceRoot":"","sources":["../src/directions.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,kDAA0B;AAC1B,6CAA+E;AAE/E,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IACjD,MAAM,MAAM,GAAG;QACb,MAAM,EAAE,aAAa;QACrB,WAAW,EAAE,mBAAmB;QAChC,GAAG,EAAE,KAAK;KACX,CAAC;IAEF,IAAA,uBAAU,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAE5C,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,oCAAuB;QACzC,GAAG,EAAE,uBAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IACjD,MAAM,MAAM,GAAG;QACb,MAAM,EAAE,aAAa;QACrB,WAAW,EAAE,mBAAmB;QAChC,GAAG,EAAE,KAAK;KACX,CAAC;IAEF,MAAM,CAAC,IAAA,oCAAuB,EAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAC7C,oEAAoE,CACrE,CAAC;AACJ,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/distance.d.ts b/dist/distance.d.ts new file mode 100644 index 0000000000..27e2f5d5c6 --- /dev/null +++ b/dist/distance.d.ts @@ -0,0 +1,152 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +import { DistanceMatrixRow, LatLng, RequestParams, ResponseData, TrafficModel, TransitMode, TransitRoutingPreference, TravelMode, TravelRestriction, UnitSystem } from "./common"; +export interface DistanceMatrixRequest extends Partial { + params: { + /** + * The starting point for calculating travel distance and time. + * You can supply one or more locations separated by the pipe character (`|`), in the form of an address, latitude/longitude coordinates, + * or a place ID: + * - If you pass an address, the service geocodes the string and converts it to a latitude/longitude coordinate to calculate distance. + * This coordinate may be different from that returned by the Geocoding API, for example a building entrance rather than its center. + * + * `origins=Bobcaygeon+ON|24+Sussex+Drive+Ottawa+ON` + * + * - If you pass latitude/longitude coordinates, they are used unchanged to calculate distance. + * Ensure that no space exists between the latitude and longitude values. + * + * `origins=41.43206,-81.38992|-33.86748,151.20699` + * + * - If you supply a place ID, you must prefix it with `place_id:`. + * You can only specify a place ID if the request includes an API key or a Google Maps APIs Premium Plan client ID. + * You can retrieve place IDs from the Geocoding API and the Places SDK (including Place Autocomplete). + * + * `origins=place_id:ChIJ3S-JXmauEmsRUcIaWtf4MzE` + * + * - Alternatively, you can supply an encoded set of coordinates using the + * [Encoded Polyline Algorithm](https://developers.google.com/maps/documentation/utilities/polylinealgorithm). + * This is particularly useful if you have a large number of origin points, because the URL is significantly shorter when using + * an encoded polyline. + * + * - Encoded polylines must be prefixed with `enc:` and followed by a colon (`:`). For example: `origins=enc:gfo}EtohhU:` + * - You can also include multiple encoded polylines, separated by the pipe character (`|`). + * For example: `origins=enc:wc~oAwquwMdlTxiKtqLyiK:|enc:c~vnAamswMvlTor@tjGi}L:|enc:udymA{~bxM:` + */ + origins: LatLng[]; + /** + * One or more locations to use as the finishing point for calculating travel distance and time. + * The options for the destinations parameter are the same as for the origins parameter, described above. + */ + destinations: LatLng[]; + /** + * Specifies the mode of transport to use when calculating distance. + * Valid values and other request details are specified in the Travel Modes section of this document. + * + * @default TravelMode.driving + */ + mode?: TravelMode; + /** + * The language in which to return results. + * - If `language` is not supplied, the API attempts to use the preferred language as specified in the `Accept-Language` header, + * or the native language of the domain from which the request is sent. + * - The API does its best to provide a street address that is readable for both the user and locals. To achieve that goal, + * it returns street addresses in the local language, transliterated to a script readable by the user if necessary, + * observing the preferred language. All other addresses are returned in the preferred language. + * Address components are all returned in the same language, which is chosen from the first component. + * - If a name is not available in the preferred language, the API uses the closest match. + * - The preferred language has a small influence on the set of results that the API chooses to return, + * and the order in which they are returned. The geocoder interprets abbreviations differently depending on language, + * such as the abbreviations for street types, or synonyms that may be valid in one language but not in another. + * For example, utca and tér are synonyms for street in Hungarian. + */ + language?: string; + /** + * The region code, specified as a [ccTLD](https://en.wikipedia.org/wiki/CcTLD) (country code top-level domain) two-character value. + * Most ccTLD codes are identical to ISO 3166-1 codes, with some exceptions. + * This parameter will only influence, not fully restrict, results from the geocoder. + * If more relevant results exist outside of the specified region, they may be included. + */ + region?: string; + /** + * Introduces restrictions to the route. Valid values are specified in the Restrictions section of this document. + * Only one restriction can be specified. + */ + avoid?: TravelRestriction[]; + /** Specifies the unit system to use when expressing distance as text. */ + units?: UnitSystem; + /** + * Specifies the desired time of arrival for transit requests, in seconds since midnight, January 1, 1970 UTC. + * You can specify either `departure_time` or `arrival_time`, but not both. + * Note that `arrival_time` must be specified as an integer. + */ + arrival_time?: Date | number; + /** + * The desired time of departure. You can specify the time as an integer in seconds since midnight, January 1, 1970 UTC. + * Alternatively, you can specify a value of now, which sets the departure time to the current time (correct to the nearest second). + * + * The departure time may be specified in two cases: + * + * - For requests where the travel mode is transit: You can optionally specify one of `departure_time` or `arrival_time`. + * If neither time is specified, the `departure_time` defaults to now (that is, the departure time defaults to the current time). + * + * - For requests where the travel mode is driving: You can specify the `departure_time` to receive a route and trip duration + * (response field: `duration_in_traffic`) that take traffic conditions into account. + * This option is only available if the request contains a valid API key, or a valid + * Google Maps APIs Premium Plan client ID and signature. + * The `departure_time` must be set to the current time or some time in the future. It cannot be in the past. + * + * **Note:** Distance Matrix requests specifying `departure_time` when `mode=driving` are limited + * to a maximum of 100 elements per request. The number of origins times the number of destinations defines the number of elements. + */ + departure_time?: Date | number; + /** + * Specifies the assumptions to use when calculating time in traffic. + * This setting affects the value returned in the `duration_in_traffic` field in the response, + * which contains the predicted time in traffic based on historical averages. + * The `traffic_model` parameter may only be specified for requests where the travel mode is `driving`, + * and where the request includes a `departure_time`, and only if the request includes an API key or + * a Google Maps APIs Premium Plan client ID. + * + * @default TrafficModel.best_guess + */ + traffic_model?: TrafficModel; + /** Specifies one or more preferred modes of transit. This parameter may only be specified for requests where the `mode` is `transit`. */ + transit_mode?: TransitMode[]; + /** + * Specifies preferences for transit requests. Using this parameter, you can bias the options returned, + * rather than accepting the default best route chosen by the API. + * This parameter may only be specified for requests where the `mode` is `transit`. + */ + transit_routing_preference?: TransitRoutingPreference; + } & RequestParams; +} +export interface DistanceMatrixResponseData extends ResponseData { + origin_addresses: string[]; + /** + * contains an array of addresses as returned by the API from your original request. + * As with origin_addresses, these are localized if appropriate. + */ + destination_addresses: string[]; + /** contains an array of elements, which in turn each contain a status, duration, and distance element. */ + rows: DistanceMatrixRow[]; +} +export interface DistanceMatrixResponse extends AxiosResponse { + data: DistanceMatrixResponseData; +} +export declare const defaultUrl = "https://maps.googleapis.com/maps/api/distancematrix/json"; +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function distancematrix({ params, method, url, paramsSerializer, ...config }: DistanceMatrixRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/distance.js b/dist/distance.js new file mode 100644 index 0000000000..88e95b5372 --- /dev/null +++ b/dist/distance.js @@ -0,0 +1,48 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.distancematrix = exports.defaultParamsSerializer = exports.defaultUrl = void 0; +const serialize_1 = require("./serialize"); +const client_1 = require("./client"); +exports.defaultUrl = "https://maps.googleapis.com/maps/api/distancematrix/json"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({ + origins: (o) => o.map(serialize_1.latLngToString), + destinations: (o) => o.map(serialize_1.latLngToString), + arrival_time: serialize_1.toTimestamp, + departure_time: serialize_1.toTimestamp, +}, exports.defaultUrl); +function distancematrix(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.distancematrix = distancematrix; +//# sourceMappingURL=distance.js.map \ No newline at end of file diff --git a/dist/distance.js.map b/dist/distance.js.map new file mode 100644 index 0000000000..fca85ee18a --- /dev/null +++ b/dist/distance.js.map @@ -0,0 +1 @@ +{"version":3,"file":"distance.js","sourceRoot":"","sources":["../src/distance.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAeH,2CAAsE;AAEtE,qCAAgD;AAyInC,QAAA,UAAU,GACrB,0DAA0D,CAAC;AAEhD,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAC/C;IACE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,0BAAc,CAAC;IACrC,YAAY,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,0BAAc,CAAC;IAC1C,YAAY,EAAE,uBAAW;IACzB,cAAc,EAAE,uBAAW;CAC5B,EACD,kBAAU,CACX,CAAC;AAEF,SAAgB,cAAc,CAC5B,EAMwB,EACxB,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAEpB,EADnB,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EAC0B,CAAC;AACxC,CAAC;AAjBD,wCAiBC"} \ No newline at end of file diff --git a/dist/distance.test.d.ts b/dist/distance.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/distance.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/distance.test.js b/dist/distance.test.js new file mode 100644 index 0000000000..976e9e9207 --- /dev/null +++ b/dist/distance.test.js @@ -0,0 +1,51 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const distance_1 = require("./distance"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("elevation should call axios correctly", () => { + const params = { + origins: ["Seattle, WA"], + destinations: ["San Francisco, CA", "New York, NY"], + key: "foo", + }; + (0, distance_1.distancematrix)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: distance_1.defaultParamsSerializer, + url: distance_1.defaultUrl, + }); +}); +test("serializer should transform correctly", () => { + const params = { + origins: ["Seattle, WA"], + destinations: ["San Francisco, CA", "New York, NY"], + key: "foo", + }; + expect((0, distance_1.defaultParamsSerializer)(params)).toEqual("destinations=San%20Francisco%2C%20CA|New%20York%2C%20NY&key=foo&origins=Seattle%2C%20WA"); +}); +//# sourceMappingURL=distance.test.js.map \ No newline at end of file diff --git a/dist/distance.test.js.map b/dist/distance.test.js.map new file mode 100644 index 0000000000..571b56eab5 --- /dev/null +++ b/dist/distance.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"distance.test.js","sourceRoot":"","sources":["../src/distance.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,kDAA0B;AAC1B,yCAIoB;AAEpB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IACjD,MAAM,MAAM,GAAG;QACb,OAAO,EAAE,CAAC,aAAa,CAAC;QACxB,YAAY,EAAE,CAAC,mBAAmB,EAAE,cAAc,CAAC;QACnD,GAAG,EAAE,KAAK;KACX,CAAC;IAEF,IAAA,yBAAc,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAEhD,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,kCAAuB;QACzC,GAAG,EAAE,qBAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IACjD,MAAM,MAAM,GAAG;QACb,OAAO,EAAE,CAAC,aAAa,CAAC;QACxB,YAAY,EAAE,CAAC,mBAAmB,EAAE,cAAc,CAAC;QACnD,GAAG,EAAE,KAAK;KACX,CAAC;IAEF,MAAM,CAAC,IAAA,kCAAuB,EAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAC7C,yFAAyF,CAC1F,CAAC;AACJ,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/elevation.d.ts b/dist/elevation.d.ts new file mode 100644 index 0000000000..84287695e1 --- /dev/null +++ b/dist/elevation.d.ts @@ -0,0 +1,66 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { LatLng, LatLngLiteral, ResponseData, RequestParams } from "./common"; +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +export interface PositionalElevationParams { + /** + * defines the location(s) on the earth from which to return elevation data. + * This parameter takes either a single location as a comma-separated {latitude,longitude} pair (e.g. "40.714728,-73.998672") + * or multiple latitude/longitude pairs passed as an array or as an encoded polyline. + */ + locations: LatLng[]; +} +export interface SampledPathElevationParams { + /** + * defines a path on the earth for which to return elevation data. This parameter defines a + * set of two or more ordered pairs defining a path along the surface of the earth. This + * parameter must be used in conjunction with the samples parameter described below. + */ + path: LatLng[]; + /** + * specifies the number of sample points along a path for which to return elevation data. + * The samples parameter divides the given path into an ordered set of equidistant points + * along the path. + */ + samples: number; +} +export interface ElevationRequest extends Partial { + params: (PositionalElevationParams | SampledPathElevationParams) & RequestParams; +} +export interface ElevationResponseData extends ResponseData { + results: { + /** + * A `location` element (containing `lat` and `lng` elements) of the position for which elevation data is being computed. + * Note that for path requests, the set of `location` elements will contain the sampled points along the path. + */ + location: LatLngLiteral; + /** An `elevation` element indicating the elevation of the location in meters. */ + elevation: number; + /** + * A `resolution` value, indicating the maximum distance between data points from which the elevation was interpolated, in meters. + * This property will be missing if the resolution is not known. + * Note that elevation data becomes more coarse (larger `resolution` values) when multiple points are passed. + * To obtain the most accurate elevation value for a point, it should be queried independently. + */ + resolution: number; + }[]; +} +export interface ElevationResponse extends AxiosResponse { + data: ElevationResponseData; +} +export declare const defaultUrl = "https://maps.googleapis.com/maps/api/elevation/json"; +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function elevation({ params, method, url, paramsSerializer, ...config }: ElevationRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/elevation.js b/dist/elevation.js new file mode 100644 index 0000000000..35a1098680 --- /dev/null +++ b/dist/elevation.js @@ -0,0 +1,46 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.elevation = exports.defaultParamsSerializer = exports.defaultUrl = void 0; +const client_1 = require("./client"); +const serialize_1 = require("./serialize"); +exports.defaultUrl = "https://maps.googleapis.com/maps/api/elevation/json"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({ + locations: (o) => o.map(serialize_1.latLngToString), + path: (o) => o.map(serialize_1.latLngToString), +}, exports.defaultUrl); +function elevation(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.elevation = elevation; +//# sourceMappingURL=elevation.js.map \ No newline at end of file diff --git a/dist/elevation.js.map b/dist/elevation.js.map new file mode 100644 index 0000000000..c486b3e6ef --- /dev/null +++ b/dist/elevation.js.map @@ -0,0 +1 @@ +{"version":3,"file":"elevation.js","sourceRoot":"","sources":["../src/elevation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAIH,qCAAgD;AAChD,2CAAyD;AAqD5C,QAAA,UAAU,GAAG,qDAAqD,CAAC;AAEnE,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAC/C;IACE,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,0BAAc,CAAC;IACvC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,0BAAc,CAAC;CACnC,EACD,kBAAU,CACX,CAAC;AAEF,SAAgB,SAAS,CACvB,EAMmB,EACnB,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAEzB,EADd,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EACqB,CAAC;AACnC,CAAC;AAjBD,8BAiBC"} \ No newline at end of file diff --git a/dist/elevation.test.d.ts b/dist/elevation.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/elevation.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/elevation.test.js b/dist/elevation.test.js new file mode 100644 index 0000000000..4cb0f4d507 --- /dev/null +++ b/dist/elevation.test.js @@ -0,0 +1,68 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const elevation_1 = require("./elevation"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("elevation should call axios correctly with location params", () => { + const params = { locations: ["10,20"], key: "foo" }; + (0, elevation_1.elevation)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: elevation_1.defaultParamsSerializer, + url: elevation_1.defaultUrl, + }); +}); +test("elevation should call axios correctly with path params", () => { + const params = { + path: [ + { lat: 35, lng: -110 }, + { lat: 45, lng: -110 }, + ], + samples: 10, + key: "foo", + }; + (0, elevation_1.elevation)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: elevation_1.defaultParamsSerializer, + url: elevation_1.defaultUrl, + }); +}); +test("serializer should transform correctly", () => { + const params = { + path: [ + { lat: 35, lng: -110 }, + { lat: 45, lng: -110 }, + ], + samples: 10, + key: "foo", + }; + expect((0, elevation_1.defaultParamsSerializer)(params)).toEqual("key=foo&path=35%2C-110|45%2C-110&samples=10"); +}); +//# sourceMappingURL=elevation.test.js.map \ No newline at end of file diff --git a/dist/elevation.test.js.map b/dist/elevation.test.js.map new file mode 100644 index 0000000000..969c7cb027 --- /dev/null +++ b/dist/elevation.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"elevation.test.js","sourceRoot":"","sources":["../src/elevation.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,kDAA0B;AAC1B,2CAA6E;AAE7E,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4DAA4D,EAAE,GAAG,EAAE;IACtE,MAAM,MAAM,GAAG,EAAE,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAEpD,IAAA,qBAAS,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAE3C,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,mCAAuB;QACzC,GAAG,EAAE,sBAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,wDAAwD,EAAE,GAAG,EAAE;IAClE,MAAM,MAAM,GAAG;QACb,IAAI,EAAE;YACJ,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE;YACtB,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE;SACvB;QACD,OAAO,EAAE,EAAE;QACX,GAAG,EAAE,KAAK;KACX,CAAC;IAEF,IAAA,qBAAS,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAE3C,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,mCAAuB;QACzC,GAAG,EAAE,sBAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IACjD,MAAM,MAAM,GAAG;QACb,IAAI,EAAE;YACJ,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE;YACtB,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE;SACvB;QACD,OAAO,EAAE,EAAE;QACX,GAAG,EAAE,KAAK;KACX,CAAC;IAEF,MAAM,CAAC,IAAA,mCAAuB,EAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAC7C,6CAA6C,CAC9C,CAAC;AACJ,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/geocode/geocode.d.ts b/dist/geocode/geocode.d.ts new file mode 100644 index 0000000000..f9cca716b4 --- /dev/null +++ b/dist/geocode/geocode.d.ts @@ -0,0 +1,92 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { LatLngBounds, GeocodeResult, ResponseData, RequestParams } from "../common"; +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +export declare const defaultUrl = "https://maps.googleapis.com/maps/api/geocode/json"; +export interface GeocodeComponents { + /** matches `postal_code` and `postal_code_prefix`. */ + postal_code?: string; + /** + * matches a country name or a two letter [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country code. + * **Note:** The API follows the ISO standard for defining countries, and the filtering works best when using + * the corresponding ISO code of the country + */ + country?: string; + /** matches the long or short name of a route. */ + route?: string; + /** matches against `locality` and `sublocality` types. */ + locality?: string; + /** matches all the administrative_area levels. */ + administrative_area?: string; +} +export interface GeocodeRequest extends Partial { + params: { + /** + * The place_id that you want to geocode. You can retrieve this information from Places API for example. + */ + place_id?: string; + /** + * The street address that you want to geocode, in the format used by the national postal service of the country concerned. + * Additional address elements such as business names and unit, suite or floor numbers should be avoided. + */ + address?: string; + /** + * The bounding box of the viewport within which to bias geocode results more prominently. + * This parameter will only influence, not fully restrict, results from the geocoder. + */ + bounds?: string | LatLngBounds; + /** + * The language in which to return results. + * - If `language` is not supplied, the geocoder attempts to use the preferred language as specified in the `Accept-Language` header, + * or the native language of the domain from which the request is sent. + * - The geocoder does its best to provide a street address that is readable for both the user and locals. + * To achieve that goal, it returns street addresses in the local language, transliterated to a script readable + * by the user if necessary, observing the preferred language. All other addresses are returned in the preferred language. + * Address components are all returned in the same language, which is chosen from the first component. + * - If a name is not available in the preferred language, the geocoder uses the closest match. + * - The preferred language has a small influence on the set of results that the API chooses to return, + * and the order in which they are returned. The geocoder interprets abbreviations differently depending on language, + * such as the abbreviations for street types, or synonyms that may be valid in one language but not in another. + * For example, utca and tér are synonyms for street in Hungarian. + */ + language?: string; + /** + * The region code, specified as a ccTLD ("top-level domain") two-character value. + * This parameter will only influence, not fully restrict, results from the geocoder. + */ + region?: string; + /** + * A components filter with elements separated by a pipe (`|`). + * The components filter is *required* if the request doesn't include an `address`. + * Each element in the components filter consists of a `component:value` pair, and fully restricts the results from the geocoder. + */ + components?: string | GeocodeComponents; + } & RequestParams; +} +export interface GeocodeResponseData extends ResponseData { + /** + * contains an array of geocoded address information and geometry information. + * + * Generally, only one entry in the `"results"` array is returned for address lookups,though the geocoder may return several results + * when address queries are ambiguous. + */ + results: GeocodeResult[]; +} +export interface GeocodeResponse extends AxiosResponse { + data: GeocodeResponseData; +} +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function geocode({ params, method, url, paramsSerializer, ...config }: GeocodeRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/geocode/geocode.js b/dist/geocode/geocode.js new file mode 100644 index 0000000000..7e1ba27eca --- /dev/null +++ b/dist/geocode/geocode.js @@ -0,0 +1,46 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.geocode = exports.defaultParamsSerializer = exports.defaultUrl = void 0; +const client_1 = require("../client"); +const serialize_1 = require("../serialize"); +exports.defaultUrl = "https://maps.googleapis.com/maps/api/geocode/json"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({ + bounds: serialize_1.latLngBoundsToString, + components: serialize_1.objectToString, +}, exports.defaultUrl); +function geocode(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.geocode = geocode; +//# sourceMappingURL=geocode.js.map \ No newline at end of file diff --git a/dist/geocode/geocode.js.map b/dist/geocode/geocode.js.map new file mode 100644 index 0000000000..bd4e5732e0 --- /dev/null +++ b/dist/geocode/geocode.js.map @@ -0,0 +1 @@ +{"version":3,"file":"geocode.js","sourceRoot":"","sources":["../../src/geocode/geocode.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AASH,sCAAiD;AACjD,4CAAgF;AAEnE,QAAA,UAAU,GAAG,mDAAmD,CAAC;AA8EjE,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAC/C;IACE,MAAM,EAAE,gCAAoB;IAC5B,UAAU,EAAE,0BAAc;CAC3B,EACD,kBAAU,CACX,CAAC;AAEF,SAAgB,OAAO,CACrB,EAMiB,EACjB,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAE3B,EADZ,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EACmB,CAAC;AACjC,CAAC;AAjBD,0BAiBC"} \ No newline at end of file diff --git a/dist/geocode/geocode.test.d.ts b/dist/geocode/geocode.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/geocode/geocode.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/geocode/geocode.test.js b/dist/geocode/geocode.test.js new file mode 100644 index 0000000000..00e5027f54 --- /dev/null +++ b/dist/geocode/geocode.test.js @@ -0,0 +1,39 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const geocode_1 = require("./geocode"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("geocode should call axios correctly", () => { + const params = { address: "Seattle", key: "foo", components: "country:us" }; + (0, geocode_1.geocode)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: geocode_1.defaultParamsSerializer, + url: geocode_1.defaultUrl, + }); +}); +//# sourceMappingURL=geocode.test.js.map \ No newline at end of file diff --git a/dist/geocode/geocode.test.js.map b/dist/geocode/geocode.test.js.map new file mode 100644 index 0000000000..902b13e641 --- /dev/null +++ b/dist/geocode/geocode.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"geocode.test.js","sourceRoot":"","sources":["../../src/geocode/geocode.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,kDAA0B;AAC1B,uCAAyE;AAEzE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,qCAAqC,EAAE,GAAG,EAAE;IAC/C,MAAM,MAAM,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC;IAE5E,IAAA,iBAAO,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAEzC,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,iCAAuB;QACzC,GAAG,EAAE,oBAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/geocode/reversegeocode.d.ts b/dist/geocode/reversegeocode.d.ts new file mode 100644 index 0000000000..72e047e5ba --- /dev/null +++ b/dist/geocode/reversegeocode.d.ts @@ -0,0 +1,93 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AddressType, Language, LatLng, RequestParams } from "../common"; +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +import { GeocodeResult, ResponseData } from "../common"; +/** + * If both `result_type` and `location_type` filters are present then the API returns only those results that match both the + * `result_type` and the `location_type` values. If none of the filter values are acceptable, the API returns `ZERO_RESULTS`. + */ +export declare enum ReverseGeocodingLocationType { + /** returns only the addresses for which Google has location information accurate down to street address precision. */ + ROOFTOP = "ROOFTOP", + /** + * returns only the addresses that reflect an approximation (usually on a road) interpolated between two precise points + * (such as intersections). An interpolated range generally indicates that rooftop geocodes are unavailable for a street address. + */ + RANGE_INTERPOLATED = "RANGE_INTERPOLATED", + /** returns only geometric centers of a location such as a polyline (for example, a street) or polygon (region). */ + GEOMETRIC_CENTER = "GEOMETRIC_CENTER", + /** returns only the addresses that are characterized as approximate. */ + APPROXIMATE = "APPROXIMATE" +} +export interface ReverseGeocodeRequest extends Partial { + params: { + /** The latitude and longitude values specifying the location for which you wish to obtain the closest, human-readable address. */ + latlng?: LatLng; + /** + * The place ID of the place for which you wish to obtain the human-readable address. + * The place ID is a unique identifier that can be used with other Google APIs. + * For example, you can use the `placeID` returned by the Roads API to get the address for a snapped point. + * The place ID may only be specified if the request includes an API key or a Google Maps APIs Premium Plan client ID. + */ + place_id?: string; + /** + * The language in which to return results. + * - Google often updates the supported languages, so this list may not be exhaustive. + * - If `language` is not supplied, the geocoder attempts to use the preferred language as specified in the + * `Accept-Language` header, or the native language of the domain from which the request is sent. + * - The geocoder does its best to provide a street address that is readable for both the user and locals. + * To achieve that goal, it returns street addresses in the local language, transliterated to a script readable by the user + * if necessary, observing the preferred language. All other addresses are returned in the preferred language. + * Address components are all returned in the same language, which is chosen from the first component. + * - If a name is not available in the preferred language, the geocoder uses the closest match. + */ + language?: Language; + /** + * A filter of one or more address types, separated by a pipe (`|`). + * If the parameter contains multiple address types, the API returns all addresses that match any of the types. + * A note about processing: The `result_type` parameter does not restrict the search to the specified address type(s). + * Rather, the `result_type` acts as a post-search filter: the API fetches all results for the specified `latlng`, + * then discards those results that do not match the specified address type(s). + * Note: This parameter is available only for requests that include an API key or a client ID. + */ + result_type?: AddressType[]; + /** + * A filter of one or more location types, separated by a pipe (`|`). + * If the parameter contains multiple location types, the API returns all addresses that match any of the types. + * A note about processing: The `location_type` parameter does not restrict the search to the specified location type(s). + * Rather, the `location_type` acts as a post-search filter: the API fetches all results for the specified `latlng`, + * then discards those results that do not match the specified location type(s). + * Note: This parameter is available only for requests that include an API key or a client ID. + */ + location_type?: ReverseGeocodingLocationType[]; + } & RequestParams; +} +export interface ReverseGeocodeResponseData extends ResponseData { + /** + * contains an array of geocoded address information and geometry information. + * + * Generally, only one entry in the `"results"` array is returned for address lookups,though the geocoder may return several results + * when address queries are ambiguous. + */ + results: GeocodeResult[]; +} +export interface ReverseGeocodeResponse extends AxiosResponse { + data: ReverseGeocodeResponseData; +} +export declare const defaultUrl = "https://maps.googleapis.com/maps/api/geocode/json"; +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function reverseGeocode({ params, method, url, paramsSerializer, ...config }: ReverseGeocodeRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/geocode/reversegeocode.js b/dist/geocode/reversegeocode.js new file mode 100644 index 0000000000..6297b99004 --- /dev/null +++ b/dist/geocode/reversegeocode.js @@ -0,0 +1,63 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.reverseGeocode = exports.defaultParamsSerializer = exports.defaultUrl = exports.ReverseGeocodingLocationType = void 0; +const serialize_1 = require("../serialize"); +const client_1 = require("../client"); +/** + * If both `result_type` and `location_type` filters are present then the API returns only those results that match both the + * `result_type` and the `location_type` values. If none of the filter values are acceptable, the API returns `ZERO_RESULTS`. + */ +var ReverseGeocodingLocationType; +(function (ReverseGeocodingLocationType) { + /** returns only the addresses for which Google has location information accurate down to street address precision. */ + ReverseGeocodingLocationType["ROOFTOP"] = "ROOFTOP"; + /** + * returns only the addresses that reflect an approximation (usually on a road) interpolated between two precise points + * (such as intersections). An interpolated range generally indicates that rooftop geocodes are unavailable for a street address. + */ + ReverseGeocodingLocationType["RANGE_INTERPOLATED"] = "RANGE_INTERPOLATED"; + /** returns only geometric centers of a location such as a polyline (for example, a street) or polygon (region). */ + ReverseGeocodingLocationType["GEOMETRIC_CENTER"] = "GEOMETRIC_CENTER"; + /** returns only the addresses that are characterized as approximate. */ + ReverseGeocodingLocationType["APPROXIMATE"] = "APPROXIMATE"; +})(ReverseGeocodingLocationType || (exports.ReverseGeocodingLocationType = ReverseGeocodingLocationType = {})); +exports.defaultUrl = "https://maps.googleapis.com/maps/api/geocode/json"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({ + latlng: serialize_1.latLngToString, +}, exports.defaultUrl); +function reverseGeocode(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.reverseGeocode = reverseGeocode; +//# sourceMappingURL=reversegeocode.js.map \ No newline at end of file diff --git a/dist/geocode/reversegeocode.js.map b/dist/geocode/reversegeocode.js.map new file mode 100644 index 0000000000..425b487baa --- /dev/null +++ b/dist/geocode/reversegeocode.js.map @@ -0,0 +1 @@ +{"version":3,"file":"reversegeocode.js","sourceRoot":"","sources":["../../src/geocode/reversegeocode.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAKH,4CAA0D;AAE1D,sCAAiD;AAEjD;;;GAGG;AACH,IAAY,4BAYX;AAZD,WAAY,4BAA4B;IACtC,sHAAsH;IACtH,mDAAmB,CAAA;IACnB;;;OAGG;IACH,yEAAyC,CAAA;IACzC,mHAAmH;IACnH,qEAAqC,CAAA;IACrC,wEAAwE;IACxE,2DAA2B,CAAA;AAC7B,CAAC,EAZW,4BAA4B,4CAA5B,4BAA4B,QAYvC;AA4DY,QAAA,UAAU,GAAG,mDAAmD,CAAC;AAEjE,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAC/C;IACE,MAAM,EAAE,0BAAc;CACvB,EACD,kBAAU,CACX,CAAC;AAEF,SAAgB,cAAc,CAC5B,EAMwB,EACxB,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAEpB,EADnB,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EAC0B,CAAC;AACxC,CAAC;AAjBD,wCAiBC"} \ No newline at end of file diff --git a/dist/geocode/reversegeocode.test.d.ts b/dist/geocode/reversegeocode.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/geocode/reversegeocode.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/geocode/reversegeocode.test.js b/dist/geocode/reversegeocode.test.js new file mode 100644 index 0000000000..cb3c1f3ed5 --- /dev/null +++ b/dist/geocode/reversegeocode.test.js @@ -0,0 +1,45 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const reversegeocode_1 = require("./reversegeocode"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("reverseGeocode should call axios correctly", () => { + const params = { + latlng: { + lat: 60.168997, + lng: 24.9433353, + }, + key: "foo", + }; + (0, reversegeocode_1.reverseGeocode)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: reversegeocode_1.defaultParamsSerializer, + url: reversegeocode_1.defaultUrl, + }); +}); +//# sourceMappingURL=reversegeocode.test.js.map \ No newline at end of file diff --git a/dist/geocode/reversegeocode.test.js.map b/dist/geocode/reversegeocode.test.js.map new file mode 100644 index 0000000000..1a1a3a2d46 --- /dev/null +++ b/dist/geocode/reversegeocode.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"reversegeocode.test.js","sourceRoot":"","sources":["../../src/geocode/reversegeocode.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,kDAA0B;AAC1B,qDAI0B;AAE1B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4CAA4C,EAAE,GAAG,EAAE;IACtD,MAAM,MAAM,GAAG;QACb,MAAM,EAAE;YACN,GAAG,EAAE,SAAS;YACd,GAAG,EAAE,UAAU;SAChB;QACD,GAAG,EAAE,KAAK;KACX,CAAC;IAEF,IAAA,+BAAc,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAEhD,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,wCAAuB;QACzC,GAAG,EAAE,2BAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/geolocate.d.ts b/dist/geolocate.d.ts new file mode 100644 index 0000000000..9fea011458 --- /dev/null +++ b/dist/geolocate.d.ts @@ -0,0 +1,109 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +import { CellTower, LatLngLiteral, RadioType, RequestParams, ResponseData, WifiAccessPoint } from "./common"; +export interface GeolocateRequest extends Partial { + data: { + /** The mobile country code (MCC) for the device's home network. */ + homeMobileCountryCode?: number; + /** The mobile network code (MNC) for the device's home network. */ + homeMobileNetworkCode?: number; + /** The mobile radio type. While this field is optional, it should be included if a value is available, for more accurate results. */ + radioType?: RadioType; + /** The carrier name. */ + carrier?: string; + /** + * Specifies whether to fall back to IP geolocation if wifi and cell tower signals are not available. + * Defaults to `true`. Set `considerIp` to `false` to disable fall back. + */ + considerIp?: boolean; + /** An array of cell tower objects. */ + cellTowers?: CellTower[]; + /** An array of WiFi access point objects. */ + wifiAccessPoints?: WifiAccessPoint[]; + }; + params: RequestParams; +} +export interface GeolocateResponseData extends ResponseData { + /** The user's estimated latitude and longitude, in degrees. Contains one `lat` and one `lng` subfield. */ + location: LatLngLiteral; + /** The accuracy of the estimated location, in meters. This represents the radius of a circle around the given location. */ + accuracy: number; +} +export interface GeolocateResponseSuccess extends AxiosResponse { + data: GeolocateResponseData; +} +/** + * In the case of an error, a standard format error response body will be returned + * and the HTTP status code will be set to an error status. + */ +export interface GeolocateResponseError extends AxiosResponse { + data: { + error: { + /** This is the same as the HTTP status of the response. */ + code: number; + /** A short description of the error. */ + message: string; + /** + * A list of errors which occurred. Each error contains an identifier for the type of error (the `reason`) + * and a short description (the `message`). + */ + errors: { + domain: string; + reason: GeolocateErrorReason; + message: string; + }[]; + }; + }; +} +export declare enum GeolocateErrorReason { + /** + * You have exceeded your daily limit. + * Domain: usageLimits + * Code: 403 + */ + dailyLimitExceeded = "dailyLimitExceeded", + /** + * Your API key is not valid for the Geolocate API. Please ensure that you've included the entire key, + * and that you've either purchased the API or have enabled billing and activated the API to obtain the free quota. + * Domain: usageLimits + * Code: 400 + */ + keyInvalid = "keyInvalid", + /** + * You have exceeded the requests per second per user limit that you configured in the Google Cloud Platform Console. + * This limit should be configured to prevent a single or small group of users from exhausting your daily quota, + * while still allowing reasonable access to all users. + * Domain: usageLimits + * Code: 403 + */ + userRateLimitExceeded = "userRateLimitExceeded", + /** + * The request was valid, but no results were returned. + * Domain: geolocation + * Code: 404 + */ + notFound = "notFound", + /** + * The request body is not valid JSON. Refer to the Request Body section for details on each field. + * Domain: global + * Code: 400 + */ + parseError = "parseError" +} +export type GeolocateResponse = GeolocateResponseSuccess | GeolocateResponseError; +export declare const defaultUrl = "https://www.googleapis.com/geolocation/v1/geolocate"; +export declare function geolocate({ params, method, url, ...config }: GeolocateRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/geolocate.js b/dist/geolocate.js new file mode 100644 index 0000000000..6b03777edf --- /dev/null +++ b/dist/geolocate.js @@ -0,0 +1,76 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.geolocate = exports.defaultUrl = exports.GeolocateErrorReason = void 0; +const client_1 = require("./client"); +var GeolocateErrorReason; +(function (GeolocateErrorReason) { + /** + * You have exceeded your daily limit. + * Domain: usageLimits + * Code: 403 + */ + GeolocateErrorReason["dailyLimitExceeded"] = "dailyLimitExceeded"; + /** + * Your API key is not valid for the Geolocate API. Please ensure that you've included the entire key, + * and that you've either purchased the API or have enabled billing and activated the API to obtain the free quota. + * Domain: usageLimits + * Code: 400 + */ + GeolocateErrorReason["keyInvalid"] = "keyInvalid"; + /** + * You have exceeded the requests per second per user limit that you configured in the Google Cloud Platform Console. + * This limit should be configured to prevent a single or small group of users from exhausting your daily quota, + * while still allowing reasonable access to all users. + * Domain: usageLimits + * Code: 403 + */ + GeolocateErrorReason["userRateLimitExceeded"] = "userRateLimitExceeded"; + /** + * The request was valid, but no results were returned. + * Domain: geolocation + * Code: 404 + */ + GeolocateErrorReason["notFound"] = "notFound"; + /** + * The request body is not valid JSON. Refer to the Request Body section for details on each field. + * Domain: global + * Code: 400 + */ + GeolocateErrorReason["parseError"] = "parseError"; +})(GeolocateErrorReason || (exports.GeolocateErrorReason = GeolocateErrorReason = {})); +exports.defaultUrl = "https://www.googleapis.com/geolocation/v1/geolocate"; +function geolocate(_a, axiosInstance) { + var { params, method = "post", url = exports.defaultUrl } = _a, config = __rest(_a, ["params", "method", "url"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url }, config)); +} +exports.geolocate = geolocate; +//# sourceMappingURL=geolocate.js.map \ No newline at end of file diff --git a/dist/geolocate.js.map b/dist/geolocate.js.map new file mode 100644 index 0000000000..56abee41d1 --- /dev/null +++ b/dist/geolocate.js.map @@ -0,0 +1 @@ +{"version":3,"file":"geolocate.js","sourceRoot":"","sources":["../src/geolocate.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAYH,qCAAgD;AA2DhD,IAAY,oBAkCX;AAlCD,WAAY,oBAAoB;IAC9B;;;;OAIG;IACH,iEAAyC,CAAA;IACzC;;;;;OAKG;IACH,iDAAyB,CAAA;IACzB;;;;;;OAMG;IACH,uEAA+C,CAAA;IAC/C;;;;OAIG;IACH,6CAAqB,CAAA;IACrB;;;;OAIG;IACH,iDAAyB,CAAA;AAC3B,CAAC,EAlCW,oBAAoB,oCAApB,oBAAoB,QAkC/B;AAMY,QAAA,UAAU,GAAG,qDAAqD,CAAC;AAEhF,SAAgB,SAAS,CACvB,EAA0E,EAC1E,aAAmD;QADnD,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,GAAG,kBAAU,OAA+B,EAA1B,MAAM,cAAtD,2BAAwD,CAAF;IACtD,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG,IACA,MAAM,EACqB,CAAC;AACnC,CAAC;AAVD,8BAUC"} \ No newline at end of file diff --git a/dist/geolocate.test.d.ts b/dist/geolocate.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/geolocate.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/geolocate.test.js b/dist/geolocate.test.js new file mode 100644 index 0000000000..165039ba35 --- /dev/null +++ b/dist/geolocate.test.js @@ -0,0 +1,40 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const geolocate_1 = require("./geolocate"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("elevation should call axios correctly", () => { + const params = { key: "foo" }; + const data = { considerIp: false }; + (0, geolocate_1.geolocate)({ params: params, data: data }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "post", + params: params, + data: data, + url: geolocate_1.defaultUrl, + }); +}); +//# sourceMappingURL=geolocate.test.js.map \ No newline at end of file diff --git a/dist/geolocate.test.js.map b/dist/geolocate.test.js.map new file mode 100644 index 0000000000..059e26936e --- /dev/null +++ b/dist/geolocate.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"geolocate.test.js","sourceRoot":"","sources":["../src/geolocate.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,kDAA0B;AAC1B,2CAAoD;AAEpD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IACjD,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IACnC,IAAA,qBAAS,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,WAAW,CAAC,CAAC;IAEvD,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,IAAI;QACV,GAAG,EAAE,sBAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000000..263d87e356 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,33 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { DirectionsRequest, DirectionsResponse, DirectionsResponseData, } from "./directions"; +export { DistanceMatrixRequest, DistanceMatrixResponse, DistanceMatrixResponseData, } from "./distance"; +export { ElevationRequest, ElevationResponse, PositionalElevationParams, SampledPathElevationParams, ElevationResponseData, } from "./elevation"; +export { FindPlaceFromTextRequest, FindPlaceFromTextResponse, FindPlaceFromTextResponseData, } from "./places/findplacefromtext"; +export { GeocodeRequest, GeocodeResponse, GeocodeResponseData, GeocodeComponents, } from "./geocode/geocode"; +export { GeolocateRequest, GeolocateResponse, GeolocateResponseSuccess, GeolocateResponseError, GeolocateResponseData, GeolocateErrorReason, } from "./geolocate"; +export { NearestRoadsRequest, NearestRoadsResponse, } from "./roads/nearestroads"; +export { PlaceAutocompleteRequest, PlaceAutocompleteResponse, PlaceAutocompleteResult, PlaceAutocompleteType, PlaceAutocompleteResponseData, } from "./places/autocomplete"; +export { PlaceDetailsRequest, PlaceDetailsResponse, PlaceDetailsResponseData, } from "./places/details"; +export { PlacePhotoRequest, PlacePhotoResponse } from "./places/photo"; +export { PlaceQueryAutocompleteRequest, PlaceQueryAutocompleteResponse, PlaceQueryAutocompleteResponseData, PlaceQueryAutocompletePrediction, } from "./places/queryautocomplete"; +export { PlacesNearbyRequest, PlacesNearbyResponse, PlacesNearbyResponseData, PlacesNearbyRanking, } from "./places/placesnearby"; +export { ReverseGeocodeRequest, ReverseGeocodeResponse, ReverseGeocodeResponseData, ReverseGeocodingLocationType, } from "./geocode/reversegeocode"; +export { SnapToRoadsRequest, SnapToRoadsResponse } from "./roads/snaptoroads"; +export { TextSearchRequest, TextSearchResponse, TextSearchResponseData, } from "./places/textsearch"; +export { TimeZoneRequest, TimeZoneResponse, TimeZoneResponseData, } from "./timezone"; +export * from "./common"; +export * from "./client"; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000000..88a082ba2d --- /dev/null +++ b/dist/index.js @@ -0,0 +1,43 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +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 __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ReverseGeocodingLocationType = exports.PlacesNearbyRanking = exports.PlaceAutocompleteType = exports.GeolocateErrorReason = void 0; +var geolocate_1 = require("./geolocate"); +Object.defineProperty(exports, "GeolocateErrorReason", { enumerable: true, get: function () { return geolocate_1.GeolocateErrorReason; } }); +var autocomplete_1 = require("./places/autocomplete"); +Object.defineProperty(exports, "PlaceAutocompleteType", { enumerable: true, get: function () { return autocomplete_1.PlaceAutocompleteType; } }); +var placesnearby_1 = require("./places/placesnearby"); +Object.defineProperty(exports, "PlacesNearbyRanking", { enumerable: true, get: function () { return placesnearby_1.PlacesNearbyRanking; } }); +var reversegeocode_1 = require("./geocode/reversegeocode"); +Object.defineProperty(exports, "ReverseGeocodingLocationType", { enumerable: true, get: function () { return reversegeocode_1.ReverseGeocodingLocationType; } }); +__exportStar(require("./common"), exports); +__exportStar(require("./client"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map new file mode 100644 index 0000000000..043d82768d --- /dev/null +++ b/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;AA8BH,yCAOqB;AADnB,iHAAA,oBAAoB,OAAA;AAMtB,sDAM+B;AAF7B,qHAAA,qBAAqB,OAAA;AAevB,sDAK+B;AAD7B,mHAAA,mBAAmB,OAAA;AAErB,2DAKkC;AADhC,8HAAA,4BAA4B,OAAA;AAc9B,2CAAyB;AACzB,2CAAyB"} \ No newline at end of file diff --git a/dist/index.test.d.ts b/dist/index.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/index.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/index.test.js b/dist/index.test.js new file mode 100644 index 0000000000..02877e2b66 --- /dev/null +++ b/dist/index.test.js @@ -0,0 +1,22 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +const _1 = require("."); +test("version exists and is string", () => { + expect(typeof _1.version).toBe("string"); +}); +//# sourceMappingURL=index.test.js.map \ No newline at end of file diff --git a/dist/index.test.js.map b/dist/index.test.js.map new file mode 100644 index 0000000000..b6e8d691f9 --- /dev/null +++ b/dist/index.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAEH,wBAA4B;AAE5B,IAAI,CAAC,8BAA8B,EAAE,GAAG,EAAE;IACxC,MAAM,CAAC,OAAO,UAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/places/autocomplete.d.ts b/dist/places/autocomplete.d.ts new file mode 100644 index 0000000000..cde78b0370 --- /dev/null +++ b/dist/places/autocomplete.d.ts @@ -0,0 +1,155 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AddressType, LatLng, PredictionSubstring, PredictionTerm, RequestParams, ResponseData, StructuredFormatting } from "../common"; +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +export declare enum PlaceAutocompleteType { + /** + * instructs the Place Autocomplete service to return only geocoding results, rather than business results. + * Generally, you use this request to disambiguate results where the location specified may be indeterminate. + */ + geocode = "geocode", + /** + * instructs the Place Autocomplete service to return only geocoding results with a precise address. + * Generally, you use this request when you know the user will be looking for a fully specified address. + */ + address = "address", + /** instructs the Place Autocomplete service to return only business results. */ + establishment = "establishment", + /** + * the `(regions)` type collection instructs the Places service to return any result matching the following types: + * - `locality` + * - `sublocality` + * - `postal_code` + * - `country` + * - `administrative_area_level_1` + * - `administrative_area_level_2` + */ + regions = "(regions)", + /** the (cities) type collection instructs the Places service to return results that match `locality` or `administrative_area_level_3`. */ + cities = "(cities)" +} +export interface PlaceAutocompleteRequest extends Partial { + params: { + /** + * The text string on which to search. The Place Autocomplete service will return candidate matches + * based on this string and order results based on their perceived relevance. + */ + input: string; + /** + * A random string which identifies an autocomplete + * [session](https://developers.google.com/places/web-service/autocomplete#session_tokens) for billing purposes. + * If this parameter is omitted from an autocomplete request, the request is billed independently + */ + sessiontoken?: string; + /** + * The position, in the input term, of the last character that the service uses to match predictions. + * For example, if the input is 'Google' and the `offset` is 3, the service will match on 'Goo'. + * The string determined by the `offset` is matched against the first word in the input term only. + * For example, if the input term is 'Google abc' and the offset is 3, the service will attempt to match against 'Goo abc'. + * If no `offset` is supplied, the service will use the whole term. + * The `offset` should generally be set to the position of the text caret. + */ + offset?: number; + /** + * The origin point from which to calculate straight-line distance to the destination (returned as distance_meters). + * If this value is omitted, straight-line distance will not be returned. + */ + origin?: LatLng; + /** The point around which you wish to retrieve place information. */ + location?: LatLng; + /** + * The distance (in meters) within which to return place results. Note that setting a radius biases results to the indicated area, + * but may not fully restrict results to the specified area. + */ + radius?: number; + /** + * The language code, indicating in which language the results should be returned, if possible. + * Searches are also biased to the selected language; results in the selected language may be given a higher ranking. + * See the list of supported languages and their codes. + * Note that we often update supported languages so this list may not be exhaustive. + * If language is not supplied, the Place Autocomplete service will attempt to use the native language + * of the domain from which the request is sent. + */ + language?: string; + /** The types of place results to return. */ + types?: PlaceAutocompleteType; + /** + * A grouping of places to which you would like to restrict your results. + * Currently, you can use `components` to filter by up to 5 countries. + * Countries must be passed as a two character, ISO 3166-1 Alpha-2 compatible country code. + * For example: `components=country:fr` would restrict your results to places within France. + * Multiple countries must be passed as multiple `country:XX` filters, with the pipe character (`|`) as a separator. + * For example: `components=country:us|country:pr|country:vi|country:gu|country:mp` would restrict your results + * to places within the United States and its unincorporated organized territories. + */ + components?: string[]; + /** + * Returns only those places that are strictly within the region defined by `location` and `radius`. + * This is a restriction, rather than a bias, meaning that results outside this region + * will not be returned even if they match the user input. + */ + strictbounds?: boolean; + } & RequestParams; +} +export interface PlaceAutocompleteResult { + /** + * contains the human-readable name for the returned result. + * For `establishment` results, this is usually the business name. + */ + description: string; + /** + * contains an integer indicating the straight-line distance between the predicted place, and the specified origin point, in meters. + * This field is only returned when the origin point is specified in the request. + * This field is not returned in predictions of type route. + */ + distance_meters?: number; + /** + * is a textual identifier that uniquely identifies a place. + * To retrieve information about the place, pass this identifier in the `placeId` field of a Places API request. + */ + place_id: string; + /** + * contains an array of terms identifying each section of the returned description + * (a section of the description is generally terminated with a comma). + */ + terms: PredictionTerm[]; + /** + * contains an array of types that apply to this place. + * For example: `[ "political", "locality" ]` or `[ "establishment", "geocode" ]`. + */ + types: AddressType[]; + /** + * contains an array with `offset` value and `length`. These describe the location of + * the entered term in the prediction result text, so that the term can be highlighted if desired. + */ + matched_substrings: PredictionSubstring[]; + /** contains details on the prediction. */ + structured_formatting: StructuredFormatting; +} +export interface PlaceAutocompleteResponseData extends ResponseData { + /** + * contains an array of places, with information about the place. + * See [Place Autocomplete Results](https://developers.google.com/places/web-service/autocomplete#place_autocomplete_results) + * for information about these results. The Places API returns up to 5 results. + */ + predictions: PlaceAutocompleteResult[]; +} +export interface PlaceAutocompleteResponse extends AxiosResponse { + data: PlaceAutocompleteResponseData; +} +export declare const defaultUrl = "https://maps.googleapis.com/maps/api/place/autocomplete/json"; +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function placeAutocomplete({ params, method, url, paramsSerializer, ...config }: PlaceAutocompleteRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/places/autocomplete.js b/dist/places/autocomplete.js new file mode 100644 index 0000000000..b4486f42d1 --- /dev/null +++ b/dist/places/autocomplete.js @@ -0,0 +1,73 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.placeAutocomplete = exports.defaultParamsSerializer = exports.defaultUrl = exports.PlaceAutocompleteType = void 0; +const serialize_1 = require("../serialize"); +const client_1 = require("../client"); +var PlaceAutocompleteType; +(function (PlaceAutocompleteType) { + /** + * instructs the Place Autocomplete service to return only geocoding results, rather than business results. + * Generally, you use this request to disambiguate results where the location specified may be indeterminate. + */ + PlaceAutocompleteType["geocode"] = "geocode"; + /** + * instructs the Place Autocomplete service to return only geocoding results with a precise address. + * Generally, you use this request when you know the user will be looking for a fully specified address. + */ + PlaceAutocompleteType["address"] = "address"; + /** instructs the Place Autocomplete service to return only business results. */ + PlaceAutocompleteType["establishment"] = "establishment"; + /** + * the `(regions)` type collection instructs the Places service to return any result matching the following types: + * - `locality` + * - `sublocality` + * - `postal_code` + * - `country` + * - `administrative_area_level_1` + * - `administrative_area_level_2` + */ + PlaceAutocompleteType["regions"] = "(regions)"; + /** the (cities) type collection instructs the Places service to return results that match `locality` or `administrative_area_level_3`. */ + PlaceAutocompleteType["cities"] = "(cities)"; +})(PlaceAutocompleteType || (exports.PlaceAutocompleteType = PlaceAutocompleteType = {})); +exports.defaultUrl = "https://maps.googleapis.com/maps/api/place/autocomplete/json"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({ + location: serialize_1.latLngToString, + origin: serialize_1.latLngToString, +}, exports.defaultUrl); +function placeAutocomplete(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.placeAutocomplete = placeAutocomplete; +//# sourceMappingURL=autocomplete.js.map \ No newline at end of file diff --git a/dist/places/autocomplete.js.map b/dist/places/autocomplete.js.map new file mode 100644 index 0000000000..763183cb36 --- /dev/null +++ b/dist/places/autocomplete.js.map @@ -0,0 +1 @@ +{"version":3,"file":"autocomplete.js","sourceRoot":"","sources":["../../src/places/autocomplete.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAYH,4CAA0D;AAE1D,sCAAiD;AAEjD,IAAY,qBAyBX;AAzBD,WAAY,qBAAqB;IAC/B;;;OAGG;IACH,4CAAmB,CAAA;IACnB;;;OAGG;IACH,4CAAmB,CAAA;IACnB,gFAAgF;IAChF,wDAA+B,CAAA;IAC/B;;;;;;;;OAQG;IACH,8CAAqB,CAAA;IACrB,0IAA0I;IAC1I,4CAAmB,CAAA;AACrB,CAAC,EAzBW,qBAAqB,qCAArB,qBAAqB,QAyBhC;AAmHY,QAAA,UAAU,GACrB,8DAA8D,CAAC;AAEpD,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAC/C;IACE,QAAQ,EAAE,0BAAc;IACxB,MAAM,EAAE,0BAAc;CACvB,EACD,kBAAU,CACX,CAAC;AAEF,SAAgB,iBAAiB,CAC/B,EAM2B,EAC3B,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAEjB,EADtB,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EAC6B,CAAC;AAC3C,CAAC;AAjBD,8CAiBC"} \ No newline at end of file diff --git a/dist/places/autocomplete.test.d.ts b/dist/places/autocomplete.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/places/autocomplete.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/places/autocomplete.test.js b/dist/places/autocomplete.test.js new file mode 100644 index 0000000000..8e75780927 --- /dev/null +++ b/dist/places/autocomplete.test.js @@ -0,0 +1,39 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const autocomplete_1 = require("./autocomplete"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("autocomplete should call axios correctly", () => { + const params = { input: "Seattle", sessiontoken: "asdf", key: "foo" }; + (0, autocomplete_1.placeAutocomplete)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: autocomplete_1.defaultParamsSerializer, + url: autocomplete_1.defaultUrl, + }); +}); +//# sourceMappingURL=autocomplete.test.js.map \ No newline at end of file diff --git a/dist/places/autocomplete.test.js.map b/dist/places/autocomplete.test.js.map new file mode 100644 index 0000000000..c518b88b0b --- /dev/null +++ b/dist/places/autocomplete.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"autocomplete.test.js","sourceRoot":"","sources":["../../src/places/autocomplete.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,kDAA0B;AAC1B,iDAIwB;AAExB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACpD,MAAM,MAAM,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAEtE,IAAA,gCAAiB,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAEnD,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,sCAAuB;QACzC,GAAG,EAAE,yBAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/places/details.d.ts b/dist/places/details.d.ts new file mode 100644 index 0000000000..c2c4fd75c0 --- /dev/null +++ b/dist/places/details.d.ts @@ -0,0 +1,62 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +import { Language, Place, RequestParams, ResponseData } from "../common"; +export interface PlaceDetailsRequest extends Partial { + params: { + /** A textual identifier that uniquely identifies a place, returned from a Place Search. */ + place_id: string; + /** + * The language code, indicating in which language the results should be returned, if possible. + * Note that some fields may not be available in the requested language. + * Note that we often update supported languages so this list may not be exhaustive. + */ + language?: Language; + /** + * The region code, specified as a ccTLD (country code top-level domain) two-character value. + * Most ccTLD codes are identical to ISO 3166-1 codes, with some exceptions. + * This parameter will only influence, not fully restrict, results. + * If more relevant results exist outside of the specified region, they may be included. + * When this parameter is used, the country name is omitted from the resulting `formatted_address` + * for results in the specified region. + */ + region?: string; + /** + * A random string which identifies an autocomplete session for billing purposes. + * Use this for Place Details requests that are called following an autocomplete request in the same user session + */ + sessiontoken?: string; + /** + * One or more fields, specifying the types of place data to return, separated by a comma. + * + * **Warning: If you do not specify at least one field with a request, or if you omit the **fields** + * parameter from a request, ALL possible fields will be returned, and you will be billed accordingly. + * This applies only to Place Details requests. + */ + fields?: string[]; + } & RequestParams; +} +export interface PlaceDetailsResponseData extends ResponseData { + result: Place; + /** contains a set of attributions about this listing which must be displayed to the user. */ + html_attributions: string[]; +} +export interface PlaceDetailsResponse extends AxiosResponse { + data: PlaceDetailsResponseData; +} +export declare const defaultUrl = "https://maps.googleapis.com/maps/api/place/details/json"; +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function placeDetails({ params, method, url, paramsSerializer, ...config }: PlaceDetailsRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/places/details.js b/dist/places/details.js new file mode 100644 index 0000000000..3050227049 --- /dev/null +++ b/dist/places/details.js @@ -0,0 +1,45 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.placeDetails = exports.defaultParamsSerializer = exports.defaultUrl = void 0; +const client_1 = require("../client"); +const serialize_1 = require("../serialize"); +exports.defaultUrl = "https://maps.googleapis.com/maps/api/place/details/json"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({}, exports.defaultUrl, { + arrayFormat: "comma", +}); +function placeDetails(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.placeDetails = placeDetails; +//# sourceMappingURL=details.js.map \ No newline at end of file diff --git a/dist/places/details.js.map b/dist/places/details.js.map new file mode 100644 index 0000000000..20501d6c07 --- /dev/null +++ b/dist/places/details.js.map @@ -0,0 +1 @@ +{"version":3,"file":"details.js","sourceRoot":"","sources":["../../src/places/details.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAKH,sCAAiD;AACjD,4CAA0C;AA8C7B,QAAA,UAAU,GACrB,yDAAyD,CAAC;AAE/C,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAAC,EAAE,EAAE,kBAAU,EAAE;IAChE,WAAW,EAAE,OAAO;CACrB,CAAC,CAAC;AAEH,SAAgB,YAAY,CAC1B,EAMsB,EACtB,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAEtB,EADjB,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EACwB,CAAC;AACtC,CAAC;AAjBD,oCAiBC"} \ No newline at end of file diff --git a/dist/places/details.test.d.ts b/dist/places/details.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/places/details.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/places/details.test.js b/dist/places/details.test.js new file mode 100644 index 0000000000..24d23bf8ef --- /dev/null +++ b/dist/places/details.test.js @@ -0,0 +1,43 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const details_1 = require("./details"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("autocomplete should call axios correctly", () => { + const params = { + place_id: "notarealid", + key: "foo", + fields: ["place_id", "name"], + }; + (0, details_1.placeDetails)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: details_1.defaultParamsSerializer, + url: details_1.defaultUrl, + }); +}); +//# sourceMappingURL=details.test.js.map \ No newline at end of file diff --git a/dist/places/details.test.js.map b/dist/places/details.test.js.map new file mode 100644 index 0000000000..f3c9037830 --- /dev/null +++ b/dist/places/details.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"details.test.js","sourceRoot":"","sources":["../../src/places/details.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,kDAA0B;AAC1B,uCAA8E;AAE9E,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACpD,MAAM,MAAM,GAAG;QACb,QAAQ,EAAE,YAAY;QACtB,GAAG,EAAE,KAAK;QACV,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC;KAC7B,CAAC;IAEF,IAAA,sBAAY,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAE9C,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,iCAAuB;QACzC,GAAG,EAAE,oBAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/places/findplacefromtext.d.ts b/dist/places/findplacefromtext.d.ts new file mode 100644 index 0000000000..eab05f96ed --- /dev/null +++ b/dist/places/findplacefromtext.d.ts @@ -0,0 +1,50 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { Language, ResponseData, Place, PlaceInputType, RequestParams } from "../common"; +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +export interface FindPlaceFromTextRequest extends Partial { + params: { + /** The text input specifying which place to search for (for example, a name, address, or phone number). */ + input: string; + /** The type of input. This can be one of either `textQuery` or `phoneNumber`. */ + inputtype: PlaceInputType; + /** + * The language code, indicating in which language the results should be returned, if possible. + * Searches are also biased to the selected language; results in the selected language may be given a higher ranking + */ + language?: Language; + /** + * The fields specifying the types of place data to return. + * + * **Note:** If you omit the fields parameter from a Find Place request, only the place_id for the result will be returned. + */ + fields?: string[]; + /** + * Prefer results in a specified area, by specifying either a radius plus lat/lng, or two lat/lng pairs representing + * the points of a rectangle. If this parameter is not specified, the API uses IP address biasing by default. + */ + locationbias?: string; + } & RequestParams; +} +export interface FindPlaceFromTextResponseData extends ResponseData { + candidates: Place[]; +} +export interface FindPlaceFromTextResponse extends AxiosResponse { + data: FindPlaceFromTextResponseData; +} +export declare const defaultUrl = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json"; +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function findPlaceFromText({ params, method, url, paramsSerializer, ...config }: FindPlaceFromTextRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/places/findplacefromtext.js b/dist/places/findplacefromtext.js new file mode 100644 index 0000000000..25c4456d10 --- /dev/null +++ b/dist/places/findplacefromtext.js @@ -0,0 +1,45 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.findPlaceFromText = exports.defaultParamsSerializer = exports.defaultUrl = void 0; +const client_1 = require("../client"); +const serialize_1 = require("../serialize"); +exports.defaultUrl = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({}, exports.defaultUrl, { + arrayFormat: "comma", +}); +function findPlaceFromText(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.findPlaceFromText = findPlaceFromText; +//# sourceMappingURL=findplacefromtext.js.map \ No newline at end of file diff --git a/dist/places/findplacefromtext.js.map b/dist/places/findplacefromtext.js.map new file mode 100644 index 0000000000..aafa66d3d2 --- /dev/null +++ b/dist/places/findplacefromtext.js.map @@ -0,0 +1 @@ +{"version":3,"file":"findplacefromtext.js","sourceRoot":"","sources":["../../src/places/findplacefromtext.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAUH,sCAAiD;AACjD,4CAA0C;AAmC7B,QAAA,UAAU,GACrB,mEAAmE,CAAC;AAEzD,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAAC,EAAE,EAAE,kBAAU,EAAE;IAChE,WAAW,EAAE,OAAO;CACrB,CAAC,CAAC;AAEH,SAAgB,iBAAiB,CAC/B,EAM2B,EAC3B,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAEjB,EADtB,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EAC6B,CAAC;AAC3C,CAAC;AAjBD,8CAiBC"} \ No newline at end of file diff --git a/dist/places/findplacefromtext.test.d.ts b/dist/places/findplacefromtext.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/places/findplacefromtext.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/places/findplacefromtext.test.js b/dist/places/findplacefromtext.test.js new file mode 100644 index 0000000000..8f6efd8b0e --- /dev/null +++ b/dist/places/findplacefromtext.test.js @@ -0,0 +1,45 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const findplacefromtext_1 = require("./findplacefromtext"); +const common_1 = require("../common"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("autocomplete should call axios correctly", () => { + const params = { + input: "google", + inputtype: common_1.PlaceInputType.textQuery, + key: "foo", + fields: ["place_id", "name"], + }; + (0, findplacefromtext_1.findPlaceFromText)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: findplacefromtext_1.defaultParamsSerializer, + url: findplacefromtext_1.defaultUrl, + }); +}); +//# sourceMappingURL=findplacefromtext.test.js.map \ No newline at end of file diff --git a/dist/places/findplacefromtext.test.js.map b/dist/places/findplacefromtext.test.js.map new file mode 100644 index 0000000000..3f5f4baa40 --- /dev/null +++ b/dist/places/findplacefromtext.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"findplacefromtext.test.js","sourceRoot":"","sources":["../../src/places/findplacefromtext.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,kDAA0B;AAC1B,2DAI6B;AAC7B,sCAA2C;AAE3C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACpD,MAAM,MAAM,GAAG;QACb,KAAK,EAAE,QAAQ;QACf,SAAS,EAAE,uBAAc,CAAC,SAAS;QACnC,GAAG,EAAE,KAAK;QACV,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC;KAC7B,CAAC;IAEF,IAAA,qCAAiB,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAEnD,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,2CAAuB;QACzC,GAAG,EAAE,8BAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/places/photo.d.ts b/dist/places/photo.d.ts new file mode 100644 index 0000000000..81174c1378 --- /dev/null +++ b/dist/places/photo.d.ts @@ -0,0 +1,57 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +import { RequestParams } from "../common"; +export interface PlacePhotoRequest extends Partial { + params: { + /** + * string identifier that uniquely identifies a photo. + * Photo references are returned from either a Place Search or Place Details request. + */ + photoreference: string; + /** + * Specifies the maximum desired height or width, in pixels, of the image returned by the Place Photos service. + * If the image is smaller than the values specified, the original image will be returned. + * If the image is larger in either dimension, it will be scaled to match the smaller of the two dimensions, + * restricted to its original aspect ratio. Both the `maxheight` and `maxwidth` properties accept an integer between 1 and 1600. + */ + maxwidth?: number; + /** + * Specifies the maximum desired height or width, in pixels, of the image returned by the Place Photos service. + * If the image is smaller than the values specified, the original image will be returned. + * If the image is larger in either dimension, it will be scaled to match the smaller of the two dimensions, + * restricted to its original aspect ratio. Both the `maxheight` and `maxwidth` properties accept an integer between 1 and 1600. + */ + maxheight?: number; + } & RequestParams; + responseType: "arraybuffer" | "blob" | "stream"; +} +/** + * The response of a successful Place Photo request will be an image. + * The type of the image will depend upon the type of the originally submitted photo. + * + * If your request exceeds your available quota, the server will return an HTTP 403 status to indicate that the quota has been exceeded. + * + * If the server is unable to understand your request, it will return HTTP 400 status, which indicates an invalid request. + * + * The most common reasons why you might see an invalid request include: + * - The submitted photo reference was incorrectly specified. + * - Your request did not include either a `maxwidth` or `maxheight` parameter. + */ +export interface PlacePhotoResponse extends AxiosResponse { +} +export declare const defaultUrl = "https://maps.googleapis.com/maps/api/place/photo"; +export declare function placePhoto({ params, method, url, responseType, ...config }: PlacePhotoRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/places/photo.js b/dist/places/photo.js new file mode 100644 index 0000000000..5f98aa323a --- /dev/null +++ b/dist/places/photo.js @@ -0,0 +1,44 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.placePhoto = exports.defaultUrl = void 0; +const client_1 = require("../client"); +exports.defaultUrl = "https://maps.googleapis.com/maps/api/place/photo"; +function placePhoto(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, responseType } = _a, config = __rest(_a, ["params", "method", "url", "responseType"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + if (!responseType) { + responseType = "arraybuffer"; + } + return axiosInstance(Object.assign({ params, + method, + url, + responseType }, config)); +} +exports.placePhoto = placePhoto; +//# sourceMappingURL=photo.js.map \ No newline at end of file diff --git a/dist/places/photo.js.map b/dist/places/photo.js.map new file mode 100644 index 0000000000..6a009d29ea --- /dev/null +++ b/dist/places/photo.js.map @@ -0,0 +1 @@ +{"version":3,"file":"photo.js","sourceRoot":"","sources":["../../src/places/photo.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAIH,sCAAiD;AAyCpC,QAAA,UAAU,GAAG,kDAAkD,CAAC;AAE7E,SAAgB,UAAU,CACxB,EAMoB,EACpB,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,YAAY,OAEM,EADf,MAAM,cALX,2CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,aAAa,CAAC;IAC/B,CAAC;IAED,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,YAAY,IACT,MAAM,EACsB,CAAC;AACpC,CAAC;AArBD,gCAqBC"} \ No newline at end of file diff --git a/dist/places/photo.test.d.ts b/dist/places/photo.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/places/photo.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/places/photo.test.js b/dist/places/photo.test.js new file mode 100644 index 0000000000..408fa1ab45 --- /dev/null +++ b/dist/places/photo.test.js @@ -0,0 +1,51 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const photo_1 = require("./photo"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("photo should call axios correctly", () => { + const params = { photoreference: "notaphotoreference", key: "foo" }; + const responseType = "arraybuffer"; + (0, photo_1.placePhoto)({ params, responseType }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params, + responseType, + url: photo_1.defaultUrl, + }); +}); +test("photo should set default responseType", () => { + const params = { photoreference: "notaphotoreference", key: "foo" }; + (0, photo_1.placePhoto)({ params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params, + responseType: "arraybuffer", + url: photo_1.defaultUrl, + }); +}); +//# sourceMappingURL=photo.test.js.map \ No newline at end of file diff --git a/dist/places/photo.test.js.map b/dist/places/photo.test.js.map new file mode 100644 index 0000000000..dd1bc98fd4 --- /dev/null +++ b/dist/places/photo.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"photo.test.js","sourceRoot":"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nearby.d.ts b/dist/places/placesnearby.d.ts new file mode 100644 index 0000000000..5f190211f8 --- /dev/null +++ b/dist/places/placesnearby.d.ts @@ -0,0 +1,102 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +import { Language, LatLng, Place, RequestParams, ResponseData } from "../common"; +export declare enum PlacesNearbyRanking { + /** + * This option sorts results based on their importance. Ranking will favor prominent places within the specified area. + * Prominence can be affected by a place's ranking in Google's index, global popularity, and other factors. + */ + prominence = "prominence", + /** + * This option biases search results in ascending order by their distance from the specified `location`. + * When distance is specified, one or more of `keyword`, `name`, or `type` is required. + */ + distance = "distance" +} +export interface PlacesNearbyRequest extends Partial { + params: { + /** The latitude/longitude around which to retrieve place information. This must be specified as latitude,longitude. */ + location: LatLng; + /** + * Defines the distance (in meters) within which to return place results. + * The maximum allowed radius is 50 000 meters. + * Note that `radius` must not be included if `rankby=distance` is specified. + */ + radius?: number; + /** + * A term to be matched against all content that Google has indexed for this place, including but not limited to + * name, type, and address, as well as customer reviews and other third-party content. + */ + keyword?: string; + /** + * The language code, indicating in which language the results should be returned, if possible. + * Note that we often update supported languages so this list may not be exhaustive. + */ + language?: Language; + /** + * Restricts results to only those places within the specified range. + * Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. + * The exact amount indicated by a specific value will vary from region to region. + */ + minprice?: number; + /** + * Restricts results to only those places within the specified range. + * Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. + * The exact amount indicated by a specific value will vary from region to region. + */ + maxprice?: number; + /** + * A term to be matched against all content that Google has indexed for this place. + * Equivalent to `keyword`. The `name` field is no longer restricted to place names. + * Values in this field are combined with values in the `keyword` field and passed as part of the same search string. + * We recommend using only the `keyword` parameter for all search terms. + */ + name?: string; + /** + * Returns only those places that are open for business at the time the query is sent. + * Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query. + */ + opennow?: boolean; + /** + * Specifies the order in which results are listed. + * Note that `rankby` must not be included if `radius` is specified. + * + * @default PlacesNearbyRanking.prominence + */ + rankby?: PlacesNearbyRanking; + /** + * Restricts the results to places matching the specified type. + * Only one type may be specified (if more than one type is provided, all types following the first entry are ignored). + */ + type?: string; + /** + * Returns the next 20 results from a previously run search. + * Setting a pagetoken parameter will execute a search with the same parameters used previously — + * all parameters other than pagetoken will be ignored. + */ + pagetoken?: string; + } & RequestParams; +} +export interface PlacesNearbyResponseData extends ResponseData { + results: Place[]; +} +export interface PlacesNearbyResponse extends AxiosResponse { + data: PlacesNearbyResponseData; +} +export declare const defaultUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"; +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function placesNearby({ params, method, url, paramsSerializer, ...config }: PlacesNearbyRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/places/placesnearby.js b/dist/places/placesnearby.js new file mode 100644 index 0000000000..422eb6605e --- /dev/null +++ b/dist/places/placesnearby.js @@ -0,0 +1,56 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.placesNearby = exports.defaultParamsSerializer = exports.defaultUrl = exports.PlacesNearbyRanking = void 0; +const serialize_1 = require("../serialize"); +const client_1 = require("../client"); +var PlacesNearbyRanking; +(function (PlacesNearbyRanking) { + /** + * This option sorts results based on their importance. Ranking will favor prominent places within the specified area. + * Prominence can be affected by a place's ranking in Google's index, global popularity, and other factors. + */ + PlacesNearbyRanking["prominence"] = "prominence"; + /** + * This option biases search results in ascending order by their distance from the specified `location`. + * When distance is specified, one or more of `keyword`, `name`, or `type` is required. + */ + PlacesNearbyRanking["distance"] = "distance"; +})(PlacesNearbyRanking || (exports.PlacesNearbyRanking = PlacesNearbyRanking = {})); +exports.defaultUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({ location: serialize_1.latLngToString }, exports.defaultUrl); +function placesNearby(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.placesNearby = placesNearby; +//# sourceMappingURL=placesnearby.js.map \ No newline at end of file diff --git a/dist/places/placesnearby.js.map b/dist/places/placesnearby.js.map new file mode 100644 index 0000000000..d4ebd4a742 --- /dev/null +++ b/dist/places/placesnearby.js.map @@ -0,0 +1 @@ +{"version":3,"file":"placesnearby.js","sourceRoot":"","sources":["../../src/places/placesnearby.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAUH,4CAA0D;AAE1D,sCAAiD;AAEjD,IAAY,mBAWX;AAXD,WAAY,mBAAmB;IAC7B;;;OAGG;IACH,gDAAyB,CAAA;IACzB;;;OAGG;IACH,4CAAqB,CAAA;AACvB,CAAC,EAXW,mBAAmB,mCAAnB,mBAAmB,QAW9B;AA2EY,QAAA,UAAU,GACrB,8DAA8D,CAAC;AAEpD,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAC/C,EAAE,QAAQ,EAAE,0BAAc,EAAE,EAC5B,kBAAU,CACX,CAAC;AAEF,SAAgB,YAAY,CAC1B,EAMsB,EACtB,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAEtB,EADjB,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EACwB,CAAC;AACtC,CAAC;AAjBD,oCAiBC"} \ No newline at end of file diff --git a/dist/places/placesnearby.test.d.ts b/dist/places/placesnearby.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/places/placesnearby.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/places/placesnearby.test.js b/dist/places/placesnearby.test.js new file mode 100644 index 0000000000..baf40b67eb --- /dev/null +++ b/dist/places/placesnearby.test.js @@ -0,0 +1,43 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const placesnearby_1 = require("./placesnearby"); +const axios_1 = __importDefault(require("axios")); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("autocomplete should call axios correctly", () => { + const params = { + location: { lat: 35, lng: -110 }, + key: "foo", + ranking: placesnearby_1.PlacesNearbyRanking.distance, + }; + (0, placesnearby_1.placesNearby)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + url: placesnearby_1.defaultUrl, + paramsSerializer: placesnearby_1.defaultParamsSerializer, + }); +}); +//# sourceMappingURL=placesnearby.test.js.map \ No newline at end of file diff --git a/dist/places/placesnearby.test.js.map b/dist/places/placesnearby.test.js.map new file mode 100644 index 0000000000..8380bb30a5 --- /dev/null +++ b/dist/places/placesnearby.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"placesnearby.test.js","sourceRoot":"","sources":["../../src/places/placesnearby.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,iDAKwB;AAExB,kDAA0B;AAE1B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACpD,MAAM,MAAM,GAAG;QACb,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE;QAChC,GAAG,EAAE,KAAK;QACV,OAAO,EAAE,kCAAmB,CAAC,QAAQ;KACtC,CAAC;IAEF,IAAA,2BAAY,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAE9C,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,GAAG,EAAE,yBAAU;QACf,gBAAgB,EAAE,sCAAuB;KAC1C,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/places/queryautocomplete.d.ts b/dist/places/queryautocomplete.d.ts new file mode 100644 index 0000000000..4b9c21aba6 --- /dev/null +++ b/dist/places/queryautocomplete.d.ts @@ -0,0 +1,77 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { LatLng, Language, ResponseData, RequestParams, PredictionTerm, PredictionSubstring, StructuredFormatting } from "../common"; +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +export interface PlaceQueryAutocompleteRequest extends Partial { + params: { + /** + * The text string on which to search. + * The Places service will return candidate matches based on this string and order results based on their perceived relevance. + */ + input: string; + /** + * The character position in the input term at which the service uses text for predictions. + * For example, if the input is 'Googl' and the completion point is 3, the service will match on 'Goo'. + * The offset should generally be set to the position of the text caret. + * If no offset is supplied, the service will use the entire term. + */ + offset?: number; + /** The point around which you wish to retrieve place information. Must be specified as latitude,longitude. */ + location?: LatLng; + /** + * The distance (in meters) within which to return place results. + * Note that setting a radius biases results to the indicated area, but may not fully restrict results to the specified area. + */ + radius?: number; + /** + * The language code, indicating in which language the results should be returned, if possible. + * Searches are also biased to the selected language; results in the selected language may be given a higher ranking. + * If language is not supplied, the Places service will attempt to use the native language of the domain from which the request is sent. + */ + language?: Language; + } & RequestParams; +} +export interface PlaceQueryAutocompletePrediction { + /** contains the human-readable name for the returned result. For establishment results, this is usually the business name. */ + description: string; + /** + * contains an array of terms identifying each section of the returned description + * (a section of the description is generally terminated with a comma). + */ + terms: PredictionTerm[]; + /** + * contains an `offset` value and a `length`. + * These describe the location of the entered term in the prediction result text, so that the term can be highlighted if desired. + */ + matched_substrings: PredictionSubstring[]; + structured_formatting?: StructuredFormatting[]; + place_id?: string; + types?: string[]; +} +export interface PlaceQueryAutocompleteResponseData extends ResponseData { + /** + * contains an array of places, with information about the place. + * See [Place Autocomplete Results](https://developers.google.com/places/web-service/autocomplete#place_autocomplete_results) + * for information about these results. The Places API returns up to 5 results. + */ + predictions: PlaceQueryAutocompletePrediction[]; +} +export interface PlaceQueryAutocompleteResponse extends AxiosResponse { + data: PlaceQueryAutocompleteResponseData; +} +export declare const defaultUrl = "https://maps.googleapis.com/maps/api/place/queryautocomplete/json"; +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function placeQueryAutocomplete({ params, method, url, paramsSerializer, ...config }: PlaceQueryAutocompleteRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/places/queryautocomplete.js b/dist/places/queryautocomplete.js new file mode 100644 index 0000000000..9a102af418 --- /dev/null +++ b/dist/places/queryautocomplete.js @@ -0,0 +1,43 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.placeQueryAutocomplete = exports.defaultParamsSerializer = exports.defaultUrl = void 0; +const client_1 = require("../client"); +const serialize_1 = require("../serialize"); +exports.defaultUrl = "https://maps.googleapis.com/maps/api/place/queryautocomplete/json"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({ location: serialize_1.latLngToString }, exports.defaultUrl); +function placeQueryAutocomplete(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.placeQueryAutocomplete = placeQueryAutocomplete; +//# sourceMappingURL=queryautocomplete.js.map \ No newline at end of file diff --git a/dist/places/queryautocomplete.js.map b/dist/places/queryautocomplete.js.map new file mode 100644 index 0000000000..a1ce9b4537 --- /dev/null +++ b/dist/places/queryautocomplete.js.map @@ -0,0 +1 @@ +{"version":3,"file":"queryautocomplete.js","sourceRoot":"","sources":["../../src/places/queryautocomplete.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAYH,sCAAiD;AACjD,4CAA0D;AAgE7C,QAAA,UAAU,GACrB,mEAAmE,CAAC;AAEzD,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAC/C,EAAE,QAAQ,EAAE,0BAAc,EAAE,EAC5B,kBAAU,CACX,CAAC;AAEF,SAAgB,sBAAsB,CACpC,EAMgC,EAChC,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAEZ,EAD3B,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EACkC,CAAC;AAChD,CAAC;AAjBD,wDAiBC"} \ No newline at end of file diff --git a/dist/places/queryautocomplete.test.d.ts b/dist/places/queryautocomplete.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/places/queryautocomplete.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/places/queryautocomplete.test.js b/dist/places/queryautocomplete.test.js new file mode 100644 index 0000000000..981ccdd41e --- /dev/null +++ b/dist/places/queryautocomplete.test.js @@ -0,0 +1,39 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const queryautocomplete_1 = require("./queryautocomplete"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("autocomplete should call axios correctly", () => { + const params = { input: "Seattle", sessiontoken: "asdf", key: "foo" }; + (0, queryautocomplete_1.placeQueryAutocomplete)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: queryautocomplete_1.defaultParamsSerializer, + url: queryautocomplete_1.defaultUrl, + }); +}); +//# sourceMappingURL=queryautocomplete.test.js.map \ No newline at end of file diff --git a/dist/places/queryautocomplete.test.js.map b/dist/places/queryautocomplete.test.js.map new file mode 100644 index 0000000000..62d7c5b16e --- /dev/null +++ b/dist/places/queryautocomplete.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"queryautocomplete.test.js","sourceRoot":"","sources":["../../src/places/queryautocomplete.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,kDAA0B;AAC1B,2DAI6B;AAE7B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACpD,MAAM,MAAM,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAEtE,IAAA,0CAAsB,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAExD,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,2CAAuB;QACzC,GAAG,EAAE,8BAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/places/textsearch.d.ts b/dist/places/textsearch.d.ts new file mode 100644 index 0000000000..7e20955d8d --- /dev/null +++ b/dist/places/textsearch.d.ts @@ -0,0 +1,93 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { ResponseData, LatLng, Language, PlaceType1, Place, RequestParams } from "../common"; +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +export interface TextSearchRequest extends Partial { + params: { + /** + * The text string on which to search, for example: "restaurant" or "123 Main Street". + * The Google Places service will return candidate matches based on this string and order the results + * based on their perceived relevance. This parameter becomes optional if the `type` parameter + * is also used in the search request. + */ + query: string; + /** + * The region code, specified as a ccTLD (country code top-level domain) two-character value. + * Most ccTLD codes are identical to ISO 3166-1 codes, with some exceptions. + * This parameter will only influence, not fully restrict, search results. + * If more relevant results exist outside of the specified region, they may be included. + * When this parameter is used, the country name is omitted from the resulting `formatted_address` + * for results in the specified region. + */ + region?: string; + /** + * The latitude/longitude around which to retrieve place information. + * This must be specified as latitude,longitude. If you specify a location parameter, + * you must also specify a radius parameter. + */ + location?: LatLng; + /** + * Defines the distance (in meters) within which to bias place results. + * The maximum allowed radius is 50 000 meters. + * Results inside of this region will be ranked higher than results outside of the search circle; + * however, prominent results from outside of the search radius may be included. + */ + radius?: number; + /** + * The language code, indicating in which language the results should be returned, if possible. + * Note that we often update supported languages so this list may not be exhaustive + */ + language?: Language; + /** + * Restricts results to only those places within the specified price level. + * Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive. + * The exact amount indicated by a specific value will vary from region to region. + */ + minprice?: number; + /** + * Restricts results to only those places within the specified price level. + * Valid values are in the range from 0 (most affordable) to 4 (most expensive), inclusive. + * The exact amount indicated by a specific value will vary from region to region. + */ + maxprice?: number; + /** + * Returns only those places that are open for business at the time the query is sent. + * Places that do not specify opening hours in the Google Places database will not be returned + * if you include this parameter in your query. + */ + opennow?: boolean; + /** + * Returns the next 20 results from a previously run search. + * Setting a `pagetoken` parameter will execute a search with the same parameters used previously — + * all parameters other than `pagetoken` will be ignored. + */ + pagetoken?: string; + /** + * Restricts the results to places matching the specified type. + * Only one type may be specified (if more than one type is provided, all types following the first entry are ignored). + */ + type?: PlaceType1; + } & RequestParams; +} +export interface TextSearchResponseData extends ResponseData { + results: Place[]; +} +export interface TextSearchResponse extends AxiosResponse { + data: TextSearchResponseData; +} +export declare const defaultUrl = "https://maps.googleapis.com/maps/api/place/textsearch/json"; +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function textSearch({ params, method, url, paramsSerializer, ...config }: TextSearchRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/places/textsearch.js b/dist/places/textsearch.js new file mode 100644 index 0000000000..7c74738c18 --- /dev/null +++ b/dist/places/textsearch.js @@ -0,0 +1,43 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.textSearch = exports.defaultParamsSerializer = exports.defaultUrl = void 0; +const client_1 = require("../client"); +const serialize_1 = require("../serialize"); +exports.defaultUrl = "https://maps.googleapis.com/maps/api/place/textsearch/json"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({ location: serialize_1.latLngToString }, exports.defaultUrl); +function textSearch(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.textSearch = textSearch; +//# sourceMappingURL=textsearch.js.map \ No newline at end of file diff --git a/dist/places/textsearch.js.map b/dist/places/textsearch.js.map new file mode 100644 index 0000000000..07b9d0c2ae --- /dev/null +++ b/dist/places/textsearch.js.map @@ -0,0 +1 @@ +{"version":3,"file":"textsearch.js","sourceRoot":"","sources":["../../src/places/textsearch.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAWH,sCAAiD;AACjD,4CAA0D;AA8E7C,QAAA,UAAU,GACrB,4DAA4D,CAAC;AAElD,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAC/C,EAAE,QAAQ,EAAE,0BAAc,EAAE,EAC5B,kBAAU,CACX,CAAC;AAEF,SAAgB,UAAU,CACxB,EAMoB,EACpB,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAExB,EADf,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EACsB,CAAC;AACpC,CAAC;AAjBD,gCAiBC"} \ No newline at end of file diff --git a/dist/places/textsearch.test.d.ts b/dist/places/textsearch.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/places/textsearch.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/places/textsearch.test.js b/dist/places/textsearch.test.js new file mode 100644 index 0000000000..11f545cc36 --- /dev/null +++ b/dist/places/textsearch.test.js @@ -0,0 +1,39 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const textsearch_1 = require("./textsearch"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("textsearch should call axios correctly", () => { + const params = { query: "Seattle", key: "foo" }; + (0, textsearch_1.textSearch)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: textsearch_1.defaultParamsSerializer, + url: textsearch_1.defaultUrl, + }); +}); +//# sourceMappingURL=textsearch.test.js.map \ No newline at end of file diff --git a/dist/places/textsearch.test.js.map b/dist/places/textsearch.test.js.map new file mode 100644 index 0000000000..64693f6543 --- /dev/null +++ b/dist/places/textsearch.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"textsearch.test.js","sourceRoot":"","sources":["../../src/places/textsearch.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,kDAA0B;AAC1B,6CAA+E;AAE/E,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,wCAAwC,EAAE,GAAG,EAAE;IAClD,MAAM,MAAM,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAEhD,IAAA,uBAAU,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAE5C,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,oCAAuB;QACzC,GAAG,EAAE,uBAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/roads/nearestroads.d.ts b/dist/roads/nearestroads.d.ts new file mode 100644 index 0000000000..3e4b46d83d --- /dev/null +++ b/dist/roads/nearestroads.d.ts @@ -0,0 +1,36 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { LatLng, SnappedPoint, RequestParams } from "../common"; +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +export interface NearestRoadsRequest extends Partial { + params: { + /** + * A list of latitude/longitude pairs. Latitude and longitude values should be separated by commas. + * Coordinates should be separated by the pipe character: "|". + * For example: `points=60.170880,24.942795|60.170879,24.942796|60.170877,24.942796`. + */ + points: LatLng[]; + } & RequestParams; +} +export interface NearestRoadsResponse extends AxiosResponse { + data: { + /** An array of snapped points. */ + snappedPoints: SnappedPoint[]; + }; +} +export declare const defaultUrl = "https://roads.googleapis.com/v1/nearestRoads"; +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function nearestRoads({ params, method, url, paramsSerializer, ...config }: NearestRoadsRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/roads/nearestroads.js b/dist/roads/nearestroads.js new file mode 100644 index 0000000000..24067b612d --- /dev/null +++ b/dist/roads/nearestroads.js @@ -0,0 +1,45 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.nearestRoads = exports.defaultParamsSerializer = exports.defaultUrl = void 0; +const client_1 = require("../client"); +const serialize_1 = require("../serialize"); +exports.defaultUrl = "https://roads.googleapis.com/v1/nearestRoads"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({ + points: (o) => o.map((latLng) => (0, serialize_1.latLngToString)(latLng)), +}, exports.defaultUrl); +function nearestRoads(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.nearestRoads = nearestRoads; +//# sourceMappingURL=nearestroads.js.map \ No newline at end of file diff --git a/dist/roads/nearestroads.js.map b/dist/roads/nearestroads.js.map new file mode 100644 index 0000000000..2305d0ba72 --- /dev/null +++ b/dist/roads/nearestroads.js.map @@ -0,0 +1 @@ +{"version":3,"file":"nearestroads.js","sourceRoot":"","sources":["../../src/roads/nearestroads.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAIH,sCAAiD;AACjD,4CAA0D;AAoB7C,QAAA,UAAU,GAAG,8CAA8C,CAAC;AAC5D,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAC/C;IACE,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAA,0BAAc,EAAC,MAAM,CAAC,CAAC;CACzD,EACD,kBAAU,CACX,CAAC;AAEF,SAAgB,YAAY,CAC1B,EAMsB,EACtB,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAEtB,EADjB,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EACwB,CAAC;AACtC,CAAC;AAjBD,oCAiBC"} \ No newline at end of file diff --git a/dist/roads/nearestroads.test.d.ts b/dist/roads/nearestroads.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/roads/nearestroads.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/roads/nearestroads.test.js b/dist/roads/nearestroads.test.js new file mode 100644 index 0000000000..2631f6a837 --- /dev/null +++ b/dist/roads/nearestroads.test.js @@ -0,0 +1,43 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const nearestroads_1 = require("./nearestroads"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("nearestRoads should call axios correctly", () => { + const params = { points: ["0,0"], key: "foo" }; + (0, nearestroads_1.nearestRoads)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: nearestroads_1.defaultParamsSerializer, + url: nearestroads_1.defaultUrl, + }); +}); +test("serializer should transform correctly", () => { + const params = { points: ["0,0"], key: "foo" }; + expect((0, nearestroads_1.defaultParamsSerializer)(params)).toEqual("key=foo&points=0%2C0"); +}); +//# sourceMappingURL=nearestroads.test.js.map \ No newline at end of file diff --git a/dist/roads/nearestroads.test.js.map b/dist/roads/nearestroads.test.js.map new file mode 100644 index 0000000000..36f002a551 --- /dev/null +++ b/dist/roads/nearestroads.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"nearestroads.test.js","sourceRoot":"","sources":["../../src/roads/nearestroads.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,kDAA0B;AAC1B,iDAIwB;AAExB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACpD,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAE/C,IAAA,2BAAY,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAE9C,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,sCAAuB;QACzC,GAAG,EAAE,yBAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IACjD,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAE/C,MAAM,CAAC,IAAA,sCAAuB,EAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAC1E,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/roads/snaptoroads.d.ts b/dist/roads/snaptoroads.d.ts new file mode 100644 index 0000000000..d21d732612 --- /dev/null +++ b/dist/roads/snaptoroads.d.ts @@ -0,0 +1,51 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { LatLng, SnappedPoint, RequestParams } from "../common"; +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +export interface SnapToRoadsRequest extends Partial { + params: { + /** + * The path to be snapped. The `path` parameter accepts a list of latitude/longitude pairs. + * Latitude and longitude values should be separated by commas. Coordinates should be separated by the pipe character: `"|"`. + * For example: `path=60.170880,24.942795|60.170879,24.942796|60.170877,24.942796`. + * + * **Note:** The snapping algorithm works best for points that are not too far apart. + * If you observe odd snapping behavior, try creating paths that have points closer together. + * To ensure the best snap-to-road quality, you should aim to provide paths on which consecutive pairs + * of points are within 300m of each other. This will also help in handling any isolated, long jumps between + * consecutive points caused by GPS signal loss, or noise. + */ + path: LatLng[]; + /** + * Whether to interpolate a path to include all points forming the full road-geometry. + * When true, additional interpolated points will also be returned, resulting in a path that smoothly follows + * the geometry of the road, even around corners and through tunnels. + * Interpolated paths will most likely contain more points than the original path. + * + * @default false + */ + interpolate?: boolean; + } & RequestParams; +} +export interface SnapToRoadsResponse extends AxiosResponse { + data: { + /** An array of snapped points. */ + snappedPoints: SnappedPoint[]; + }; +} +export declare const defaultUrl = "https://roads.googleapis.com/v1/snapToRoads"; +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function snapToRoads({ params, method, url, paramsSerializer, ...config }: SnapToRoadsRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/roads/snaptoroads.js b/dist/roads/snaptoroads.js new file mode 100644 index 0000000000..4984a15751 --- /dev/null +++ b/dist/roads/snaptoroads.js @@ -0,0 +1,45 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.snapToRoads = exports.defaultParamsSerializer = exports.defaultUrl = void 0; +const client_1 = require("../client"); +const serialize_1 = require("../serialize"); +exports.defaultUrl = "https://roads.googleapis.com/v1/snapToRoads"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({ + path: (o) => o.map(serialize_1.latLngToString), +}, exports.defaultUrl); +function snapToRoads(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.snapToRoads = snapToRoads; +//# sourceMappingURL=snaptoroads.js.map \ No newline at end of file diff --git a/dist/roads/snaptoroads.js.map b/dist/roads/snaptoroads.js.map new file mode 100644 index 0000000000..5641894b05 --- /dev/null +++ b/dist/roads/snaptoroads.js.map @@ -0,0 +1 @@ +{"version":3,"file":"snaptoroads.js","sourceRoot":"","sources":["../../src/roads/snaptoroads.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAIH,sCAAiD;AACjD,4CAA0D;AAkC7C,QAAA,UAAU,GAAG,6CAA6C,CAAC;AAC3D,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAC/C;IACE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,0BAAc,CAAC;CACnC,EACD,kBAAU,CACX,CAAC;AAEF,SAAgB,WAAW,CACzB,EAMqB,EACrB,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAEvB,EADhB,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EACuB,CAAC;AACrC,CAAC;AAjBD,kCAiBC"} \ No newline at end of file diff --git a/dist/roads/snaptoroads.test.d.ts b/dist/roads/snaptoroads.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/roads/snaptoroads.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/roads/snaptoroads.test.js b/dist/roads/snaptoroads.test.js new file mode 100644 index 0000000000..f49af0f972 --- /dev/null +++ b/dist/roads/snaptoroads.test.js @@ -0,0 +1,43 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const axios_1 = __importDefault(require("axios")); +const snaptoroads_1 = require("./snaptoroads"); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("snapToRoads should call axios correctly", () => { + const params = { path: ["0,0"], key: "foo" }; + (0, snaptoroads_1.snapToRoads)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: snaptoroads_1.defaultParamsSerializer, + url: snaptoroads_1.defaultUrl, + }); +}); +test("serializer should transform correctly", () => { + const params = { path: ["0,0"], key: "foo" }; + expect((0, snaptoroads_1.defaultParamsSerializer)(params)).toEqual("key=foo&path=0%2C0"); +}); +//# sourceMappingURL=snaptoroads.test.js.map \ No newline at end of file diff --git a/dist/roads/snaptoroads.test.js.map b/dist/roads/snaptoroads.test.js.map new file mode 100644 index 0000000000..e16dd0a596 --- /dev/null +++ b/dist/roads/snaptoroads.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"snaptoroads.test.js","sourceRoot":"","sources":["../../src/roads/snaptoroads.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,kDAA0B;AAC1B,+CAIuB;AAEvB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACnD,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAE7C,IAAA,yBAAW,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAE7C,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,qCAAuB;QACzC,GAAG,EAAE,wBAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IACjD,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IAE7C,MAAM,CAAC,IAAA,qCAAuB,EAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;AACxE,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/serialize.d.ts b/dist/serialize.d.ts new file mode 100644 index 0000000000..3c6393c6a8 --- /dev/null +++ b/dist/serialize.d.ts @@ -0,0 +1,30 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { LatLng, LatLngBounds, LatLngLiteral } from "./common"; +export declare function latLngToString(o: LatLng): string; +export declare function objectToString(o: string | object): string; +export declare function latLngBoundsToString(latLngBounds: string | LatLngBounds): string; +export declare function toLatLngLiteral(o: LatLng): LatLngLiteral; +export declare function latLngArrayToStringMaybeEncoded(o: string | LatLng[]): string; +export type serializerFunction = (any: any) => string | number | boolean; +export type serializerFormat = { + [key: string]: serializerFunction; +}; +export declare function serializer(format: serializerFormat, baseUrl: string, queryStringOptions?: object): (params: Record) => string; +export declare function toTimestamp(o: "now" | number | Date): number | "now"; +export declare function createPremiumPlanQueryString(serializedParams: { + [key: string]: string; +}, queryStringOptions: object, baseUrl: string): string; diff --git a/dist/serialize.js b/dist/serialize.js new file mode 100644 index 0000000000..3a6750a8ab --- /dev/null +++ b/dist/serialize.js @@ -0,0 +1,148 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createPremiumPlanQueryString = exports.toTimestamp = exports.serializer = exports.latLngArrayToStringMaybeEncoded = exports.toLatLngLiteral = exports.latLngBoundsToString = exports.objectToString = exports.latLngToString = void 0; +const util_1 = require("./util"); +const url_signature_1 = require("@googlemaps/url-signature"); +const query_string_1 = __importDefault(require("query-string")); +const qs = query_string_1.default.stringify; +const separator = "|"; +function latLngToString(o) { + if (typeof o === "string") { + return o; + } + else if (Array.isArray(o) && o.length === 2) { + // no transformation + } + else if ("lat" in o && "lng" in o) { + o = [o.lat, o.lng]; + } + else if ("latitude" in o && "longitude" in o) { + o = [o.latitude, o.longitude]; + } + else { + throw new TypeError(); + } + return o + .map((x) => { + return x.toString(); + }) + .join(","); +} +exports.latLngToString = latLngToString; +function objectToString(o) { + if (typeof o === "string") { + return o; + } + else { + const keys = Object.keys(o); + keys.sort(); + return keys.map((k) => k + ":" + o[k]).join(separator); + } +} +exports.objectToString = objectToString; +function latLngBoundsToString(latLngBounds) { + if (typeof latLngBounds === "string") { + return latLngBounds; + } + else { + return (latLngToString(latLngBounds.southwest) + + separator + + latLngToString(latLngBounds.northeast)); + } +} +exports.latLngBoundsToString = latLngBoundsToString; +function toLatLngLiteral(o) { + if (typeof o === "string") { + const parts = o.split(",").map(Number); + return { lat: parts[0], lng: parts[1] }; + } + else if (Array.isArray(o) && o.length === 2) { + const parts = o.map(Number); + return { lat: parts[0], lng: parts[1] }; + } + else if ("lat" in o && "lng" in o) { + return o; + } + else if ("latitude" in o && "longitude" in o) { + return { lat: o.latitude, lng: o.longitude }; + } + else { + throw new TypeError(); + } +} +exports.toLatLngLiteral = toLatLngLiteral; +function latLngArrayToStringMaybeEncoded(o) { + if (typeof o === "string") { + return o; + } + const concatenated = o.map(latLngToString).join(separator); + const encoded = `enc:${(0, util_1.encodePath)(o.map(toLatLngLiteral))}`; + if (encoded.length < concatenated.length) { + return encoded; + } + return concatenated; +} +exports.latLngArrayToStringMaybeEncoded = latLngArrayToStringMaybeEncoded; +function serializer(format, baseUrl, queryStringOptions = { + arrayFormat: "separator", + arrayFormatSeparator: separator, +}) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (params) => { + // avoid mutating params + const serializedParams = Object.assign({}, params); + for (const key of Object.keys(format)) { + if (key in serializedParams) { + serializedParams[key] = format[key](serializedParams[key]); + } + } + if ("client_id" in serializedParams && + "client_secret" in serializedParams) { + // Special case to handle premium plan signature + return createPremiumPlanQueryString(serializedParams, queryStringOptions, baseUrl); + } + return qs(serializedParams, queryStringOptions); + }; +} +exports.serializer = serializer; +function toTimestamp(o) { + if (o === "now") { + return o; + } + if (o instanceof Date) { + return Math.round(Number(o) / 1000); + } + return o; +} +exports.toTimestamp = toTimestamp; +function createPremiumPlanQueryString(serializedParams, queryStringOptions, baseUrl) { + serializedParams.client = serializedParams.client_id; + const clientSecret = serializedParams.client_secret; + delete serializedParams.client_id; + delete serializedParams.client_secret; + const partialQueryString = qs(serializedParams, queryStringOptions); + const unsignedUrl = `${baseUrl}?${partialQueryString}`; + const signature = (0, url_signature_1.createSignature)(unsignedUrl, clientSecret); + // The signature must come last + return `${partialQueryString}&signature=${signature}`; +} +exports.createPremiumPlanQueryString = createPremiumPlanQueryString; +//# sourceMappingURL=serialize.js.map \ No newline at end of file diff --git a/dist/serialize.js.map b/dist/serialize.js.map new file mode 100644 index 0000000000..1262a2beab --- /dev/null +++ b/dist/serialize.js.map @@ -0,0 +1 @@ +{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;AAIH,iCA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QAED,OAAO,EAAE,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC;AAjCD,gCAiCC;AAED,SAAgB,WAAW,CAAC,CAAwB;IAClD,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,CAAC;IACX,CAAC;IACD,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AARD,kCAQC;AAED,SAAgB,4BAA4B,CAC1C,gBAA2C,EAC3C,kBAA0B,EAC1B,OAAe;IAEf,gBAAgB,CAAC,MAAM,GAAG,gBAAgB,CAAC,SAAS,CAAC;IACrD,MAAM,YAAY,GAAG,gBAAgB,CAAC,aAAa,CAAC;IACpD,OAAO,gBAAgB,CAAC,SAAS,CAAC;IAClC,OAAO,gBAAgB,CAAC,aAAa,CAAC;IAEtC,MAAM,kBAAkB,GAAG,EAAE,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;IACpE,MAAM,WAAW,GAAG,GAAG,OAAO,IAAI,kBAAkB,EAAE,CAAC;IACvD,MAAM,SAAS,GAAG,IAAA,+BAAe,EAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IAE7D,+BAA+B;IAC/B,OAAO,GAAG,kBAAkB,cAAc,SAAS,EAAE,CAAC;AACxD,CAAC;AAhBD,oEAgBC"} \ No newline at end of file diff --git a/dist/serialize.test.d.ts b/dist/serialize.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/serialize.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/serialize.test.js b/dist/serialize.test.js new file mode 100644 index 0000000000..c60b945435 --- /dev/null +++ b/dist/serialize.test.js @@ -0,0 +1,131 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +const serialize_1 = require("./serialize"); +test("latLngToString is correct", () => { + expect((0, serialize_1.latLngToString)("")).toBe(""); + expect((0, serialize_1.latLngToString)("10,20")).toBe("10,20"); + expect((0, serialize_1.latLngToString)([10, 20])).toBe("10,20"); + expect((0, serialize_1.latLngToString)({ lat: 10, lng: 20 })).toBe("10,20"); + expect((0, serialize_1.latLngToString)({ latitude: 10, longitude: 20 })).toBe("10,20"); + expect(() => { + (0, serialize_1.latLngToString)({}); + }).toThrow(TypeError); +}); +test("latLngBoundsToString is correct", () => { + expect((0, serialize_1.latLngBoundsToString)("")).toBe(""); + expect((0, serialize_1.latLngBoundsToString)({ + southwest: { lat: 1, lng: 2 }, + northeast: { lat: 3, lng: 4 }, + })).toBe("1,2|3,4"); +}); +test("serializer", () => { + expect((0, serialize_1.serializer)({ quz: (o) => o }, "http://mock.url")({ foo: ["bar"] })).toBe("foo=bar"); + expect((0, serialize_1.serializer)({ + foo: (o) => o.map((latLng) => (0, serialize_1.latLngToString)(latLng)), + }, "http://mock.url")({ + foo: [ + [0, 1], + [2, 3], + ], + })).toBe("foo=0%2C1|2%2C3"); +}); +test("serializer should not mutate params", () => { + const location = { lat: 0, lng: 1 }; + const params = { + location, + }; + (0, serialize_1.serializer)({ location: serialize_1.latLngToString }, "http://mock.url")(params); + expect(params.location).toBe(location); +}); +test("serializer should return pipe joined arrays by default", () => { + expect((0, serialize_1.serializer)({}, "http://mock.url")({ foo: ["b", "a", "r"] })).toBe("foo=b|a|r"); +}); +test("serializer creates premium plan query string if premium plan params are included", () => { + const params = { + avoid: "ferries", + destination: { + lat: "38.8977", + lng: "-77.0365", + }, + mode: "driving", + origin: { + lat: "33.8121", + lng: "-117.9190", + }, + units: "imperial", + client_id: "testClient", + client_secret: "testClientSecret", + }; + expect((0, serialize_1.serializer)({ + origin: serialize_1.latLngToString, + destination: serialize_1.latLngToString, + }, "https://test.url/maps/api/directions/json")(params)).toEqual("avoid=ferries&client=testClient&destination=38.8977%2C-77.0365&mode=driving&origin=33.8121%2C-117.9190&units=imperial&signature=YRJoTd6ohbpsR14WkWv3S7H6MqU="); +}); +test("objectToString", () => { + expect((0, serialize_1.objectToString)("foo")).toBe("foo"); + expect((0, serialize_1.objectToString)({ c: "c", a: "a", b: "b" })).toBe("a:a|b:b|c:c"); +}); +test("latLngArrayToStringMaybeEncoded", () => { + expect((0, serialize_1.latLngArrayToStringMaybeEncoded)("0,0")).toEqual("0,0"); + expect((0, serialize_1.latLngArrayToStringMaybeEncoded)([[0, 0]])).toEqual("0,0"); + expect((0, serialize_1.latLngArrayToStringMaybeEncoded)([ + [40.714728, -73.998672], + [-34.397, 150.644], + ])).toEqual("enc:abowFtzsbMhgmiMuobzi@"); +}); +test("toLatLngLiteral", () => { + expect((0, serialize_1.toLatLngLiteral)("0,1")).toEqual({ lat: 0, lng: 1 }); + expect((0, serialize_1.toLatLngLiteral)([0, 1])).toEqual({ lat: 0, lng: 1 }); + expect((0, serialize_1.toLatLngLiteral)({ lat: 0, lng: 1 })).toEqual({ + lat: 0, + lng: 1, + }); + expect((0, serialize_1.toLatLngLiteral)({ latitude: 0, longitude: 1 })).toEqual({ + lat: 0, + lng: 1, + }); + expect(() => { + (0, serialize_1.toLatLngLiteral)({}); + }).toThrow(TypeError); +}); +test("toTimestamp", () => { + expect((0, serialize_1.toTimestamp)(100)).toEqual(100); + const dt = new Date(); + const seconds = Math.round(Number(dt) / 1000); + expect((0, serialize_1.toTimestamp)(dt)).toEqual(seconds); + expect((0, serialize_1.toTimestamp)("now")).toEqual("now"); + expect((0, serialize_1.toTimestamp)(new Date("2022-06-22T09:03:33.430Z"))).toEqual(1655888613); +}); +test("createPremiumPlanQueryString", () => { + const serializedParams = { + avoid: "ferries", + destination: "38.8977,-77.0365", + mode: "driving", + origin: "33.8121,-117.9190", + units: "imperial", + client_id: "testClient", + client_secret: "testClientSecret", + }; + const queryStringOptions = { + arrayFormat: "separator", + arrayFormatSeparator: "|", + }; + const baseUrl = "https://test.url/maps/api/directions/json"; + expect((0, serialize_1.createPremiumPlanQueryString)(serializedParams, queryStringOptions, baseUrl)).toEqual("avoid=ferries&client=testClient&destination=38.8977%2C-77.0365&mode=driving&origin=33.8121%2C-117.9190&units=imperial&signature=YRJoTd6ohbpsR14WkWv3S7H6MqU="); +}); +//# sourceMappingURL=serialize.test.js.map \ No newline at end of file diff --git a/dist/serialize.test.js.map b/dist/serialize.test.js.map new file mode 100644 index 0000000000..97be39604f --- /dev/null +++ b/dist/serialize.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"serialize.test.js","sourceRoot":"","sources":["../src/serialize.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAGH,2CASqB;AAErB,IAAI,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACrC,MAAM,CAAC,IAAA,0BAAc,EAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpC,MAAM,CAAC,IAAA,0BAAc,EAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9C,MAAM,CAAC,IAAA,0BAAc,EAAC,CAAC,EAAE,EAAE,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,OAAO,CAAC,UAAU,CAAC,CAAC;AAChF,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,8BAA8B,EAAE,GAAG,EAAE;IACxC,MAAM,gBAAgB,GAAG;QACvB,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,kBAAkB;QAC/B,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,mBAAmB;QAC3B,KAAK,EAAE,UAAU;QACjB,SAAS,EAAE,YAAY;QACvB,aAAa,EAAE,kBAAkB;KAClC,CAAC;IACF,MAAM,kBAAkB,GAAG;QACzB,WAAW,EAAE,WAAW;QACxB,oBAAoB,EAAE,GAAG;KAC1B,CAAC;IACF,MAAM,OAAO,GAAG,2CAA2C,CAAC;IAE5D,MAAM,CACJ,IAAA,wCAA4B,EAAC,gBAAgB,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAC5E,CAAC,OAAO,CACP,8JAA8J,CAC/J,CAAC;AACJ,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/timezone.d.ts b/dist/timezone.d.ts new file mode 100644 index 0000000000..c7eb79d2c0 --- /dev/null +++ b/dist/timezone.d.ts @@ -0,0 +1,67 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; +import { Language, LatLng, RequestParams, ResponseData } from "./common"; +export interface TimeZoneRequest extends Partial { + params: { + /** a comma-separated `lat,lng` tuple (eg. `location=-33.86,151.20`), representing the location to look up. */ + location: LatLng; + /** + * specifies the desired time as seconds since midnight, January 1, 1970 UTC. + * The Time Zone API uses the timestamp to determine whether or not Daylight Savings should be applied, + * based on the time zone of the location. Note that the API does not take historical time zones into account. + * That is, if you specify a past timestamp, the API does not take into account the possibility that + * the location was previously in a different time zone. + */ + timestamp: Date | number; + /** + * The language in which to return results. + * Note that we often update supported languages so this list may not be exhaustive. + * + * @default Language.English + */ + language?: Language; + } & RequestParams; +} +export interface TimeZoneResponseData extends ResponseData { + /** + * the offset for daylight-savings time in seconds. + * This will be zero if the time zone is not in Daylight Savings Time during the specified `timestamp`. + */ + dstOffset: number; + /** the offset from UTC (in seconds) for the given location. This does not take into effect daylight savings. */ + rawOffset: number; + /** + * a string containing the ID of the time zone, such as "America/Los_Angeles" or "Australia/Sydney". + * These IDs are defined by [Unicode Common Locale Data Repository (CLDR) project](http://cldr.unicode.org/), + * and currently available in file [timezone.xml](http://unicode.org/repos/cldr/trunk/common/bcp47/timezone.xml). + * When a timezone has several IDs, the canonical one is returned. In timezone.xml, this is the first alias of each timezone. + * For example, "Asia/Calcutta" is returned, not "Asia/Kolkata". + */ + timeZoneId: string; + /** + * a string containing the long form name of the time zone. + * This field will be localized if the `language` parameter is set. + * eg. "Pacific Daylight Time" or "Australian Eastern Daylight Time" + */ + timeZoneName: string; +} +export interface TimeZoneResponse extends AxiosResponse { + data: TimeZoneResponseData; +} +export declare const defaultUrl = "https://maps.googleapis.com/maps/api/timezone/json"; +export declare const defaultParamsSerializer: (params: Record) => string; +export declare function timezone({ params, method, url, paramsSerializer, ...config }: TimeZoneRequest, axiosInstance?: AxiosInstance): Promise; diff --git a/dist/timezone.js b/dist/timezone.js new file mode 100644 index 0000000000..0ed68ece15 --- /dev/null +++ b/dist/timezone.js @@ -0,0 +1,46 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.timezone = exports.defaultParamsSerializer = exports.defaultUrl = void 0; +const serialize_1 = require("./serialize"); +const client_1 = require("./client"); +exports.defaultUrl = "https://maps.googleapis.com/maps/api/timezone/json"; +exports.defaultParamsSerializer = (0, serialize_1.serializer)({ + timestamp: serialize_1.toTimestamp, + location: serialize_1.latLngToString, +}, exports.defaultUrl); +function timezone(_a, axiosInstance) { + var { params, method = "get", url = exports.defaultUrl, paramsSerializer = exports.defaultParamsSerializer } = _a, config = __rest(_a, ["params", "method", "url", "paramsSerializer"]); + if (axiosInstance === void 0) { axiosInstance = client_1.defaultAxiosInstance; } + return axiosInstance(Object.assign({ params, + method, + url, + paramsSerializer }, config)); +} +exports.timezone = timezone; +//# sourceMappingURL=timezone.js.map \ No newline at end of file diff --git a/dist/timezone.js.map b/dist/timezone.js.map new file mode 100644 index 0000000000..6d66d4630b --- /dev/null +++ b/dist/timezone.js.map @@ -0,0 +1 @@ +{"version":3,"file":"timezone.js","sourceRoot":"","sources":["../src/timezone.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;AAIH,2CAAsE;AAEtE,qCAAgD;AAoDnC,QAAA,UAAU,GAAG,oDAAoD,CAAC;AAClE,QAAA,uBAAuB,GAAG,IAAA,sBAAU,EAC/C;IACE,SAAS,EAAE,uBAAW;IACtB,QAAQ,EAAE,0BAAc;CACzB,EACD,kBAAU,CACX,CAAC;AACF,SAAgB,QAAQ,CACtB,EAMkB,EAClB,aAAmD;QAPnD,EACE,MAAM,EACN,MAAM,GAAG,KAAK,EACd,GAAG,GAAG,kBAAU,EAChB,gBAAgB,GAAG,+BAAuB,OAE1B,EADb,MAAM,cALX,+CAMC,CADU;IAEX,8BAAA,EAAA,gBAA+B,6BAAoB;IAEnD,OAAO,aAAa,iBAClB,MAAM;QACN,MAAM;QACN,GAAG;QACH,gBAAgB,IACb,MAAM,EACoB,CAAC;AAClC,CAAC;AAjBD,4BAiBC"} \ No newline at end of file diff --git a/dist/timezone.test.d.ts b/dist/timezone.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/timezone.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/timezone.test.js b/dist/timezone.test.js new file mode 100644 index 0000000000..eff755e065 --- /dev/null +++ b/dist/timezone.test.js @@ -0,0 +1,47 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const timezone_1 = require("./timezone"); +const axios_1 = __importDefault(require("axios")); +jest.mock("axios"); +const mockedAxios = axios_1.default; +afterEach(() => { + jest.clearAllMocks(); +}); +test("elevation should call axios correctly", () => { + const params = { + location: { lat: 35, lng: -110 }, + timestamp: 999999999, + key: "foo", + }; + (0, timezone_1.timezone)({ params: params }, mockedAxios); + expect(mockedAxios).toHaveBeenCalledTimes(1); + expect(mockedAxios).toHaveBeenCalledWith({ + method: "get", + params: params, + paramsSerializer: timezone_1.defaultParamsSerializer, + url: timezone_1.defaultUrl, + }); +}); +test("serializer should handle date object", () => { + const dt = new Date(); + expect((0, timezone_1.defaultParamsSerializer)({ timestamp: dt })).toEqual(`timestamp=${Math.round(Number(dt) / 1000)}`); +}); +//# sourceMappingURL=timezone.test.js.map \ No newline at end of file diff --git a/dist/timezone.test.js.map b/dist/timezone.test.js.map new file mode 100644 index 0000000000..a7141cbc82 --- /dev/null +++ b/dist/timezone.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"timezone.test.js","sourceRoot":"","sources":["../src/timezone.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;AAEH,yCAA2E;AAE3E,kDAA0B;AAE1B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,MAAM,WAAW,GAAG,eAAkC,CAAC;AAEvD,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IACjD,MAAM,MAAM,GAAG;QACb,QAAQ,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE;QAChC,SAAS,EAAE,SAAS;QACpB,GAAG,EAAE,KAAK;KACX,CAAC;IACF,IAAA,mBAAQ,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;IAE1C,MAAM,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,MAAM;QACd,gBAAgB,EAAE,kCAAuB;QACzC,GAAG,EAAE,qBAAU;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,sCAAsC,EAAE,GAAG,EAAE;IAChD,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC;IACtB,MAAM,CAAC,IAAA,kCAAuB,EAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CACxD,aAAa,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAC7C,CAAC;AACJ,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/util.d.ts b/dist/util.d.ts new file mode 100644 index 0000000000..1201b3b19d --- /dev/null +++ b/dist/util.d.ts @@ -0,0 +1,29 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { LatLngLiteral } from "./common"; +/** + * Polyline encodes an array of LatLng objects. + * + * See {@link https://developers.google.com/maps/documentation/utilities/polylinealgorithm} + * + */ +export declare function encodePath(path: LatLngLiteral[]): string; +/** + * Decodes a polyline encoded string. + * + * See {@link https://developers.google.com/maps/documentation/utilities/polylinealgorithm} + */ +export declare function decodePath(encodedPath: string): LatLngLiteral[]; diff --git a/dist/util.js b/dist/util.js new file mode 100644 index 0000000000..871e9eacee --- /dev/null +++ b/dist/util.js @@ -0,0 +1,82 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.decodePath = exports.encodePath = void 0; +/** + * Polyline encodes an array of LatLng objects. + * + * See {@link https://developers.google.com/maps/documentation/utilities/polylinealgorithm} + * + */ +function encodePath(path) { + const result = []; + let start = [0, 0]; + let end; + const encodePart = function (part) { + part = part < 0 ? ~(part << 1) : part << 1; + while (part >= 0x20) { + result.push(String.fromCharCode((0x20 | (part & 0x1f)) + 63)); + part >>= 5; + } + result.push(String.fromCharCode(part + 63)); + }; + for (let i = 0, I = path.length || 0; i < I; ++i) { + end = [Math.round(path[i].lat * 1e5), Math.round(path[i].lng * 1e5)]; + encodePart(end[0] - start[0]); // lat + encodePart(end[1] - start[1]); // lng + start = end; + } + return result.join(""); +} +exports.encodePath = encodePath; +/** + * Decodes a polyline encoded string. + * + * See {@link https://developers.google.com/maps/documentation/utilities/polylinealgorithm} + */ +function decodePath(encodedPath) { + const len = encodedPath.length || 0; + const path = new Array(Math.floor(encodedPath.length / 2)); + let index = 0; + let lat = 0; + let lng = 0; + let pointIndex; + for (pointIndex = 0; index < len; ++pointIndex) { + let result = 1; + let shift = 0; + let b; + do { + b = encodedPath.charCodeAt(index++) - 63 - 1; + result += b << shift; + shift += 5; + } while (b >= 0x1f); + lat += result & 1 ? ~(result >> 1) : result >> 1; + result = 1; + shift = 0; + do { + b = encodedPath.charCodeAt(index++) - 63 - 1; + result += b << shift; + shift += 5; + } while (b >= 0x1f); + lng += result & 1 ? ~(result >> 1) : result >> 1; + path[pointIndex] = { lat: lat * 1e-5, lng: lng * 1e-5 }; + } + path.length = pointIndex; + return path; +} +exports.decodePath = decodePath; +//# sourceMappingURL=util.js.map \ No newline at end of file diff --git a/dist/util.js.map b/dist/util.js.map new file mode 100644 index 0000000000..1df5c96529 --- /dev/null +++ b/dist/util.js.map @@ -0,0 +1 @@ +{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,IAAqB;IAC9C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,KAAK,GAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACrC,IAAI,GAAqB,CAAC;IAE1B,MAAM,UAAU,GAAG,UAAU,IAAY;QACvC,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;QAC3C,OAAO,IAAI,IAAI,IAAI,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAC9D,IAAI,KAAK,CAAC,CAAC;QACb,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC;IAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;QACjD,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,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,GAAG,CAAC,CAAC;QACX,KAAK,GAAG,CAAC,CAAC;QACV,GAAG,CAAC;YACF,CAAC,GAAG,WAAW,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAC7C,MAAM,IAAI,CAAC,IAAI,KAAK,CAAC;YACrB,KAAK,IAAI,CAAC,CAAC;QACb,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE;QACpB,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC;QAEjD,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,EAAE,CAAC;IAC1D,CAAC;IACD,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC;IAEzB,OAAO,IAAI,CAAC;AACd,CAAC;AAjCD,gCAiCC"} \ No newline at end of file diff --git a/dist/util.test.d.ts b/dist/util.test.d.ts new file mode 100644 index 0000000000..f9d49af078 --- /dev/null +++ b/dist/util.test.d.ts @@ -0,0 +1,16 @@ +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export {}; diff --git a/dist/util.test.js b/dist/util.test.js new file mode 100644 index 0000000000..84f1486dc3 --- /dev/null +++ b/dist/util.test.js @@ -0,0 +1,104 @@ +"use strict"; +/** + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +const util_1 = require("./util"); +describe("polyline encoding and decoding is correct", () => { + const encoded = "gcneIpgxzRcDnBoBlEHzKjBbHlG`@`IkDxIiKhKoMaLwTwHeIqHuAyGXeB~Ew@fFjAtIzExF"; + const decoded = [ + { + lat: 53.489320000000006, + lng: -104.16777, + }, + { + lat: 53.490140000000004, + lng: -104.16833000000001, + }, + { + lat: 53.490700000000004, + lng: -104.16936000000001, + }, + { + lat: 53.49065, + lng: -104.17142000000001, + }, + { + lat: 53.49011, + lng: -104.17288, + }, + { + lat: 53.488760000000006, + lng: -104.17305, + }, + { + lat: 53.48715000000001, + lng: -104.17219000000001, + }, + { + lat: 53.485420000000005, + lng: -104.17022000000001, + }, + { + lat: 53.483450000000005, + lng: -104.1679, + }, + { + lat: 53.48554000000001, + lng: -104.16442, + }, + { + lat: 53.487100000000005, + lng: -104.16279000000002, + }, + { + lat: 53.48863000000001, + lng: -104.16236, + }, + { + lat: 53.49004000000001, + lng: -104.16249, + }, + { + lat: 53.490550000000006, + lng: -104.16361, + }, + { + lat: 53.49083, + lng: -104.16477, + }, + { + lat: 53.49045, + lng: -104.16648, + }, + { + lat: 53.48935, + lng: -104.16773, + }, + ]; + test("encodePath is correct", () => { + expect((0, util_1.encodePath)(decoded)).toEqual(encoded); + expect((0, util_1.encodePath)([])).toEqual(""); + }); + test("decodePath is correct", () => { + expect((0, util_1.decodePath)(encoded)).toEqual(decoded); + expect((0, util_1.decodePath)("")).toEqual([]); + }); + test("roundtrip", () => { + expect((0, util_1.encodePath)((0, util_1.decodePath)(encoded))).toEqual(encoded); + expect((0, util_1.decodePath)((0, util_1.encodePath)(decoded))).toEqual(decoded); + }); +}); +//# sourceMappingURL=util.test.js.map \ No newline at end of file diff --git a/dist/util.test.js.map b/dist/util.test.js.map new file mode 100644 index 0000000000..d15ddde7a2 --- /dev/null +++ b/dist/util.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"util.test.js","sourceRoot":"","sources":["../src/util.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAEH,iCAAgD;AAEhD,QAAQ,CAAC,2CAA2C,EAAE,GAAG,EAAE;IACzD,MAAM,OAAO,GACX,0EAA0E,CAAC;IAC7E,MAAM,OAAO,GAAG;QACd;YACE,GAAG,EAAE,kBAAkB;YACvB,GAAG,EAAE,CAAC,SAAS;SAChB;QACD;YACE,GAAG,EAAE,kBAAkB;YACvB,GAAG,EAAE,CAAC,kBAAkB;SACzB;QACD;YACE,GAAG,EAAE,kBAAkB;YACvB,GAAG,EAAE,CAAC,kBAAkB;SACzB;QACD;YACE,GAAG,EAAE,QAAQ;YACb,GAAG,EAAE,CAAC,kBAAkB;SACzB;QACD;YACE,GAAG,EAAE,QAAQ;YACb,GAAG,EAAE,CAAC,SAAS;SAChB;QACD;YACE,GAAG,EAAE,kBAAkB;YACvB,GAAG,EAAE,CAAC,SAAS;SAChB;QACD;YACE,GAAG,EAAE,iBAAiB;YACtB,GAAG,EAAE,CAAC,kBAAkB;SACzB;QACD;YACE,GAAG,EAAE,kBAAkB;YACvB,GAAG,EAAE,CAAC,kBAAkB;SACzB;QACD;YACE,GAAG,EAAE,kBAAkB;YACvB,GAAG,EAAE,CAAC,QAAQ;SACf;QACD;YACE,GAAG,EAAE,iBAAiB;YACtB,GAAG,EAAE,CAAC,SAAS;SAChB;QACD;YACE,GAAG,EAAE,kBAAkB;YACvB,GAAG,EAAE,CAAC,kBAAkB;SACzB;QACD;YACE,GAAG,EAAE,iBAAiB;YACtB,GAAG,EAAE,CAAC,SAAS;SAChB;QACD;YACE,GAAG,EAAE,iBAAiB;YACtB,GAAG,EAAE,CAAC,SAAS;SAChB;QACD;YACE,GAAG,EAAE,kBA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