@chaosity/location-client 0.5.0 → 0.6.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/README.md +14 -0
- package/dist/adapters/GeoPlaces.d.ts +1 -1
- package/dist/auth/TokenProvider.js +3 -3
- package/dist/cjs/adapters/GeoPlaces.d.ts +64 -0
- package/dist/cjs/adapters/GeoPlaces.js +213 -0
- package/dist/cjs/auth/TokenProvider.d.ts +64 -0
- package/dist/cjs/auth/TokenProvider.js +144 -0
- package/dist/cjs/auth/tokenRefresh.d.ts +37 -0
- package/dist/cjs/auth/tokenRefresh.js +58 -0
- package/dist/cjs/client/GeoPlacesClient.d.ts +39 -0
- package/dist/cjs/client/GeoPlacesClient.js +68 -0
- package/dist/cjs/errors/LocationServiceException.d.ts +44 -0
- package/dist/cjs/errors/LocationServiceException.js +60 -0
- package/dist/cjs/index.d.ts +24 -0
- package/dist/cjs/index.js +72 -0
- package/dist/cjs/maps/Utils.d.ts +2 -0
- package/dist/cjs/maps/Utils.js +8 -0
- package/dist/cjs/maps/createTransformRequest.d.ts +10 -0
- package/dist/cjs/maps/createTransformRequest.js +43 -0
- package/dist/cjs/maps/mapEnums.d.ts +102 -0
- package/dist/cjs/maps/mapEnums.js +103 -0
- package/dist/cjs/maps/mapLanguage.d.ts +43 -0
- package/dist/cjs/maps/mapLanguage.js +75 -0
- package/dist/cjs/maps/mapPoi.d.ts +44 -0
- package/dist/cjs/maps/mapPoi.js +64 -0
- package/dist/cjs/maps/mapStyle.d.ts +77 -0
- package/dist/cjs/maps/mapStyle.js +111 -0
- package/dist/cjs/maps/staticMap.d.ts +85 -0
- package/dist/cjs/maps/staticMap.js +81 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/server/LocationServiceConnector.d.ts +55 -0
- package/dist/cjs/server/LocationServiceConnector.js +91 -0
- package/dist/cjs/server/getClientConfig.d.ts +40 -0
- package/dist/cjs/server/getClientConfig.js +130 -0
- package/dist/cjs/server/index.d.ts +6 -0
- package/dist/cjs/server/index.js +9 -0
- package/dist/cjs/transport/endpoints.d.ts +2 -0
- package/dist/cjs/transport/endpoints.js +34 -0
- package/dist/cjs/transport/errors.d.ts +19 -0
- package/dist/cjs/transport/errors.js +104 -0
- package/dist/cjs/transport/http.d.ts +24 -0
- package/dist/cjs/transport/http.js +142 -0
- package/dist/cjs/types/index.d.ts +34 -0
- package/dist/cjs/types/index.js +3 -0
- package/dist/cjs/utils/roundPosition.d.ts +66 -0
- package/dist/cjs/utils/roundPosition.js +109 -0
- package/dist/cjs/utils/tokenClaims.d.ts +55 -0
- package/dist/cjs/utils/tokenClaims.js +61 -0
- package/dist/client/GeoPlacesClient.d.ts +3 -3
- package/dist/client/GeoPlacesClient.js +4 -4
- package/dist/index.d.ts +22 -22
- package/dist/index.js +12 -12
- package/dist/maps/Utils.d.ts +1 -1
- package/dist/maps/Utils.js +1 -1
- package/dist/maps/createTransformRequest.js +1 -1
- package/dist/maps/mapLanguage.d.ts +31 -7
- package/dist/maps/mapLanguage.js +50 -20
- package/dist/maps/mapStyle.d.ts +1 -1
- package/dist/maps/mapStyle.js +17 -16
- package/dist/maps/staticMap.d.ts +1 -1
- package/dist/maps/staticMap.js +12 -4
- package/dist/server/LocationServiceConnector.d.ts +2 -2
- package/dist/server/LocationServiceConnector.js +6 -6
- package/dist/server/getClientConfig.d.ts +1 -1
- package/dist/server/getClientConfig.js +2 -2
- package/dist/server/index.d.ts +6 -6
- package/dist/server/index.js +3 -3
- package/dist/transport/endpoints.d.ts +1 -1
- package/dist/transport/endpoints.js +1 -1
- package/dist/transport/errors.d.ts +1 -1
- package/dist/transport/errors.js +1 -1
- package/dist/transport/http.js +2 -2
- package/package.json +33 -11
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GeoPlacesClient = void 0;
|
|
7
|
+
const debug_1 = __importDefault(require("debug"));
|
|
8
|
+
const endpoints_js_1 = require("../transport/endpoints.js");
|
|
9
|
+
const http_js_1 = require("../transport/http.js");
|
|
10
|
+
const roundPosition_js_1 = require("../utils/roundPosition.js");
|
|
11
|
+
const tokenClaims_js_1 = require("../utils/tokenClaims.js");
|
|
12
|
+
const log = (0, debug_1.default)('location-client:api');
|
|
13
|
+
/**
|
|
14
|
+
* GeoPlacesClient — AWS Location Service compatible client with custom auth.
|
|
15
|
+
*
|
|
16
|
+
* Uses AWS SDK command classes but replaces SigV4 with a Bearer token. All
|
|
17
|
+
* request and response types are identical to AWS Location Service.
|
|
18
|
+
*
|
|
19
|
+
* Pass `getToken` in config for live refresh without recreating the client.
|
|
20
|
+
*/
|
|
21
|
+
class GeoPlacesClient {
|
|
22
|
+
constructor(config) {
|
|
23
|
+
this.clientConfig = config;
|
|
24
|
+
this.config = { serviceId: 'Geo Places' };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* This application's own configuration, as carried on the access token
|
|
28
|
+
* (api#65) — bias precision, and the countries it is scoped to.
|
|
29
|
+
*
|
|
30
|
+
* Provided so an application can SHOW its own settings: populate a country
|
|
31
|
+
* selector with the markets it actually serves, label a settings screen,
|
|
32
|
+
* and so on. Being a few minutes stale is cosmetic for that.
|
|
33
|
+
*
|
|
34
|
+
* It is not an entitlement check. See AppConfigClaims for why acting on
|
|
35
|
+
* `countries` client-side makes requests fail that would otherwise succeed.
|
|
36
|
+
*
|
|
37
|
+
* Returns `{}` when the token carries no application config, which is the
|
|
38
|
+
* case until one is configured in the portal.
|
|
39
|
+
*/
|
|
40
|
+
getAppConfig() {
|
|
41
|
+
const token = this.clientConfig.getToken?.() ?? this.clientConfig.token;
|
|
42
|
+
return (0, tokenClaims_js_1.readAppConfigClaims)(token);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @param options `signal` to cancel, `timeoutMs` per attempt, `retry: false`
|
|
46
|
+
* to disable the retry loop. Every failure throws LocationServiceException.
|
|
47
|
+
*/
|
|
48
|
+
async send(command, options) {
|
|
49
|
+
const cmd = command;
|
|
50
|
+
const endpoint = (0, endpoints_js_1.resolveEndpoint)(cmd);
|
|
51
|
+
// Prefer the getToken callback (live ref) over a static token string.
|
|
52
|
+
const token = this.clientConfig.getToken?.() ?? this.clientConfig.token;
|
|
53
|
+
// Resolve the token BEFORE rounding: the precision this application is
|
|
54
|
+
// entitled to is a claim on it (api#65). Absent claim -> the 3 dp floor.
|
|
55
|
+
const { biasDecimals } = (0, tokenClaims_js_1.readAppConfigClaims)(token);
|
|
56
|
+
const input = (0, roundPosition_js_1.roundPositionFields)(cmd.input, biasDecimals);
|
|
57
|
+
log('Sending %s to %s', cmd.constructor?.name, endpoint);
|
|
58
|
+
return (0, http_js_1.requestJson)(`${this.clientConfig.apiUrl}${endpoint}`, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: {
|
|
61
|
+
'Content-Type': 'application/json',
|
|
62
|
+
Authorization: `Bearer ${token}`,
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify(input),
|
|
65
|
+
}, options);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.GeoPlacesClient = GeoPlacesClient;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface LocationServiceExceptionOptions {
|
|
2
|
+
message: string;
|
|
3
|
+
code: string;
|
|
4
|
+
/** Absent for failures that never reached the server: network, timeout, abort. */
|
|
5
|
+
statusCode?: number;
|
|
6
|
+
requestId?: string;
|
|
7
|
+
/** Structured extras — `source: 'client'` marks a locally-raised failure. */
|
|
8
|
+
details?: Record<string, unknown>;
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
/** Parsed from the `Retry-After` header, in milliseconds. */
|
|
11
|
+
retryAfterMs?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The single error type this package throws.
|
|
15
|
+
*
|
|
16
|
+
* Every failure — an API error envelope, a network fault, a timeout, an abort —
|
|
17
|
+
* arrives as one of these, so a caller writes one `catch` and asks the getters
|
|
18
|
+
* rather than sniffing at `TypeError` vs `DOMException` vs a bare `Error`.
|
|
19
|
+
*/
|
|
20
|
+
export declare class LocationServiceException extends Error {
|
|
21
|
+
readonly code: string;
|
|
22
|
+
readonly statusCode?: number;
|
|
23
|
+
readonly requestId?: string;
|
|
24
|
+
readonly details?: Record<string, unknown>;
|
|
25
|
+
readonly retryAfterMs?: number;
|
|
26
|
+
constructor(options: LocationServiceExceptionOptions);
|
|
27
|
+
/**
|
|
28
|
+
* Worth another attempt.
|
|
29
|
+
*
|
|
30
|
+
* Deliberately a explicit list rather than `statusCode >= 500`: a 500 or 501
|
|
31
|
+
* means the server broke on this request and will break again, while 502/503/
|
|
32
|
+
* 504 mean it never got there or gave up waiting. Retrying the first kind just
|
|
33
|
+
* multiplies the damage. Network failures and timeouts are retryable because
|
|
34
|
+
* nothing was necessarily processed.
|
|
35
|
+
*/
|
|
36
|
+
get isRetryable(): boolean;
|
|
37
|
+
get isThrottling(): boolean;
|
|
38
|
+
get isValidation(): boolean;
|
|
39
|
+
/** Credentials or entitlements — the caller must act, retrying will not help. */
|
|
40
|
+
get isAuth(): boolean;
|
|
41
|
+
get isAborted(): boolean;
|
|
42
|
+
get isTimeout(): boolean;
|
|
43
|
+
toString(): string;
|
|
44
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocationServiceException = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The single error type this package throws.
|
|
6
|
+
*
|
|
7
|
+
* Every failure — an API error envelope, a network fault, a timeout, an abort —
|
|
8
|
+
* arrives as one of these, so a caller writes one `catch` and asks the getters
|
|
9
|
+
* rather than sniffing at `TypeError` vs `DOMException` vs a bare `Error`.
|
|
10
|
+
*/
|
|
11
|
+
class LocationServiceException extends Error {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options.message, { cause: options.cause });
|
|
14
|
+
this.name = 'LocationServiceException';
|
|
15
|
+
this.code = options.code;
|
|
16
|
+
this.statusCode = options.statusCode;
|
|
17
|
+
this.requestId = options.requestId;
|
|
18
|
+
this.details = options.details;
|
|
19
|
+
this.retryAfterMs = options.retryAfterMs;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Worth another attempt.
|
|
23
|
+
*
|
|
24
|
+
* Deliberately a explicit list rather than `statusCode >= 500`: a 500 or 501
|
|
25
|
+
* means the server broke on this request and will break again, while 502/503/
|
|
26
|
+
* 504 mean it never got there or gave up waiting. Retrying the first kind just
|
|
27
|
+
* multiplies the damage. Network failures and timeouts are retryable because
|
|
28
|
+
* nothing was necessarily processed.
|
|
29
|
+
*/
|
|
30
|
+
get isRetryable() {
|
|
31
|
+
if (this.code === 'AbortedException')
|
|
32
|
+
return false;
|
|
33
|
+
if (this.code === 'NetworkException' || this.code === 'TimeoutException')
|
|
34
|
+
return true;
|
|
35
|
+
return (this.statusCode === 429 || [502, 503, 504].includes(this.statusCode ?? 0));
|
|
36
|
+
}
|
|
37
|
+
get isThrottling() {
|
|
38
|
+
return this.code === 'ThrottlingException' || this.statusCode === 429;
|
|
39
|
+
}
|
|
40
|
+
get isValidation() {
|
|
41
|
+
return this.code === 'ValidationException' || this.statusCode === 400;
|
|
42
|
+
}
|
|
43
|
+
/** Credentials or entitlements — the caller must act, retrying will not help. */
|
|
44
|
+
get isAuth() {
|
|
45
|
+
return this.statusCode === 401 || this.statusCode === 403;
|
|
46
|
+
}
|
|
47
|
+
get isAborted() {
|
|
48
|
+
return this.code === 'AbortedException';
|
|
49
|
+
}
|
|
50
|
+
get isTimeout() {
|
|
51
|
+
return this.code === 'TimeoutException';
|
|
52
|
+
}
|
|
53
|
+
toString() {
|
|
54
|
+
const parts = [`LocationServiceException: [${this.code}] ${this.message}`];
|
|
55
|
+
if (this.requestId)
|
|
56
|
+
parts.push(`(requestId: ${this.requestId})`);
|
|
57
|
+
return parts.join(' ');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.LocationServiceException = LocationServiceException;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { GeoPlacesClient } from './client/GeoPlacesClient.js';
|
|
2
|
+
export type { SendOptions } from './client/GeoPlacesClient.js';
|
|
3
|
+
export { DEFAULT_MAX_ATTEMPTS, DEFAULT_TIMEOUT_MS } from './transport/http.js';
|
|
4
|
+
export type { RequestOptions } from './transport/http.js';
|
|
5
|
+
export { TOKEN_REFRESH_BUFFER_SECONDS, readTokenExpiry, } from './auth/tokenRefresh.js';
|
|
6
|
+
export { LocationServiceException } from './errors/LocationServiceException.js';
|
|
7
|
+
export type { LocationServiceExceptionOptions } from './errors/LocationServiceException.js';
|
|
8
|
+
export * from '@aws-sdk/client-geo-places';
|
|
9
|
+
export * from '@aws/amazon-location-utilities-datatypes';
|
|
10
|
+
export { GeoPlaces } from './adapters/GeoPlaces.js';
|
|
11
|
+
export type { GeoPlacesDetailOptions, GeoPlacesOptions, } from './adapters/GeoPlaces.js';
|
|
12
|
+
export { createTransformRequest } from './maps/createTransformRequest.js';
|
|
13
|
+
export { applyMapLanguage } from './maps/mapLanguage.js';
|
|
14
|
+
export { POI_CATEGORIES, setAllPoiVisibility, setPoiVisibility, } from './maps/mapPoi.js';
|
|
15
|
+
export type { PoiCategory } from './maps/mapPoi.js';
|
|
16
|
+
export { buildMapStyleUrl, fetchMapStyle } from './maps/mapStyle.js';
|
|
17
|
+
export type { MapStyleOptions } from './maps/mapStyle.js';
|
|
18
|
+
export { buildStaticMapUrl, fetchStaticMap, staticMapAccept, } from './maps/staticMap.js';
|
|
19
|
+
export type { StaticMapFileName, StaticMapOptions } from './maps/staticMap.js';
|
|
20
|
+
export { BUILDINGS, COLOR_SCHEMES, CONTOUR_DENSITIES, LABEL_SIZES, MAP_FEATURE_MODES, MAP_STYLES, SCALE_BAR_UNITS, SPRITE_VARIANTS, STATIC_MAP_STYLES, TERRAINS, TRAFFIC_MODES, TRAVEL_MODES, } from './maps/mapEnums.js';
|
|
21
|
+
export type { Buildings, ColorScheme, ContourDensity, LabelSize, MapFeatureMode, MapStyle, ScaleBarUnit, SpriteVariant, StaticMapStyle, Terrain, TrafficMode, TravelMode, } from './maps/mapEnums.js';
|
|
22
|
+
export { transformRequest } from './maps/Utils.js';
|
|
23
|
+
export type { ClientConfig, GeoPlacesCommand, MapLike } from './types/index.js';
|
|
24
|
+
export type { AppConfigClaims } from './utils/tokenClaims.js';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.transformRequest = exports.TRAVEL_MODES = exports.TRAFFIC_MODES = exports.TERRAINS = exports.STATIC_MAP_STYLES = exports.SPRITE_VARIANTS = exports.SCALE_BAR_UNITS = exports.MAP_STYLES = exports.MAP_FEATURE_MODES = exports.LABEL_SIZES = exports.CONTOUR_DENSITIES = exports.COLOR_SCHEMES = exports.BUILDINGS = exports.staticMapAccept = exports.fetchStaticMap = exports.buildStaticMapUrl = exports.fetchMapStyle = exports.buildMapStyleUrl = exports.setPoiVisibility = exports.setAllPoiVisibility = exports.POI_CATEGORIES = exports.applyMapLanguage = exports.createTransformRequest = exports.GeoPlaces = exports.LocationServiceException = exports.readTokenExpiry = exports.TOKEN_REFRESH_BUFFER_SECONDS = exports.DEFAULT_TIMEOUT_MS = exports.DEFAULT_MAX_ATTEMPTS = exports.GeoPlacesClient = void 0;
|
|
18
|
+
// Client (Custom - uses our auth instead of AWS SigV4)
|
|
19
|
+
var GeoPlacesClient_js_1 = require("./client/GeoPlacesClient.js");
|
|
20
|
+
Object.defineProperty(exports, "GeoPlacesClient", { enumerable: true, get: function () { return GeoPlacesClient_js_1.GeoPlacesClient; } });
|
|
21
|
+
// Transport options — cancellation, per-attempt timeout, retry policy
|
|
22
|
+
var http_js_1 = require("./transport/http.js");
|
|
23
|
+
Object.defineProperty(exports, "DEFAULT_MAX_ATTEMPTS", { enumerable: true, get: function () { return http_js_1.DEFAULT_MAX_ATTEMPTS; } });
|
|
24
|
+
Object.defineProperty(exports, "DEFAULT_TIMEOUT_MS", { enumerable: true, get: function () { return http_js_1.DEFAULT_TIMEOUT_MS; } });
|
|
25
|
+
// Token refresh policy — shared by the server provider and the React provider
|
|
26
|
+
var tokenRefresh_js_1 = require("./auth/tokenRefresh.js");
|
|
27
|
+
Object.defineProperty(exports, "TOKEN_REFRESH_BUFFER_SECONDS", { enumerable: true, get: function () { return tokenRefresh_js_1.TOKEN_REFRESH_BUFFER_SECONDS; } });
|
|
28
|
+
Object.defineProperty(exports, "readTokenExpiry", { enumerable: true, get: function () { return tokenRefresh_js_1.readTokenExpiry; } });
|
|
29
|
+
// Errors
|
|
30
|
+
var LocationServiceException_js_1 = require("./errors/LocationServiceException.js");
|
|
31
|
+
Object.defineProperty(exports, "LocationServiceException", { enumerable: true, get: function () { return LocationServiceException_js_1.LocationServiceException; } });
|
|
32
|
+
// Re-export AWS SDK commands and types
|
|
33
|
+
__exportStar(require("@aws-sdk/client-geo-places"), exports);
|
|
34
|
+
// Re-export AWS Location Utilities (data type conversions)
|
|
35
|
+
__exportStar(require("@aws/amazon-location-utilities-datatypes"), exports);
|
|
36
|
+
// Adapters (Custom - for MapLibre integration)
|
|
37
|
+
var GeoPlaces_js_1 = require("./adapters/GeoPlaces.js");
|
|
38
|
+
Object.defineProperty(exports, "GeoPlaces", { enumerable: true, get: function () { return GeoPlaces_js_1.GeoPlaces; } });
|
|
39
|
+
// Maps utilities
|
|
40
|
+
var createTransformRequest_js_1 = require("./maps/createTransformRequest.js");
|
|
41
|
+
Object.defineProperty(exports, "createTransformRequest", { enumerable: true, get: function () { return createTransformRequest_js_1.createTransformRequest; } });
|
|
42
|
+
var mapLanguage_js_1 = require("./maps/mapLanguage.js");
|
|
43
|
+
Object.defineProperty(exports, "applyMapLanguage", { enumerable: true, get: function () { return mapLanguage_js_1.applyMapLanguage; } });
|
|
44
|
+
var mapPoi_js_1 = require("./maps/mapPoi.js");
|
|
45
|
+
Object.defineProperty(exports, "POI_CATEGORIES", { enumerable: true, get: function () { return mapPoi_js_1.POI_CATEGORIES; } });
|
|
46
|
+
Object.defineProperty(exports, "setAllPoiVisibility", { enumerable: true, get: function () { return mapPoi_js_1.setAllPoiVisibility; } });
|
|
47
|
+
Object.defineProperty(exports, "setPoiVisibility", { enumerable: true, get: function () { return mapPoi_js_1.setPoiVisibility; } });
|
|
48
|
+
var mapStyle_js_1 = require("./maps/mapStyle.js");
|
|
49
|
+
Object.defineProperty(exports, "buildMapStyleUrl", { enumerable: true, get: function () { return mapStyle_js_1.buildMapStyleUrl; } });
|
|
50
|
+
Object.defineProperty(exports, "fetchMapStyle", { enumerable: true, get: function () { return mapStyle_js_1.fetchMapStyle; } });
|
|
51
|
+
var staticMap_js_1 = require("./maps/staticMap.js");
|
|
52
|
+
Object.defineProperty(exports, "buildStaticMapUrl", { enumerable: true, get: function () { return staticMap_js_1.buildStaticMapUrl; } });
|
|
53
|
+
Object.defineProperty(exports, "fetchStaticMap", { enumerable: true, get: function () { return staticMap_js_1.fetchStaticMap; } });
|
|
54
|
+
Object.defineProperty(exports, "staticMapAccept", { enumerable: true, get: function () { return staticMap_js_1.staticMapAccept; } });
|
|
55
|
+
// Accepted values for every map parameter, as VALUES so a picker can be built
|
|
56
|
+
// from them, plus the matching types. Case sensitive — see mapEnums.ts.
|
|
57
|
+
var mapEnums_js_1 = require("./maps/mapEnums.js");
|
|
58
|
+
Object.defineProperty(exports, "BUILDINGS", { enumerable: true, get: function () { return mapEnums_js_1.BUILDINGS; } });
|
|
59
|
+
Object.defineProperty(exports, "COLOR_SCHEMES", { enumerable: true, get: function () { return mapEnums_js_1.COLOR_SCHEMES; } });
|
|
60
|
+
Object.defineProperty(exports, "CONTOUR_DENSITIES", { enumerable: true, get: function () { return mapEnums_js_1.CONTOUR_DENSITIES; } });
|
|
61
|
+
Object.defineProperty(exports, "LABEL_SIZES", { enumerable: true, get: function () { return mapEnums_js_1.LABEL_SIZES; } });
|
|
62
|
+
Object.defineProperty(exports, "MAP_FEATURE_MODES", { enumerable: true, get: function () { return mapEnums_js_1.MAP_FEATURE_MODES; } });
|
|
63
|
+
Object.defineProperty(exports, "MAP_STYLES", { enumerable: true, get: function () { return mapEnums_js_1.MAP_STYLES; } });
|
|
64
|
+
Object.defineProperty(exports, "SCALE_BAR_UNITS", { enumerable: true, get: function () { return mapEnums_js_1.SCALE_BAR_UNITS; } });
|
|
65
|
+
Object.defineProperty(exports, "SPRITE_VARIANTS", { enumerable: true, get: function () { return mapEnums_js_1.SPRITE_VARIANTS; } });
|
|
66
|
+
Object.defineProperty(exports, "STATIC_MAP_STYLES", { enumerable: true, get: function () { return mapEnums_js_1.STATIC_MAP_STYLES; } });
|
|
67
|
+
Object.defineProperty(exports, "TERRAINS", { enumerable: true, get: function () { return mapEnums_js_1.TERRAINS; } });
|
|
68
|
+
Object.defineProperty(exports, "TRAFFIC_MODES", { enumerable: true, get: function () { return mapEnums_js_1.TRAFFIC_MODES; } });
|
|
69
|
+
Object.defineProperty(exports, "TRAVEL_MODES", { enumerable: true, get: function () { return mapEnums_js_1.TRAVEL_MODES; } });
|
|
70
|
+
var Utils_js_1 = require("./maps/Utils.js");
|
|
71
|
+
Object.defineProperty(exports, "transformRequest", { enumerable: true, get: function () { return Utils_js_1.transformRequest; } });
|
|
72
|
+
// Server-only utilities are available via '@chaosity/location-client/server'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformRequest = transformRequest;
|
|
4
|
+
const createTransformRequest_js_1 = require("./createTransformRequest.js");
|
|
5
|
+
function transformRequest(url, config) {
|
|
6
|
+
const token = config.getToken?.() ?? config.token;
|
|
7
|
+
return (0, createTransformRequest_js_1.createTransformRequest)(config.apiUrl, () => token)(url);
|
|
8
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RequestTransformFunction } from 'maplibre-gl';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a transformRequest function for MapLibre that adds authentication
|
|
4
|
+
* and proper Accept headers for AWS Location Service API requests.
|
|
5
|
+
*
|
|
6
|
+
* @param apiUrl - Base URL of the Location Service API
|
|
7
|
+
* @param getToken - Callback function that returns the current auth token
|
|
8
|
+
* @returns MapLibre transformRequest function
|
|
9
|
+
*/
|
|
10
|
+
export declare function createTransformRequest(apiUrl: string, getToken: () => string | undefined): RequestTransformFunction;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTransformRequest = createTransformRequest;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a transformRequest function for MapLibre that adds authentication
|
|
6
|
+
* and proper Accept headers for AWS Location Service API requests.
|
|
7
|
+
*
|
|
8
|
+
* @param apiUrl - Base URL of the Location Service API
|
|
9
|
+
* @param getToken - Callback function that returns the current auth token
|
|
10
|
+
* @returns MapLibre transformRequest function
|
|
11
|
+
*/
|
|
12
|
+
function createTransformRequest(apiUrl, getToken) {
|
|
13
|
+
return (url, _resourceType) => {
|
|
14
|
+
if (url.startsWith(apiUrl)) {
|
|
15
|
+
const token = getToken();
|
|
16
|
+
if (!token) {
|
|
17
|
+
console.warn('[createTransformRequest] No token available');
|
|
18
|
+
return { url };
|
|
19
|
+
}
|
|
20
|
+
const headers = {
|
|
21
|
+
Authorization: `Bearer ${token}`,
|
|
22
|
+
};
|
|
23
|
+
// Set appropriate Accept headers based on resource type
|
|
24
|
+
if (url.includes('/tiles/')) {
|
|
25
|
+
headers['Accept'] = 'application/x-protobuf';
|
|
26
|
+
}
|
|
27
|
+
else if (url.includes('/glyphs/')) {
|
|
28
|
+
headers['Accept'] = 'application/x-protobuf';
|
|
29
|
+
}
|
|
30
|
+
else if (url.includes('/sprites/') && url.endsWith('.png')) {
|
|
31
|
+
headers['Accept'] = 'image/png';
|
|
32
|
+
}
|
|
33
|
+
else if (url.includes('/sprites/') && url.endsWith('.json')) {
|
|
34
|
+
headers['Accept'] = 'application/json';
|
|
35
|
+
}
|
|
36
|
+
else if (url.includes('/descriptor')) {
|
|
37
|
+
headers['Accept'] = 'application/json';
|
|
38
|
+
}
|
|
39
|
+
return { url, headers };
|
|
40
|
+
}
|
|
41
|
+
return { url };
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The values Amazon Location accepts for each map parameter.
|
|
3
|
+
*
|
|
4
|
+
* WHY THESE ARE EXPORTED AS VALUES, NOT JUST TYPES
|
|
5
|
+
*
|
|
6
|
+
* A type union gives you compile-time safety and nothing to iterate. Every
|
|
7
|
+
* consumer that renders a style picker then re-types the same list by hand into
|
|
8
|
+
* a `<select>`, and those copies drift the moment AWS adds a style. Exporting
|
|
9
|
+
* the arrays means a dropdown is `MAP_STYLES.map(...)` and cannot disagree with
|
|
10
|
+
* the type beside it.
|
|
11
|
+
*
|
|
12
|
+
* THESE ARE CASE SENSITIVE
|
|
13
|
+
*
|
|
14
|
+
* AWS documents them so, and since location-service-api#89 the API enforces it
|
|
15
|
+
* rather than forwarding a wrong-cased value for Amazon to reject with an
|
|
16
|
+
* unhelpful 404. `'light'` is not `'Light'`:
|
|
17
|
+
*
|
|
18
|
+
* GET /maps/Standard/descriptor?colorScheme=light
|
|
19
|
+
* 400 "'colorScheme' is case sensitive — use 'Light', not 'light'"
|
|
20
|
+
*
|
|
21
|
+
* So take the values from here rather than typing them, and the case is right
|
|
22
|
+
* by construction.
|
|
23
|
+
*
|
|
24
|
+
* MEMBERSHIP IS NOT THE WHOLE STORY
|
|
25
|
+
*
|
|
26
|
+
* A value being in one of these lists does not mean it is legal in every
|
|
27
|
+
* COMBINATION. `Traffic: 'All'` is valid, and `Style: 'Satellite'` is valid,
|
|
28
|
+
* but together they are not:
|
|
29
|
+
*
|
|
30
|
+
* 400 "Traffic is not supported for style."
|
|
31
|
+
*
|
|
32
|
+
* Amazon owns those rules and answers them per request; the API forwards that
|
|
33
|
+
* message verbatim. Do not try to encode combination rules here — they change
|
|
34
|
+
* without an SDK release.
|
|
35
|
+
*
|
|
36
|
+
* KEEPING THESE HONEST
|
|
37
|
+
*
|
|
38
|
+
* The API derives its copy from the AWS SDK's own `enums.d.ts` via
|
|
39
|
+
* `npm run generate:maps-enums`, so that side cannot drift. This file is the
|
|
40
|
+
* client-side mirror and every value below was additionally confirmed against
|
|
41
|
+
* the live geo-maps API on 2026-08-26. If the API starts rejecting something
|
|
42
|
+
* listed here, its generated list is the authority.
|
|
43
|
+
*/
|
|
44
|
+
/** Map styles for the style descriptor. */
|
|
45
|
+
export declare const MAP_STYLES: readonly ["Hybrid", "Monochrome", "Satellite", "Standard"];
|
|
46
|
+
export type MapStyle = (typeof MAP_STYLES)[number];
|
|
47
|
+
/**
|
|
48
|
+
* Styles the STATIC map accepts — deliberately narrower than `MAP_STYLES`.
|
|
49
|
+
*
|
|
50
|
+
* `/maps/static/*` takes only Satellite and Standard. Passing Hybrid or
|
|
51
|
+
* Monochrome there is a 400, so the two lists are not interchangeable.
|
|
52
|
+
*/
|
|
53
|
+
export declare const STATIC_MAP_STYLES: readonly ["Satellite", "Standard"];
|
|
54
|
+
export type StaticMapStyle = (typeof STATIC_MAP_STYLES)[number];
|
|
55
|
+
/** Light or dark cartography. Not applicable to the raster styles. */
|
|
56
|
+
export declare const COLOR_SCHEMES: readonly ["Dark", "Light"];
|
|
57
|
+
export type ColorScheme = (typeof COLOR_SCHEMES)[number];
|
|
58
|
+
/** Terrain overlay. `Hillshade` is shaded relief; `Terrain3D` is elevation. */
|
|
59
|
+
export declare const TERRAINS: readonly ["Hillshade", "Terrain3D"];
|
|
60
|
+
export type Terrain = (typeof TERRAINS)[number];
|
|
61
|
+
/** 3D building extrusions. One value today, kept a list for when that changes. */
|
|
62
|
+
export declare const BUILDINGS: readonly ["Buildings3D"];
|
|
63
|
+
export type Buildings = (typeof BUILDINGS)[number];
|
|
64
|
+
/**
|
|
65
|
+
* Elevation contour line density.
|
|
66
|
+
*
|
|
67
|
+
* All three work. An earlier version of this library documented `Medium` as
|
|
68
|
+
* "the only value currently supported by the AWS SDK", which was wrong — `High`
|
|
69
|
+
* and `Low` were both confirmed against the live API on 2026-08-26.
|
|
70
|
+
*/
|
|
71
|
+
export declare const CONTOUR_DENSITIES: readonly ["High", "Low", "Medium"];
|
|
72
|
+
export type ContourDensity = (typeof CONTOUR_DENSITIES)[number];
|
|
73
|
+
/**
|
|
74
|
+
* Traffic overlay.
|
|
75
|
+
*
|
|
76
|
+
* `Congestion` was previously missing from this library's types, so it could
|
|
77
|
+
* not be requested from TypeScript even though the API accepts it.
|
|
78
|
+
*/
|
|
79
|
+
export declare const TRAFFIC_MODES: readonly ["All", "Congestion"];
|
|
80
|
+
export type TrafficMode = (typeof TRAFFIC_MODES)[number];
|
|
81
|
+
/** Routing overlays. Sent as a comma-separated list; each entry is checked. */
|
|
82
|
+
export declare const TRAVEL_MODES: readonly ["Transit", "Truck"];
|
|
83
|
+
export type TravelMode = (typeof TRAVEL_MODES)[number];
|
|
84
|
+
/** Sprite sheet variant. One value today. */
|
|
85
|
+
export declare const SPRITE_VARIANTS: readonly ["Default"];
|
|
86
|
+
export type SpriteVariant = (typeof SPRITE_VARIANTS)[number];
|
|
87
|
+
/** Static map label size. */
|
|
88
|
+
export declare const LABEL_SIZES: readonly ["Large", "Small"];
|
|
89
|
+
export type LabelSize = (typeof LABEL_SIZES)[number];
|
|
90
|
+
/** Static map scale bar units. */
|
|
91
|
+
export declare const SCALE_BAR_UNITS: readonly ["Kilometers", "KilometersMiles", "Miles", "MilesKilometers"];
|
|
92
|
+
export type ScaleBarUnit = (typeof SCALE_BAR_UNITS)[number];
|
|
93
|
+
/**
|
|
94
|
+
* Static map points-of-interest rendering.
|
|
95
|
+
*
|
|
96
|
+
* A MODE, not a list of categories — an easy one to get wrong, and the reason
|
|
97
|
+
* the static map route returned a confusing error before
|
|
98
|
+
* location-service-api#35. To filter POIs on an interactive map, use
|
|
99
|
+
* `setPoiVisibility` instead.
|
|
100
|
+
*/
|
|
101
|
+
export declare const MAP_FEATURE_MODES: readonly ["Disabled", "Enabled"];
|
|
102
|
+
export type MapFeatureMode = (typeof MAP_FEATURE_MODES)[number];
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The values Amazon Location accepts for each map parameter.
|
|
4
|
+
*
|
|
5
|
+
* WHY THESE ARE EXPORTED AS VALUES, NOT JUST TYPES
|
|
6
|
+
*
|
|
7
|
+
* A type union gives you compile-time safety and nothing to iterate. Every
|
|
8
|
+
* consumer that renders a style picker then re-types the same list by hand into
|
|
9
|
+
* a `<select>`, and those copies drift the moment AWS adds a style. Exporting
|
|
10
|
+
* the arrays means a dropdown is `MAP_STYLES.map(...)` and cannot disagree with
|
|
11
|
+
* the type beside it.
|
|
12
|
+
*
|
|
13
|
+
* THESE ARE CASE SENSITIVE
|
|
14
|
+
*
|
|
15
|
+
* AWS documents them so, and since location-service-api#89 the API enforces it
|
|
16
|
+
* rather than forwarding a wrong-cased value for Amazon to reject with an
|
|
17
|
+
* unhelpful 404. `'light'` is not `'Light'`:
|
|
18
|
+
*
|
|
19
|
+
* GET /maps/Standard/descriptor?colorScheme=light
|
|
20
|
+
* 400 "'colorScheme' is case sensitive — use 'Light', not 'light'"
|
|
21
|
+
*
|
|
22
|
+
* So take the values from here rather than typing them, and the case is right
|
|
23
|
+
* by construction.
|
|
24
|
+
*
|
|
25
|
+
* MEMBERSHIP IS NOT THE WHOLE STORY
|
|
26
|
+
*
|
|
27
|
+
* A value being in one of these lists does not mean it is legal in every
|
|
28
|
+
* COMBINATION. `Traffic: 'All'` is valid, and `Style: 'Satellite'` is valid,
|
|
29
|
+
* but together they are not:
|
|
30
|
+
*
|
|
31
|
+
* 400 "Traffic is not supported for style."
|
|
32
|
+
*
|
|
33
|
+
* Amazon owns those rules and answers them per request; the API forwards that
|
|
34
|
+
* message verbatim. Do not try to encode combination rules here — they change
|
|
35
|
+
* without an SDK release.
|
|
36
|
+
*
|
|
37
|
+
* KEEPING THESE HONEST
|
|
38
|
+
*
|
|
39
|
+
* The API derives its copy from the AWS SDK's own `enums.d.ts` via
|
|
40
|
+
* `npm run generate:maps-enums`, so that side cannot drift. This file is the
|
|
41
|
+
* client-side mirror and every value below was additionally confirmed against
|
|
42
|
+
* the live geo-maps API on 2026-08-26. If the API starts rejecting something
|
|
43
|
+
* listed here, its generated list is the authority.
|
|
44
|
+
*/
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.MAP_FEATURE_MODES = exports.SCALE_BAR_UNITS = exports.LABEL_SIZES = exports.SPRITE_VARIANTS = exports.TRAVEL_MODES = exports.TRAFFIC_MODES = exports.CONTOUR_DENSITIES = exports.BUILDINGS = exports.TERRAINS = exports.COLOR_SCHEMES = exports.STATIC_MAP_STYLES = exports.MAP_STYLES = void 0;
|
|
47
|
+
/** Map styles for the style descriptor. */
|
|
48
|
+
exports.MAP_STYLES = [
|
|
49
|
+
'Hybrid',
|
|
50
|
+
'Monochrome',
|
|
51
|
+
'Satellite',
|
|
52
|
+
'Standard',
|
|
53
|
+
];
|
|
54
|
+
/**
|
|
55
|
+
* Styles the STATIC map accepts — deliberately narrower than `MAP_STYLES`.
|
|
56
|
+
*
|
|
57
|
+
* `/maps/static/*` takes only Satellite and Standard. Passing Hybrid or
|
|
58
|
+
* Monochrome there is a 400, so the two lists are not interchangeable.
|
|
59
|
+
*/
|
|
60
|
+
exports.STATIC_MAP_STYLES = ['Satellite', 'Standard'];
|
|
61
|
+
/** Light or dark cartography. Not applicable to the raster styles. */
|
|
62
|
+
exports.COLOR_SCHEMES = ['Dark', 'Light'];
|
|
63
|
+
/** Terrain overlay. `Hillshade` is shaded relief; `Terrain3D` is elevation. */
|
|
64
|
+
exports.TERRAINS = ['Hillshade', 'Terrain3D'];
|
|
65
|
+
/** 3D building extrusions. One value today, kept a list for when that changes. */
|
|
66
|
+
exports.BUILDINGS = ['Buildings3D'];
|
|
67
|
+
/**
|
|
68
|
+
* Elevation contour line density.
|
|
69
|
+
*
|
|
70
|
+
* All three work. An earlier version of this library documented `Medium` as
|
|
71
|
+
* "the only value currently supported by the AWS SDK", which was wrong — `High`
|
|
72
|
+
* and `Low` were both confirmed against the live API on 2026-08-26.
|
|
73
|
+
*/
|
|
74
|
+
exports.CONTOUR_DENSITIES = ['High', 'Low', 'Medium'];
|
|
75
|
+
/**
|
|
76
|
+
* Traffic overlay.
|
|
77
|
+
*
|
|
78
|
+
* `Congestion` was previously missing from this library's types, so it could
|
|
79
|
+
* not be requested from TypeScript even though the API accepts it.
|
|
80
|
+
*/
|
|
81
|
+
exports.TRAFFIC_MODES = ['All', 'Congestion'];
|
|
82
|
+
/** Routing overlays. Sent as a comma-separated list; each entry is checked. */
|
|
83
|
+
exports.TRAVEL_MODES = ['Transit', 'Truck'];
|
|
84
|
+
/** Sprite sheet variant. One value today. */
|
|
85
|
+
exports.SPRITE_VARIANTS = ['Default'];
|
|
86
|
+
/** Static map label size. */
|
|
87
|
+
exports.LABEL_SIZES = ['Large', 'Small'];
|
|
88
|
+
/** Static map scale bar units. */
|
|
89
|
+
exports.SCALE_BAR_UNITS = [
|
|
90
|
+
'Kilometers',
|
|
91
|
+
'KilometersMiles',
|
|
92
|
+
'Miles',
|
|
93
|
+
'MilesKilometers',
|
|
94
|
+
];
|
|
95
|
+
/**
|
|
96
|
+
* Static map points-of-interest rendering.
|
|
97
|
+
*
|
|
98
|
+
* A MODE, not a list of categories — an easy one to get wrong, and the reason
|
|
99
|
+
* the static map route returned a confusing error before
|
|
100
|
+
* location-service-api#35. To filter POIs on an interactive map, use
|
|
101
|
+
* `setPoiVisibility` instead.
|
|
102
|
+
*/
|
|
103
|
+
exports.MAP_FEATURE_MODES = ['Disabled', 'Enabled'];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { MapLike } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The `text-field` expression that prefers `language`, then English, then the
|
|
4
|
+
* feature's default name.
|
|
5
|
+
*
|
|
6
|
+
* Based on the approach documented at:
|
|
7
|
+
* https://docs.aws.amazon.com/location/latest/developerguide/how-to-set-preferred-language-map.html
|
|
8
|
+
*/
|
|
9
|
+
export declare function languageExpression(language: string): unknown[];
|
|
10
|
+
/**
|
|
11
|
+
* Whether a `text-field` reads a name property — the only kind of label a
|
|
12
|
+
* language rewrite makes sense for (#28).
|
|
13
|
+
*
|
|
14
|
+
* The AWS Standard style has 62 symbol layers with a text-field and 30 of
|
|
15
|
+
* them do NOT label by name: `building_label_number` reads
|
|
16
|
+
* `addr_housenumber`, and the 29 `shield_*` layers read `shield_text` or
|
|
17
|
+
* `ref`. Replacing those with a `name:<lang>` coalesce points them at a
|
|
18
|
+
* property their features do not carry, and the house numbers and road
|
|
19
|
+
* shields disappear — for `en` too. Measured against the live sandbox on
|
|
20
|
+
* 2026-08-29; the testbed showed it as "one map has house numbers, the
|
|
21
|
+
* others don't".
|
|
22
|
+
*
|
|
23
|
+
* Serialising the expression is the simplest exact test: `name`, `name:en`,
|
|
24
|
+
* `name_en` and a literal `{name}` template all contain it, and none of the
|
|
25
|
+
* non-name properties do.
|
|
26
|
+
*/
|
|
27
|
+
export declare function labelsByName(textField: unknown): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Apply a preferred display language to the name labels on a MapLibre map.
|
|
30
|
+
*
|
|
31
|
+
* AWS GeoMaps vector tiles carry `name:${lang}` properties (`name:en`,
|
|
32
|
+
* `name:fr`, `name:ja`, …). Every symbol layer whose `text-field` reads a
|
|
33
|
+
* name is rewritten to prefer the requested language, falling back to
|
|
34
|
+
* English then the default name. Layers that label by something else — house
|
|
35
|
+
* numbers, road shields — are left exactly as the style declared them.
|
|
36
|
+
*
|
|
37
|
+
* @param map - MapLibre Map instance (or any object matching the MapLike interface)
|
|
38
|
+
* @param language - ISO 639-1 language code (e.g. 'en', 'fr', 'de', 'ja', 'zh', 'ar')
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* map.once('style.load', () => applyMapLanguage(map, 'fr'))
|
|
42
|
+
*/
|
|
43
|
+
export declare function applyMapLanguage(map: MapLike, language: string): void;
|