@chaosity/location-client 0.3.0 → 0.4.1

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/dist/index.d.ts CHANGED
@@ -15,6 +15,8 @@ export { POI_CATEGORIES, setAllPoiVisibility, setPoiVisibility, } from './maps/m
15
15
  export type { PoiCategory } from './maps/mapPoi';
16
16
  export { buildMapStyleUrl, fetchMapStyle } from './maps/mapStyle';
17
17
  export type { MapStyleOptions } from './maps/mapStyle';
18
+ 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';
19
+ export type { Buildings, ColorScheme, ContourDensity, LabelSize, MapFeatureMode, MapStyle, ScaleBarUnit, SpriteVariant, StaticMapStyle, Terrain, TrafficMode, TravelMode, } from './maps/mapEnums';
18
20
  export { transformRequest } from './maps/Utils';
19
21
  export type { ClientConfig, GeoPlacesCommand, MapLike } from './types';
20
22
  export type { AppConfigClaims } from './utils/tokenClaims';
package/dist/index.js CHANGED
@@ -17,5 +17,8 @@ export { createTransformRequest } from './maps/createTransformRequest';
17
17
  export { applyMapLanguage } from './maps/mapLanguage';
18
18
  export { POI_CATEGORIES, setAllPoiVisibility, setPoiVisibility, } from './maps/mapPoi';
19
19
  export { buildMapStyleUrl, fetchMapStyle } from './maps/mapStyle';
20
+ // Accepted values for every map parameter, as VALUES so a picker can be built
21
+ // from them, plus the matching types. Case sensitive — see mapEnums.ts.
22
+ 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';
20
23
  export { transformRequest } from './maps/Utils';
21
24
  // Server-only utilities are available via '@chaosity/location-client/server'
@@ -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,100 @@
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 const MAP_STYLES = [
46
+ 'Hybrid',
47
+ 'Monochrome',
48
+ 'Satellite',
49
+ 'Standard',
50
+ ];
51
+ /**
52
+ * Styles the STATIC map accepts — deliberately narrower than `MAP_STYLES`.
53
+ *
54
+ * `/maps/static/*` takes only Satellite and Standard. Passing Hybrid or
55
+ * Monochrome there is a 400, so the two lists are not interchangeable.
56
+ */
57
+ export const STATIC_MAP_STYLES = ['Satellite', 'Standard'];
58
+ /** Light or dark cartography. Not applicable to the raster styles. */
59
+ export const COLOR_SCHEMES = ['Dark', 'Light'];
60
+ /** Terrain overlay. `Hillshade` is shaded relief; `Terrain3D` is elevation. */
61
+ export const TERRAINS = ['Hillshade', 'Terrain3D'];
62
+ /** 3D building extrusions. One value today, kept a list for when that changes. */
63
+ export const BUILDINGS = ['Buildings3D'];
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 const CONTOUR_DENSITIES = ['High', 'Low', 'Medium'];
72
+ /**
73
+ * Traffic overlay.
74
+ *
75
+ * `Congestion` was previously missing from this library's types, so it could
76
+ * not be requested from TypeScript even though the API accepts it.
77
+ */
78
+ export const TRAFFIC_MODES = ['All', 'Congestion'];
79
+ /** Routing overlays. Sent as a comma-separated list; each entry is checked. */
80
+ export const TRAVEL_MODES = ['Transit', 'Truck'];
81
+ /** Sprite sheet variant. One value today. */
82
+ export const SPRITE_VARIANTS = ['Default'];
83
+ /** Static map label size. */
84
+ export const LABEL_SIZES = ['Large', 'Small'];
85
+ /** Static map scale bar units. */
86
+ export const SCALE_BAR_UNITS = [
87
+ 'Kilometers',
88
+ 'KilometersMiles',
89
+ 'Miles',
90
+ 'MilesKilometers',
91
+ ];
92
+ /**
93
+ * Static map points-of-interest rendering.
94
+ *
95
+ * A MODE, not a list of categories — an easy one to get wrong, and the reason
96
+ * the static map route returned a confusing error before
97
+ * location-service-api#35. To filter POIs on an interactive map, use
98
+ * `setPoiVisibility` instead.
99
+ */
100
+ export const MAP_FEATURE_MODES = ['Disabled', 'Enabled'];
@@ -1,23 +1,42 @@
1
1
  import type { StyleSpecification } from 'maplibre-gl';
2
+ import type { Buildings, ColorScheme, ContourDensity, MapStyle, Terrain, TrafficMode, TravelMode } from './mapEnums';
2
3
  /**
3
4
  * Options for building an AWS Location Service map style URL.
4
5
  * All parameters map directly to query parameters supported by the style descriptor endpoint.
6
+ *
7
+ * Values are CASE SENSITIVE — the API rejects a wrong-cased one with a 400 that
8
+ * names the right spelling. Import the arrays from `mapEnums` to build pickers
9
+ * rather than typing the values, and the case is right by construction.
5
10
  */
6
11
  export interface MapStyleOptions {
7
12
  /** Color scheme for the map (default: Light). Not applicable to Satellite/Hybrid styles. */
8
- colorScheme?: 'Light' | 'Dark';
13
+ colorScheme?: ColorScheme;
9
14
  /** ISO 3166-1 alpha-3 country code for political boundary perspective (e.g. 'IND', 'TUR'). */
10
15
  politicalView?: string;
11
16
  /** Terrain overlay type. */
12
- terrain?: 'Hillshade' | 'Terrain3D';
17
+ terrain?: Terrain;
13
18
  /** Enable 3D building extrusions. */
14
- buildings?: 'Buildings3D';
15
- /** Elevation contour line density. Only 'Medium' is currently supported by the AWS SDK. */
16
- contourDensity?: 'Medium';
17
- /** Enable real-time traffic flow visualization. */
18
- traffic?: 'All';
19
+ buildings?: Buildings;
20
+ /**
21
+ * Elevation contour line density.
22
+ *
23
+ * All of High, Low and Medium work. This was previously typed as `'Medium'`
24
+ * alone, documented as "the only value currently supported by the AWS SDK",
25
+ * which was wrong — the other two were confirmed against the live API.
26
+ */
27
+ contourDensity?: ContourDensity;
28
+ /**
29
+ * Traffic overlay.
30
+ *
31
+ * `Congestion` was previously missing here, so it could not be requested from
32
+ * TypeScript even though the API accepts it.
33
+ *
34
+ * Valid on its own, but NOT with every style: `Satellite` + `All` answers
35
+ * 400 "Traffic is not supported for style." Amazon owns that rule.
36
+ */
37
+ traffic?: TrafficMode;
19
38
  /** Travel mode overlays for routing-specific features. */
20
- travelModes?: Array<'Truck' | 'Transit'>;
39
+ travelModes?: TravelMode[];
21
40
  }
22
41
  /**
23
42
  * Build a map style descriptor URL for the Location Service API.
@@ -31,7 +50,7 @@ export interface MapStyleOptions {
31
50
  * const url = buildMapStyleUrl(API_URL, 'Standard', { colorScheme: 'Dark', terrain: 'Hillshade' })
32
51
  * map.setStyle(url)
33
52
  */
34
- export declare function buildMapStyleUrl(apiUrl: string, mapStyle: string, options?: MapStyleOptions): string;
53
+ export declare function buildMapStyleUrl(apiUrl: string, mapStyle: MapStyle, options?: MapStyleOptions): string;
35
54
  /**
36
55
  * Fetch the map style descriptor with authentication and apply descriptor-level modifications.
37
56
  *
@@ -53,6 +72,6 @@ export declare function buildMapStyleUrl(apiUrl: string, mapStyle: string, optio
53
72
  * const style = await fetchMapStyle(API_URL, 'Standard', getToken, { colorScheme: 'Dark', language: 'fr' })
54
73
  * const map = new maplibregl.Map({ style, transformRequest: createTransformRequest(API_URL, getToken) })
55
74
  */
56
- export declare function fetchMapStyle(apiUrl: string, mapStyle: string, getToken: () => string | undefined, options?: MapStyleOptions & {
75
+ export declare function fetchMapStyle(apiUrl: string, mapStyle: MapStyle, getToken: () => string | undefined, options?: MapStyleOptions & {
57
76
  language?: string;
58
77
  }): Promise<StyleSpecification>;
@@ -1,3 +1,4 @@
1
+ import { parseErrorResponse } from '../transport/errors';
1
2
  /**
2
3
  * Build a map style descriptor URL for the Location Service API.
3
4
  *
@@ -61,7 +62,19 @@ export async function fetchMapStyle(apiUrl, mapStyle, getToken, options = {}) {
61
62
  },
62
63
  });
63
64
  if (!response.ok) {
64
- throw new Error(`Failed to fetch map style: ${response.status} ${response.statusText}`);
65
+ // Read the body. The API sends `{message, code, requestId}` and the message
66
+ // is the whole point of it — for a style request it is Amazon's own
67
+ // sentence, forwarded verbatim by location-service-api#89:
68
+ //
69
+ // 400 "Traffic is not supported for style."
70
+ // 400 "light is not a supported color scheme for style Standard."
71
+ //
72
+ // This used to throw `Failed to fetch map style: 400`, discarding all of it
73
+ // two lines before anyone could read it — the same defect #89 fixed in the
74
+ // API, one layer up. Reuses parseErrorResponse so a style failure arrives as
75
+ // the same LocationServiceException as every other call in this package,
76
+ // with `code`, `statusCode` and `requestId` intact.
77
+ throw parseErrorResponse(response.status, response.statusText, await response.text(), response.headers);
65
78
  }
66
79
  const style = (await response.json());
67
80
  if (language) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaosity/location-client",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Client library for Chaosity Location Service with AWS Location Service compatibility",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",