google-maps-fetch 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +258 -2
- package/compat/package.json +5 -0
- package/dist/chunk-DU6WHR7R.cjs +246 -0
- package/dist/chunk-KSK2WERM.js +246 -0
- package/dist/compat.cjs +1215 -0
- package/dist/compat.d.cts +786 -0
- package/dist/compat.d.ts +786 -0
- package/dist/compat.js +1215 -0
- package/dist/index.cjs +127 -0
- package/dist/index.d.cts +108 -0
- package/dist/index.d.ts +108 -0
- package/dist/index.js +127 -0
- package/dist/types-FNou8i90.d.cts +629 -0
- package/dist/types-FNou8i90.d.ts +629 -0
- package/package.json +92 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkDU6WHR7Rcjs = require('./chunk-DU6WHR7R.cjs');
|
|
16
|
+
|
|
17
|
+
// src/addressvalidation.ts
|
|
18
|
+
var base = "https://addressvalidation.googleapis.com/v1";
|
|
19
|
+
function createAddressValidation(send) {
|
|
20
|
+
const validate = (request, call) => send({ method: "POST", url: `${base}:validateAddress`, body: request }, call);
|
|
21
|
+
const feedback = async ({ responseId, conclusion }, call) => {
|
|
22
|
+
await send({ method: "POST", url: `${base}:provideValidationFeedback`, body: { responseId, conclusion } }, call);
|
|
23
|
+
};
|
|
24
|
+
return { validate, feedback };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/classic.ts
|
|
28
|
+
var checkStatus = (body, api) => {
|
|
29
|
+
if (body.status === "OK") return body;
|
|
30
|
+
if (body.status === "ZERO_RESULTS") return void 0;
|
|
31
|
+
throw new (0, _chunkDU6WHR7Rcjs.MapsError)(_nullishCoalesce(body.error_message, () => ( `${api} failed: ${body.status}`)), 200, body.status, body);
|
|
32
|
+
};
|
|
33
|
+
var point = (value) => {
|
|
34
|
+
const { latitude, longitude } = _chunkDU6WHR7Rcjs.toLatLng.call(void 0, value);
|
|
35
|
+
return `${latitude},${longitude}`;
|
|
36
|
+
};
|
|
37
|
+
var points = (values) => values.map(point).join("|");
|
|
38
|
+
|
|
39
|
+
// src/geocode.ts
|
|
40
|
+
var url = "https://maps.googleapis.com/maps/api/geocode/json";
|
|
41
|
+
var components = (value) => typeof value === "object" ? Object.entries(value).map(([k, v]) => `${k}:${v}`).join("|") : value;
|
|
42
|
+
function createGeocoding(send) {
|
|
43
|
+
const run = async (query, call) => await _asyncNullishCoalesce(await _asyncOptionalChain([checkStatus, 'call', async _ => _(await send({ method: "GET", url, keyIn: "query", query }, call), "Geocoding"), 'optionalAccess', async _2 => _2.results]), async () => ( []));
|
|
44
|
+
const geocode = ({ address, placeId, components: filter, bounds, language, region }, call) => run(
|
|
45
|
+
{
|
|
46
|
+
address,
|
|
47
|
+
place_id: placeId,
|
|
48
|
+
components: components(filter),
|
|
49
|
+
bounds: bounds && `${point(bounds.low)}|${point(bounds.high)}`,
|
|
50
|
+
language,
|
|
51
|
+
region
|
|
52
|
+
},
|
|
53
|
+
call
|
|
54
|
+
);
|
|
55
|
+
const reverseGeocode = ({ location, resultType, locationType, language }, call) => run({ latlng: point(location), result_type: _optionalChain([resultType, 'optionalAccess', _3 => _3.join, 'call', _4 => _4("|")]), location_type: _optionalChain([locationType, 'optionalAccess', _5 => _5.join, 'call', _6 => _6("|")]), language }, call);
|
|
56
|
+
return { geocode, reverseGeocode };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/services.ts
|
|
60
|
+
var seconds2 = (t) => typeof t === "number" ? Math.floor(t) : Math.floor(t.getTime() / 1e3);
|
|
61
|
+
function createServices(send) {
|
|
62
|
+
const elevation = async (request, call) => {
|
|
63
|
+
const query = "locations" in request ? { locations: points(request.locations) } : { path: points(request.path), samples: request.samples };
|
|
64
|
+
const body = await send(
|
|
65
|
+
{ method: "GET", url: "https://maps.googleapis.com/maps/api/elevation/json", keyIn: "query", query },
|
|
66
|
+
call
|
|
67
|
+
);
|
|
68
|
+
return _nullishCoalesce(_optionalChain([checkStatus, 'call', _7 => _7(body, "Elevation"), 'optionalAccess', _8 => _8.results]), () => ( []));
|
|
69
|
+
};
|
|
70
|
+
const timezone = async ({ location, timestamp = /* @__PURE__ */ new Date(), language }, call) => {
|
|
71
|
+
const body = await send(
|
|
72
|
+
{
|
|
73
|
+
method: "GET",
|
|
74
|
+
url: "https://maps.googleapis.com/maps/api/timezone/json",
|
|
75
|
+
keyIn: "query",
|
|
76
|
+
query: { location: point(location), timestamp: seconds2(timestamp), language }
|
|
77
|
+
},
|
|
78
|
+
call
|
|
79
|
+
);
|
|
80
|
+
const zone = checkStatus(body, "Time Zone");
|
|
81
|
+
return zone && { dstOffset: zone.dstOffset, rawOffset: zone.rawOffset, timeZoneId: zone.timeZoneId, timeZoneName: zone.timeZoneName };
|
|
82
|
+
};
|
|
83
|
+
const geolocate = (request = {}, call) => send({ method: "POST", url: "https://www.googleapis.com/geolocation/v1/geolocate", body: request }, call);
|
|
84
|
+
const roads = {
|
|
85
|
+
/** Snaps a GPS trace to the roads it most likely followed */
|
|
86
|
+
snap: async ({ path, interpolate }, call) => await _asyncNullishCoalesce((await send(
|
|
87
|
+
{ method: "GET", url: "https://roads.googleapis.com/v1/snapToRoads", query: { path: points(path), interpolate } },
|
|
88
|
+
call
|
|
89
|
+
)).snappedPoints, async () => ( [])),
|
|
90
|
+
/** The nearest road segment for each point, independently */
|
|
91
|
+
nearest: async ({ points: list }, call) => await _asyncNullishCoalesce((await send(
|
|
92
|
+
{ method: "GET", url: "https://roads.googleapis.com/v1/nearestRoads", query: { points: points(list) } },
|
|
93
|
+
call
|
|
94
|
+
)).snappedPoints, async () => ( []))
|
|
95
|
+
};
|
|
96
|
+
return { elevation, timezone, geolocate, roads };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/index.ts
|
|
100
|
+
function createClient(options) {
|
|
101
|
+
const send = _chunkDU6WHR7Rcjs.createTransport.call(void 0, options);
|
|
102
|
+
return {
|
|
103
|
+
places: _chunkDU6WHR7Rcjs.createPlaces.call(void 0, send),
|
|
104
|
+
routes: _chunkDU6WHR7Rcjs.createRoutes.call(void 0, send),
|
|
105
|
+
addressValidation: createAddressValidation(send),
|
|
106
|
+
...createGeocoding(send),
|
|
107
|
+
...createServices(send),
|
|
108
|
+
/**
|
|
109
|
+
* Any Google Maps Platform REST endpoint, with the key, field mask, retries, timeouts and errors handled.
|
|
110
|
+
* The key goes in the X-Goog-Api-Key header, or in the query string with keyIn: 'query' for the older JSON APIs.
|
|
111
|
+
*/
|
|
112
|
+
request: (request, call) => send(request, call)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
exports.MapsError = _chunkDU6WHR7Rcjs.MapsError; exports.createClient = createClient; exports.matrixFields = _chunkDU6WHR7Rcjs.matrixFields; exports.newSessionToken = _chunkDU6WHR7Rcjs.newSessionToken; exports.placeFields = _chunkDU6WHR7Rcjs.placeFields; exports.routeFields = _chunkDU6WHR7Rcjs.routeFields; exports.searchNearbyFields = _chunkDU6WHR7Rcjs.searchNearbyFields; exports.searchTextFields = _chunkDU6WHR7Rcjs.searchTextFields; exports.seconds = _chunkDU6WHR7Rcjs.seconds; exports.toLatLng = _chunkDU6WHR7Rcjs.toLatLng; exports.toWaypoint = _chunkDU6WHR7Rcjs.toWaypoint;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { A as AutocompleteRequest, b as FieldOptions, c as AutocompleteResponse, d as GetPlaceOptions, P as Place, e as Send, f as SearchTextRequest, g as SearchTextResponse, h as SearchNearbyRequest, i as SearchNearbyResponse, C as CallOptions, j as PhotoMedia, k as ComputeRoutesRequest, l as ComputeRoutesResponse, m as ComputeRouteMatrixRequest, L as LocalizedValues, n as LatLngInput, o as LatLng, W as WaypointInput, p as Waypoint, q as ClientOptions, R as Request, r as ElevationRequest, E as ElevationResult, s as TimeZoneRequest, T as TimeZone, t as GeolocateRequest, a as GeolocateResponse, u as SnapToRoadsRequest, S as SnappedPoint, N as NearestRoadsRequest, v as GeocodeRequest, G as GeocodeResult, w as ReverseGeocodeRequest, V as ValidateAddressRequest, x as ValidateAddressResponse, y as ValidationConclusion } from './types-FNou8i90.cjs';
|
|
2
|
+
export { z as AddressComponent, B as AddressComponentValidation, D as Area, H as Circle, F as FetchLike, I as FormattableText, J as LocalizedText, K as Location, M as MapsError, O as OpeningHours, Q as Photo, U as PlacePrediction, X as Polyline, Y as PostalAddress, Z as QueryPrediction, _ as Review, $ as Route, a0 as RouteLeg, a1 as RouteLegStep, a2 as RouteMatrixDestination, a3 as RouteMatrixElement, a4 as RouteMatrixOrigin, a5 as RouteModifiers, a6 as SecondaryOpeningHours, a7 as StringRange, a8 as StructuredFormat, a9 as Suggestion, aa as TravelMode, ab as Viewport } from './types-FNou8i90.cjs';
|
|
3
|
+
|
|
4
|
+
declare const placeFields: string[];
|
|
5
|
+
declare const searchTextFields: string[];
|
|
6
|
+
declare const searchNearbyFields: string[];
|
|
7
|
+
interface PlaceSession {
|
|
8
|
+
/** The token in use until the next get() */
|
|
9
|
+
readonly token: string;
|
|
10
|
+
/** sessionToken is filled in for you */
|
|
11
|
+
autocomplete(request: AutocompleteRequest, options?: FieldOptions): Promise<AutocompleteResponse>;
|
|
12
|
+
/** Fetches the place and ends the session; the next autocomplete starts a new one */
|
|
13
|
+
get(id: string, options?: FieldOptions & Omit<GetPlaceOptions, 'sessionToken'>): Promise<Place>;
|
|
14
|
+
}
|
|
15
|
+
declare function createPlaces(send: Send): {
|
|
16
|
+
autocomplete: ({ ...request }: AutocompleteRequest, { fields, ...call }?: FieldOptions) => Promise<AutocompleteResponse>;
|
|
17
|
+
get: (id: string, { fields, languageCode, regionCode, sessionToken, ...call }?: FieldOptions & GetPlaceOptions) => Promise<Place>;
|
|
18
|
+
searchText: (request: SearchTextRequest, { fields, ...call }?: FieldOptions) => Promise<SearchTextResponse>;
|
|
19
|
+
searchNearby: (request: SearchNearbyRequest, { fields, ...call }?: FieldOptions) => Promise<SearchNearbyResponse>;
|
|
20
|
+
photo: (name: string, { maxWidthPx, maxHeightPx, ...call }?: CallOptions & {
|
|
21
|
+
maxWidthPx?: number;
|
|
22
|
+
maxHeightPx?: number;
|
|
23
|
+
}) => Promise<PhotoMedia>;
|
|
24
|
+
session: () => PlaceSession;
|
|
25
|
+
};
|
|
26
|
+
type Places = ReturnType<typeof createPlaces>;
|
|
27
|
+
|
|
28
|
+
declare const routeFields: string[];
|
|
29
|
+
declare const matrixFields: string[];
|
|
30
|
+
declare function createRoutes(send: Send): {
|
|
31
|
+
compute: ({ origin, destination, intermediates, ...rest }: ComputeRoutesRequest, { fields, ...call }?: FieldOptions) => Promise<ComputeRoutesResponse>;
|
|
32
|
+
matrix: ({ origins, destinations, ...rest }: ComputeRouteMatrixRequest, { fields, ...call }?: FieldOptions) => Promise<{
|
|
33
|
+
destinationIndex: number;
|
|
34
|
+
originIndex: number;
|
|
35
|
+
status?: {
|
|
36
|
+
code?: number;
|
|
37
|
+
message?: string;
|
|
38
|
+
};
|
|
39
|
+
condition?: string;
|
|
40
|
+
distanceMeters?: number;
|
|
41
|
+
duration?: string;
|
|
42
|
+
staticDuration?: string;
|
|
43
|
+
localizedValues?: LocalizedValues;
|
|
44
|
+
}[]>;
|
|
45
|
+
};
|
|
46
|
+
type Routes = ReturnType<typeof createRoutes>;
|
|
47
|
+
|
|
48
|
+
declare const toLatLng: (value: LatLngInput) => LatLng;
|
|
49
|
+
/** Turns an address, coordinates or a Waypoint into a Routes API Waypoint */
|
|
50
|
+
declare const toWaypoint: (value: WaypointInput) => Waypoint;
|
|
51
|
+
/** "1234s" (a Routes API duration) to 1234 */
|
|
52
|
+
declare const seconds: (duration: string | undefined) => number | undefined;
|
|
53
|
+
/** A random session token for Places autocomplete */
|
|
54
|
+
declare const newSessionToken: () => string;
|
|
55
|
+
|
|
56
|
+
declare function createClient(options: ClientOptions): {
|
|
57
|
+
/**
|
|
58
|
+
* Any Google Maps Platform REST endpoint, with the key, field mask, retries, timeouts and errors handled.
|
|
59
|
+
* The key goes in the X-Goog-Api-Key header, or in the query string with keyIn: 'query' for the older JSON APIs.
|
|
60
|
+
*/
|
|
61
|
+
request: <T = unknown>(request: Request, call?: CallOptions) => Promise<T>;
|
|
62
|
+
elevation: (request: ElevationRequest, call?: CallOptions) => Promise<ElevationResult[]>;
|
|
63
|
+
timezone: ({ location, timestamp, language }: TimeZoneRequest, call?: CallOptions) => Promise<TimeZone | undefined>;
|
|
64
|
+
geolocate: (request?: GeolocateRequest, call?: CallOptions) => Promise<GeolocateResponse>;
|
|
65
|
+
roads: {
|
|
66
|
+
snap: ({ path, interpolate }: SnapToRoadsRequest, call?: CallOptions) => Promise<SnappedPoint[]>;
|
|
67
|
+
nearest: ({ points: list }: NearestRoadsRequest, call?: CallOptions) => Promise<SnappedPoint[]>;
|
|
68
|
+
};
|
|
69
|
+
geocode: ({ address, placeId, components: filter, bounds, language, region }: GeocodeRequest, call?: CallOptions) => Promise<GeocodeResult[]>;
|
|
70
|
+
reverseGeocode: ({ location, resultType, locationType, language }: ReverseGeocodeRequest, call?: CallOptions) => Promise<GeocodeResult[]>;
|
|
71
|
+
places: {
|
|
72
|
+
autocomplete: ({ ...request }: AutocompleteRequest, { fields, ...call }?: FieldOptions) => Promise<AutocompleteResponse>;
|
|
73
|
+
get: (id: string, { fields, languageCode, regionCode, sessionToken, ...call }?: FieldOptions & GetPlaceOptions) => Promise<Place>;
|
|
74
|
+
searchText: (request: SearchTextRequest, { fields, ...call }?: FieldOptions) => Promise<SearchTextResponse>;
|
|
75
|
+
searchNearby: (request: SearchNearbyRequest, { fields, ...call }?: FieldOptions) => Promise<SearchNearbyResponse>;
|
|
76
|
+
photo: (name: string, { maxWidthPx, maxHeightPx, ...call }?: CallOptions & {
|
|
77
|
+
maxWidthPx?: number;
|
|
78
|
+
maxHeightPx?: number;
|
|
79
|
+
}) => Promise<PhotoMedia>;
|
|
80
|
+
session: () => PlaceSession;
|
|
81
|
+
};
|
|
82
|
+
routes: {
|
|
83
|
+
compute: ({ origin, destination, intermediates, ...rest }: ComputeRoutesRequest, { fields, ...call }?: FieldOptions) => Promise<ComputeRoutesResponse>;
|
|
84
|
+
matrix: ({ origins, destinations, ...rest }: ComputeRouteMatrixRequest, { fields, ...call }?: FieldOptions) => Promise<{
|
|
85
|
+
destinationIndex: number;
|
|
86
|
+
originIndex: number;
|
|
87
|
+
status?: {
|
|
88
|
+
code?: number;
|
|
89
|
+
message?: string;
|
|
90
|
+
};
|
|
91
|
+
condition?: string;
|
|
92
|
+
distanceMeters?: number;
|
|
93
|
+
duration?: string;
|
|
94
|
+
staticDuration?: string;
|
|
95
|
+
localizedValues?: LocalizedValues;
|
|
96
|
+
}[]>;
|
|
97
|
+
};
|
|
98
|
+
addressValidation: {
|
|
99
|
+
validate: (request: ValidateAddressRequest, call?: CallOptions) => Promise<ValidateAddressResponse>;
|
|
100
|
+
feedback: ({ responseId, conclusion }: {
|
|
101
|
+
responseId: string;
|
|
102
|
+
conclusion: ValidationConclusion;
|
|
103
|
+
}, call?: CallOptions) => Promise<void>;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
type MapsClient = ReturnType<typeof createClient>;
|
|
107
|
+
|
|
108
|
+
export { AutocompleteRequest, AutocompleteResponse, CallOptions, ClientOptions, ComputeRouteMatrixRequest, ComputeRoutesRequest, ComputeRoutesResponse, ElevationRequest, ElevationResult, FieldOptions, GeocodeRequest, GeocodeResult, GeolocateRequest, GeolocateResponse, GetPlaceOptions, LatLng, LatLngInput, LocalizedValues, type MapsClient, Request as MapsRequest, NearestRoadsRequest, PhotoMedia, Place, type PlaceSession, type Places, ReverseGeocodeRequest, type Routes, SearchNearbyRequest, SearchNearbyResponse, SearchTextRequest, SearchTextResponse, SnapToRoadsRequest, SnappedPoint, TimeZone, TimeZoneRequest, ValidateAddressRequest, ValidateAddressResponse, ValidationConclusion, Waypoint, WaypointInput, createClient, matrixFields, newSessionToken, placeFields, routeFields, searchNearbyFields, searchTextFields, seconds, toLatLng, toWaypoint };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { A as AutocompleteRequest, b as FieldOptions, c as AutocompleteResponse, d as GetPlaceOptions, P as Place, e as Send, f as SearchTextRequest, g as SearchTextResponse, h as SearchNearbyRequest, i as SearchNearbyResponse, C as CallOptions, j as PhotoMedia, k as ComputeRoutesRequest, l as ComputeRoutesResponse, m as ComputeRouteMatrixRequest, L as LocalizedValues, n as LatLngInput, o as LatLng, W as WaypointInput, p as Waypoint, q as ClientOptions, R as Request, r as ElevationRequest, E as ElevationResult, s as TimeZoneRequest, T as TimeZone, t as GeolocateRequest, a as GeolocateResponse, u as SnapToRoadsRequest, S as SnappedPoint, N as NearestRoadsRequest, v as GeocodeRequest, G as GeocodeResult, w as ReverseGeocodeRequest, V as ValidateAddressRequest, x as ValidateAddressResponse, y as ValidationConclusion } from './types-FNou8i90.js';
|
|
2
|
+
export { z as AddressComponent, B as AddressComponentValidation, D as Area, H as Circle, F as FetchLike, I as FormattableText, J as LocalizedText, K as Location, M as MapsError, O as OpeningHours, Q as Photo, U as PlacePrediction, X as Polyline, Y as PostalAddress, Z as QueryPrediction, _ as Review, $ as Route, a0 as RouteLeg, a1 as RouteLegStep, a2 as RouteMatrixDestination, a3 as RouteMatrixElement, a4 as RouteMatrixOrigin, a5 as RouteModifiers, a6 as SecondaryOpeningHours, a7 as StringRange, a8 as StructuredFormat, a9 as Suggestion, aa as TravelMode, ab as Viewport } from './types-FNou8i90.js';
|
|
3
|
+
|
|
4
|
+
declare const placeFields: string[];
|
|
5
|
+
declare const searchTextFields: string[];
|
|
6
|
+
declare const searchNearbyFields: string[];
|
|
7
|
+
interface PlaceSession {
|
|
8
|
+
/** The token in use until the next get() */
|
|
9
|
+
readonly token: string;
|
|
10
|
+
/** sessionToken is filled in for you */
|
|
11
|
+
autocomplete(request: AutocompleteRequest, options?: FieldOptions): Promise<AutocompleteResponse>;
|
|
12
|
+
/** Fetches the place and ends the session; the next autocomplete starts a new one */
|
|
13
|
+
get(id: string, options?: FieldOptions & Omit<GetPlaceOptions, 'sessionToken'>): Promise<Place>;
|
|
14
|
+
}
|
|
15
|
+
declare function createPlaces(send: Send): {
|
|
16
|
+
autocomplete: ({ ...request }: AutocompleteRequest, { fields, ...call }?: FieldOptions) => Promise<AutocompleteResponse>;
|
|
17
|
+
get: (id: string, { fields, languageCode, regionCode, sessionToken, ...call }?: FieldOptions & GetPlaceOptions) => Promise<Place>;
|
|
18
|
+
searchText: (request: SearchTextRequest, { fields, ...call }?: FieldOptions) => Promise<SearchTextResponse>;
|
|
19
|
+
searchNearby: (request: SearchNearbyRequest, { fields, ...call }?: FieldOptions) => Promise<SearchNearbyResponse>;
|
|
20
|
+
photo: (name: string, { maxWidthPx, maxHeightPx, ...call }?: CallOptions & {
|
|
21
|
+
maxWidthPx?: number;
|
|
22
|
+
maxHeightPx?: number;
|
|
23
|
+
}) => Promise<PhotoMedia>;
|
|
24
|
+
session: () => PlaceSession;
|
|
25
|
+
};
|
|
26
|
+
type Places = ReturnType<typeof createPlaces>;
|
|
27
|
+
|
|
28
|
+
declare const routeFields: string[];
|
|
29
|
+
declare const matrixFields: string[];
|
|
30
|
+
declare function createRoutes(send: Send): {
|
|
31
|
+
compute: ({ origin, destination, intermediates, ...rest }: ComputeRoutesRequest, { fields, ...call }?: FieldOptions) => Promise<ComputeRoutesResponse>;
|
|
32
|
+
matrix: ({ origins, destinations, ...rest }: ComputeRouteMatrixRequest, { fields, ...call }?: FieldOptions) => Promise<{
|
|
33
|
+
destinationIndex: number;
|
|
34
|
+
originIndex: number;
|
|
35
|
+
status?: {
|
|
36
|
+
code?: number;
|
|
37
|
+
message?: string;
|
|
38
|
+
};
|
|
39
|
+
condition?: string;
|
|
40
|
+
distanceMeters?: number;
|
|
41
|
+
duration?: string;
|
|
42
|
+
staticDuration?: string;
|
|
43
|
+
localizedValues?: LocalizedValues;
|
|
44
|
+
}[]>;
|
|
45
|
+
};
|
|
46
|
+
type Routes = ReturnType<typeof createRoutes>;
|
|
47
|
+
|
|
48
|
+
declare const toLatLng: (value: LatLngInput) => LatLng;
|
|
49
|
+
/** Turns an address, coordinates or a Waypoint into a Routes API Waypoint */
|
|
50
|
+
declare const toWaypoint: (value: WaypointInput) => Waypoint;
|
|
51
|
+
/** "1234s" (a Routes API duration) to 1234 */
|
|
52
|
+
declare const seconds: (duration: string | undefined) => number | undefined;
|
|
53
|
+
/** A random session token for Places autocomplete */
|
|
54
|
+
declare const newSessionToken: () => string;
|
|
55
|
+
|
|
56
|
+
declare function createClient(options: ClientOptions): {
|
|
57
|
+
/**
|
|
58
|
+
* Any Google Maps Platform REST endpoint, with the key, field mask, retries, timeouts and errors handled.
|
|
59
|
+
* The key goes in the X-Goog-Api-Key header, or in the query string with keyIn: 'query' for the older JSON APIs.
|
|
60
|
+
*/
|
|
61
|
+
request: <T = unknown>(request: Request, call?: CallOptions) => Promise<T>;
|
|
62
|
+
elevation: (request: ElevationRequest, call?: CallOptions) => Promise<ElevationResult[]>;
|
|
63
|
+
timezone: ({ location, timestamp, language }: TimeZoneRequest, call?: CallOptions) => Promise<TimeZone | undefined>;
|
|
64
|
+
geolocate: (request?: GeolocateRequest, call?: CallOptions) => Promise<GeolocateResponse>;
|
|
65
|
+
roads: {
|
|
66
|
+
snap: ({ path, interpolate }: SnapToRoadsRequest, call?: CallOptions) => Promise<SnappedPoint[]>;
|
|
67
|
+
nearest: ({ points: list }: NearestRoadsRequest, call?: CallOptions) => Promise<SnappedPoint[]>;
|
|
68
|
+
};
|
|
69
|
+
geocode: ({ address, placeId, components: filter, bounds, language, region }: GeocodeRequest, call?: CallOptions) => Promise<GeocodeResult[]>;
|
|
70
|
+
reverseGeocode: ({ location, resultType, locationType, language }: ReverseGeocodeRequest, call?: CallOptions) => Promise<GeocodeResult[]>;
|
|
71
|
+
places: {
|
|
72
|
+
autocomplete: ({ ...request }: AutocompleteRequest, { fields, ...call }?: FieldOptions) => Promise<AutocompleteResponse>;
|
|
73
|
+
get: (id: string, { fields, languageCode, regionCode, sessionToken, ...call }?: FieldOptions & GetPlaceOptions) => Promise<Place>;
|
|
74
|
+
searchText: (request: SearchTextRequest, { fields, ...call }?: FieldOptions) => Promise<SearchTextResponse>;
|
|
75
|
+
searchNearby: (request: SearchNearbyRequest, { fields, ...call }?: FieldOptions) => Promise<SearchNearbyResponse>;
|
|
76
|
+
photo: (name: string, { maxWidthPx, maxHeightPx, ...call }?: CallOptions & {
|
|
77
|
+
maxWidthPx?: number;
|
|
78
|
+
maxHeightPx?: number;
|
|
79
|
+
}) => Promise<PhotoMedia>;
|
|
80
|
+
session: () => PlaceSession;
|
|
81
|
+
};
|
|
82
|
+
routes: {
|
|
83
|
+
compute: ({ origin, destination, intermediates, ...rest }: ComputeRoutesRequest, { fields, ...call }?: FieldOptions) => Promise<ComputeRoutesResponse>;
|
|
84
|
+
matrix: ({ origins, destinations, ...rest }: ComputeRouteMatrixRequest, { fields, ...call }?: FieldOptions) => Promise<{
|
|
85
|
+
destinationIndex: number;
|
|
86
|
+
originIndex: number;
|
|
87
|
+
status?: {
|
|
88
|
+
code?: number;
|
|
89
|
+
message?: string;
|
|
90
|
+
};
|
|
91
|
+
condition?: string;
|
|
92
|
+
distanceMeters?: number;
|
|
93
|
+
duration?: string;
|
|
94
|
+
staticDuration?: string;
|
|
95
|
+
localizedValues?: LocalizedValues;
|
|
96
|
+
}[]>;
|
|
97
|
+
};
|
|
98
|
+
addressValidation: {
|
|
99
|
+
validate: (request: ValidateAddressRequest, call?: CallOptions) => Promise<ValidateAddressResponse>;
|
|
100
|
+
feedback: ({ responseId, conclusion }: {
|
|
101
|
+
responseId: string;
|
|
102
|
+
conclusion: ValidationConclusion;
|
|
103
|
+
}, call?: CallOptions) => Promise<void>;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
type MapsClient = ReturnType<typeof createClient>;
|
|
107
|
+
|
|
108
|
+
export { AutocompleteRequest, AutocompleteResponse, CallOptions, ClientOptions, ComputeRouteMatrixRequest, ComputeRoutesRequest, ComputeRoutesResponse, ElevationRequest, ElevationResult, FieldOptions, GeocodeRequest, GeocodeResult, GeolocateRequest, GeolocateResponse, GetPlaceOptions, LatLng, LatLngInput, LocalizedValues, type MapsClient, Request as MapsRequest, NearestRoadsRequest, PhotoMedia, Place, type PlaceSession, type Places, ReverseGeocodeRequest, type Routes, SearchNearbyRequest, SearchNearbyResponse, SearchTextRequest, SearchTextResponse, SnapToRoadsRequest, SnappedPoint, TimeZone, TimeZoneRequest, ValidateAddressRequest, ValidateAddressResponse, ValidationConclusion, Waypoint, WaypointInput, createClient, matrixFields, newSessionToken, placeFields, routeFields, searchNearbyFields, searchTextFields, seconds, toLatLng, toWaypoint };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MapsError,
|
|
3
|
+
createPlaces,
|
|
4
|
+
createRoutes,
|
|
5
|
+
createTransport,
|
|
6
|
+
matrixFields,
|
|
7
|
+
newSessionToken,
|
|
8
|
+
placeFields,
|
|
9
|
+
routeFields,
|
|
10
|
+
searchNearbyFields,
|
|
11
|
+
searchTextFields,
|
|
12
|
+
seconds,
|
|
13
|
+
toLatLng,
|
|
14
|
+
toWaypoint
|
|
15
|
+
} from "./chunk-KSK2WERM.js";
|
|
16
|
+
|
|
17
|
+
// src/addressvalidation.ts
|
|
18
|
+
var base = "https://addressvalidation.googleapis.com/v1";
|
|
19
|
+
function createAddressValidation(send) {
|
|
20
|
+
const validate = (request, call) => send({ method: "POST", url: `${base}:validateAddress`, body: request }, call);
|
|
21
|
+
const feedback = async ({ responseId, conclusion }, call) => {
|
|
22
|
+
await send({ method: "POST", url: `${base}:provideValidationFeedback`, body: { responseId, conclusion } }, call);
|
|
23
|
+
};
|
|
24
|
+
return { validate, feedback };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/classic.ts
|
|
28
|
+
var checkStatus = (body, api) => {
|
|
29
|
+
if (body.status === "OK") return body;
|
|
30
|
+
if (body.status === "ZERO_RESULTS") return void 0;
|
|
31
|
+
throw new MapsError(body.error_message ?? `${api} failed: ${body.status}`, 200, body.status, body);
|
|
32
|
+
};
|
|
33
|
+
var point = (value) => {
|
|
34
|
+
const { latitude, longitude } = toLatLng(value);
|
|
35
|
+
return `${latitude},${longitude}`;
|
|
36
|
+
};
|
|
37
|
+
var points = (values) => values.map(point).join("|");
|
|
38
|
+
|
|
39
|
+
// src/geocode.ts
|
|
40
|
+
var url = "https://maps.googleapis.com/maps/api/geocode/json";
|
|
41
|
+
var components = (value) => typeof value === "object" ? Object.entries(value).map(([k, v]) => `${k}:${v}`).join("|") : value;
|
|
42
|
+
function createGeocoding(send) {
|
|
43
|
+
const run = async (query, call) => checkStatus(await send({ method: "GET", url, keyIn: "query", query }, call), "Geocoding")?.results ?? [];
|
|
44
|
+
const geocode = ({ address, placeId, components: filter, bounds, language, region }, call) => run(
|
|
45
|
+
{
|
|
46
|
+
address,
|
|
47
|
+
place_id: placeId,
|
|
48
|
+
components: components(filter),
|
|
49
|
+
bounds: bounds && `${point(bounds.low)}|${point(bounds.high)}`,
|
|
50
|
+
language,
|
|
51
|
+
region
|
|
52
|
+
},
|
|
53
|
+
call
|
|
54
|
+
);
|
|
55
|
+
const reverseGeocode = ({ location, resultType, locationType, language }, call) => run({ latlng: point(location), result_type: resultType?.join("|"), location_type: locationType?.join("|"), language }, call);
|
|
56
|
+
return { geocode, reverseGeocode };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/services.ts
|
|
60
|
+
var seconds2 = (t) => typeof t === "number" ? Math.floor(t) : Math.floor(t.getTime() / 1e3);
|
|
61
|
+
function createServices(send) {
|
|
62
|
+
const elevation = async (request, call) => {
|
|
63
|
+
const query = "locations" in request ? { locations: points(request.locations) } : { path: points(request.path), samples: request.samples };
|
|
64
|
+
const body = await send(
|
|
65
|
+
{ method: "GET", url: "https://maps.googleapis.com/maps/api/elevation/json", keyIn: "query", query },
|
|
66
|
+
call
|
|
67
|
+
);
|
|
68
|
+
return checkStatus(body, "Elevation")?.results ?? [];
|
|
69
|
+
};
|
|
70
|
+
const timezone = async ({ location, timestamp = /* @__PURE__ */ new Date(), language }, call) => {
|
|
71
|
+
const body = await send(
|
|
72
|
+
{
|
|
73
|
+
method: "GET",
|
|
74
|
+
url: "https://maps.googleapis.com/maps/api/timezone/json",
|
|
75
|
+
keyIn: "query",
|
|
76
|
+
query: { location: point(location), timestamp: seconds2(timestamp), language }
|
|
77
|
+
},
|
|
78
|
+
call
|
|
79
|
+
);
|
|
80
|
+
const zone = checkStatus(body, "Time Zone");
|
|
81
|
+
return zone && { dstOffset: zone.dstOffset, rawOffset: zone.rawOffset, timeZoneId: zone.timeZoneId, timeZoneName: zone.timeZoneName };
|
|
82
|
+
};
|
|
83
|
+
const geolocate = (request = {}, call) => send({ method: "POST", url: "https://www.googleapis.com/geolocation/v1/geolocate", body: request }, call);
|
|
84
|
+
const roads = {
|
|
85
|
+
/** Snaps a GPS trace to the roads it most likely followed */
|
|
86
|
+
snap: async ({ path, interpolate }, call) => (await send(
|
|
87
|
+
{ method: "GET", url: "https://roads.googleapis.com/v1/snapToRoads", query: { path: points(path), interpolate } },
|
|
88
|
+
call
|
|
89
|
+
)).snappedPoints ?? [],
|
|
90
|
+
/** The nearest road segment for each point, independently */
|
|
91
|
+
nearest: async ({ points: list }, call) => (await send(
|
|
92
|
+
{ method: "GET", url: "https://roads.googleapis.com/v1/nearestRoads", query: { points: points(list) } },
|
|
93
|
+
call
|
|
94
|
+
)).snappedPoints ?? []
|
|
95
|
+
};
|
|
96
|
+
return { elevation, timezone, geolocate, roads };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/index.ts
|
|
100
|
+
function createClient(options) {
|
|
101
|
+
const send = createTransport(options);
|
|
102
|
+
return {
|
|
103
|
+
places: createPlaces(send),
|
|
104
|
+
routes: createRoutes(send),
|
|
105
|
+
addressValidation: createAddressValidation(send),
|
|
106
|
+
...createGeocoding(send),
|
|
107
|
+
...createServices(send),
|
|
108
|
+
/**
|
|
109
|
+
* Any Google Maps Platform REST endpoint, with the key, field mask, retries, timeouts and errors handled.
|
|
110
|
+
* The key goes in the X-Goog-Api-Key header, or in the query string with keyIn: 'query' for the older JSON APIs.
|
|
111
|
+
*/
|
|
112
|
+
request: (request, call) => send(request, call)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
MapsError,
|
|
117
|
+
createClient,
|
|
118
|
+
matrixFields,
|
|
119
|
+
newSessionToken,
|
|
120
|
+
placeFields,
|
|
121
|
+
routeFields,
|
|
122
|
+
searchNearbyFields,
|
|
123
|
+
searchTextFields,
|
|
124
|
+
seconds,
|
|
125
|
+
toLatLng,
|
|
126
|
+
toWaypoint
|
|
127
|
+
};
|