@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.
Files changed (73) hide show
  1. package/README.md +14 -0
  2. package/dist/adapters/GeoPlaces.d.ts +1 -1
  3. package/dist/auth/TokenProvider.js +3 -3
  4. package/dist/cjs/adapters/GeoPlaces.d.ts +64 -0
  5. package/dist/cjs/adapters/GeoPlaces.js +213 -0
  6. package/dist/cjs/auth/TokenProvider.d.ts +64 -0
  7. package/dist/cjs/auth/TokenProvider.js +144 -0
  8. package/dist/cjs/auth/tokenRefresh.d.ts +37 -0
  9. package/dist/cjs/auth/tokenRefresh.js +58 -0
  10. package/dist/cjs/client/GeoPlacesClient.d.ts +39 -0
  11. package/dist/cjs/client/GeoPlacesClient.js +68 -0
  12. package/dist/cjs/errors/LocationServiceException.d.ts +44 -0
  13. package/dist/cjs/errors/LocationServiceException.js +60 -0
  14. package/dist/cjs/index.d.ts +24 -0
  15. package/dist/cjs/index.js +72 -0
  16. package/dist/cjs/maps/Utils.d.ts +2 -0
  17. package/dist/cjs/maps/Utils.js +8 -0
  18. package/dist/cjs/maps/createTransformRequest.d.ts +10 -0
  19. package/dist/cjs/maps/createTransformRequest.js +43 -0
  20. package/dist/cjs/maps/mapEnums.d.ts +102 -0
  21. package/dist/cjs/maps/mapEnums.js +103 -0
  22. package/dist/cjs/maps/mapLanguage.d.ts +43 -0
  23. package/dist/cjs/maps/mapLanguage.js +75 -0
  24. package/dist/cjs/maps/mapPoi.d.ts +44 -0
  25. package/dist/cjs/maps/mapPoi.js +64 -0
  26. package/dist/cjs/maps/mapStyle.d.ts +77 -0
  27. package/dist/cjs/maps/mapStyle.js +111 -0
  28. package/dist/cjs/maps/staticMap.d.ts +85 -0
  29. package/dist/cjs/maps/staticMap.js +81 -0
  30. package/dist/cjs/package.json +3 -0
  31. package/dist/cjs/server/LocationServiceConnector.d.ts +55 -0
  32. package/dist/cjs/server/LocationServiceConnector.js +91 -0
  33. package/dist/cjs/server/getClientConfig.d.ts +40 -0
  34. package/dist/cjs/server/getClientConfig.js +130 -0
  35. package/dist/cjs/server/index.d.ts +6 -0
  36. package/dist/cjs/server/index.js +9 -0
  37. package/dist/cjs/transport/endpoints.d.ts +2 -0
  38. package/dist/cjs/transport/endpoints.js +34 -0
  39. package/dist/cjs/transport/errors.d.ts +19 -0
  40. package/dist/cjs/transport/errors.js +104 -0
  41. package/dist/cjs/transport/http.d.ts +24 -0
  42. package/dist/cjs/transport/http.js +142 -0
  43. package/dist/cjs/types/index.d.ts +34 -0
  44. package/dist/cjs/types/index.js +3 -0
  45. package/dist/cjs/utils/roundPosition.d.ts +66 -0
  46. package/dist/cjs/utils/roundPosition.js +109 -0
  47. package/dist/cjs/utils/tokenClaims.d.ts +55 -0
  48. package/dist/cjs/utils/tokenClaims.js +61 -0
  49. package/dist/client/GeoPlacesClient.d.ts +3 -3
  50. package/dist/client/GeoPlacesClient.js +4 -4
  51. package/dist/index.d.ts +22 -22
  52. package/dist/index.js +12 -12
  53. package/dist/maps/Utils.d.ts +1 -1
  54. package/dist/maps/Utils.js +1 -1
  55. package/dist/maps/createTransformRequest.js +1 -1
  56. package/dist/maps/mapLanguage.d.ts +31 -7
  57. package/dist/maps/mapLanguage.js +50 -20
  58. package/dist/maps/mapStyle.d.ts +1 -1
  59. package/dist/maps/mapStyle.js +17 -16
  60. package/dist/maps/staticMap.d.ts +1 -1
  61. package/dist/maps/staticMap.js +12 -4
  62. package/dist/server/LocationServiceConnector.d.ts +2 -2
  63. package/dist/server/LocationServiceConnector.js +6 -6
  64. package/dist/server/getClientConfig.d.ts +1 -1
  65. package/dist/server/getClientConfig.js +2 -2
  66. package/dist/server/index.d.ts +6 -6
  67. package/dist/server/index.js +3 -3
  68. package/dist/transport/endpoints.d.ts +1 -1
  69. package/dist/transport/endpoints.js +1 -1
  70. package/dist/transport/errors.d.ts +1 -1
  71. package/dist/transport/errors.js +1 -1
  72. package/dist/transport/http.js +2 -2
  73. package/package.json +33 -11
@@ -1,4 +1,4 @@
1
- import { parseErrorResponse } from '../transport/errors';
1
+ import { parseErrorResponse } from '../transport/errors.js';
2
2
  /**
3
3
  * The Accept header this request must send.
4
4
  *
@@ -9,6 +9,8 @@ import { parseErrorResponse } from '../transport/errors';
9
9
  export function staticMapAccept(style) {
10
10
  return style === 'Standard' ? 'image/png' : 'image/jpeg';
11
11
  }
12
+ /** A coordinate as the API accepts it: at most six decimals, no float noise. */
13
+ const coord = (n) => String(Number(n.toFixed(6)));
12
14
  /** Build the request URL without fetching it. */
13
15
  export function buildStaticMapUrl(apiUrl, options) {
14
16
  const { width, height, center, boundingBox, boundedPositions, fileName = 'map', ...rest } = options;
@@ -19,12 +21,18 @@ export function buildStaticMapUrl(apiUrl, options) {
19
21
  // Positions go over the wire as comma-separated numbers. api#35 records that
20
22
  // passing arrays straight through worked only by accidental stringification;
21
23
  // doing it explicitly here means the shape is ours, not JavaScript's default.
24
+ //
25
+ // Each number is rounded to six decimals (#29). The API caps a coordinate at
26
+ // fourteen decimals, and a value straight from `map.getCenter()` routinely
27
+ // has fifteen or sixteen — so the obvious "render what the user is looking
28
+ // at" was a 400 blaming the FORMAT. Six decimals is ~10 cm, more than a
29
+ // raster render can show.
22
30
  if (center)
23
- params.set('center', center.join(','));
31
+ params.set('center', center.map(coord).join(','));
24
32
  if (boundingBox)
25
- params.set('bounding-box', boundingBox.join(','));
33
+ params.set('bounding-box', boundingBox.map(coord).join(','));
26
34
  if (boundedPositions) {
27
- params.set('bounded-positions', boundedPositions.flat().join(','));
35
+ params.set('bounded-positions', boundedPositions.flat().map(coord).join(','));
28
36
  }
29
37
  // The API accepts kebab-case on the wire and camelCase for older callers;
30
38
  // kebab is the documented form, so emit that.
@@ -1,5 +1,5 @@
1
- import type { RequestOptions } from '../transport/http';
2
- import type { AppConfigClaims } from '../utils/tokenClaims';
1
+ import type { RequestOptions } from '../transport/http.js';
2
+ import type { AppConfigClaims } from '../utils/tokenClaims.js';
3
3
  export interface ConnectorConfig {
4
4
  apiUrl?: string;
5
5
  token?: string;
@@ -1,10 +1,10 @@
1
1
  import debug from 'debug';
2
- import { LocationServiceException } from '../errors/LocationServiceException';
3
- import { resolveEndpoint } from '../transport/endpoints';
4
- import { requestJson } from '../transport/http';
5
- import { roundPositionFields } from '../utils/roundPosition';
6
- import { readAppConfigClaims } from '../utils/tokenClaims';
7
- import { getClientConfig } from './getClientConfig';
2
+ import { LocationServiceException } from '../errors/LocationServiceException.js';
3
+ import { resolveEndpoint } from '../transport/endpoints.js';
4
+ import { requestJson } from '../transport/http.js';
5
+ import { roundPositionFields } from '../utils/roundPosition.js';
6
+ import { readAppConfigClaims } from '../utils/tokenClaims.js';
7
+ import { getClientConfig } from './getClientConfig.js';
8
8
  const log = debug('location-client:connector');
9
9
  /**
10
10
  * LocationServiceConnector — server-side connector for the Location Service API.
@@ -1,4 +1,4 @@
1
- import type { ClientConfig } from '../types';
1
+ import type { ClientConfig } from '../types/index.js';
2
2
  export interface ServerAuthConfig {
3
3
  apiUrl?: string;
4
4
  clientId?: string;
@@ -1,7 +1,7 @@
1
1
  import debug from 'debug';
2
2
  import { createHash } from 'node:crypto';
3
- import { TokenProvider } from '../auth/TokenProvider';
4
- import { LocationServiceException } from '../errors/LocationServiceException';
3
+ import { TokenProvider } from '../auth/TokenProvider.js';
4
+ import { LocationServiceException } from '../errors/LocationServiceException.js';
5
5
  const log = debug('location-client:clientConfig');
6
6
  // Singleton instance to prevent race conditions
7
7
  let tokenProviderInstance = null;
@@ -1,6 +1,6 @@
1
- export { TokenProvider } from '../auth/TokenProvider';
2
- export type { TokenProviderConfig, TokenResponse } from '../auth/TokenProvider';
3
- export { getClientConfig } from './getClientConfig';
4
- export type { ServerAuthConfig, ServerClientConfig } from './getClientConfig';
5
- export { LocationServiceConnector } from './LocationServiceConnector';
6
- export type { ConnectorConfig, SendOptions } from './LocationServiceConnector';
1
+ export { TokenProvider } from '../auth/TokenProvider.js';
2
+ export type { TokenProviderConfig, TokenResponse, } from '../auth/TokenProvider.js';
3
+ export { getClientConfig } from './getClientConfig.js';
4
+ export type { ServerAuthConfig, ServerClientConfig } from './getClientConfig.js';
5
+ export { LocationServiceConnector } from './LocationServiceConnector.js';
6
+ export type { ConnectorConfig, SendOptions, } from './LocationServiceConnector.js';
@@ -1,3 +1,3 @@
1
- export { TokenProvider } from '../auth/TokenProvider';
2
- export { getClientConfig } from './getClientConfig';
3
- export { LocationServiceConnector } from './LocationServiceConnector';
1
+ export { TokenProvider } from '../auth/TokenProvider.js';
2
+ export { getClientConfig } from './getClientConfig.js';
3
+ export { LocationServiceConnector } from './LocationServiceConnector.js';
@@ -1,2 +1,2 @@
1
- import type { GeoPlacesCommand } from '../types';
1
+ import type { GeoPlacesCommand } from '../types/index.js';
2
2
  export declare function resolveEndpoint(command: GeoPlacesCommand): string;
@@ -1,5 +1,5 @@
1
1
  import { AutocompleteCommand, GeocodeCommand, GetPlaceCommand, ReverseGeocodeCommand, SearchNearbyCommand, SearchTextCommand, SuggestCommand, } from '@aws-sdk/client-geo-places';
2
- import { LocationServiceException } from '../errors/LocationServiceException';
2
+ import { LocationServiceException } from '../errors/LocationServiceException.js';
3
3
  /**
4
4
  * Command class -> API path.
5
5
  *
@@ -1,4 +1,4 @@
1
- import { LocationServiceException } from '../errors/LocationServiceException';
1
+ import { LocationServiceException } from '../errors/LocationServiceException.js';
2
2
  /**
3
3
  * Turn a non-2xx response into a LocationServiceException.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { LocationServiceException } from '../errors/LocationServiceException';
1
+ import { LocationServiceException } from '../errors/LocationServiceException.js';
2
2
  /**
3
3
  * Turn a non-2xx response into a LocationServiceException.
4
4
  *
@@ -1,6 +1,6 @@
1
1
  import debug from 'debug';
2
- import { LocationServiceException } from '../errors/LocationServiceException';
3
- import { parseErrorResponse, parseRetryAfter } from './errors';
2
+ import { LocationServiceException } from '../errors/LocationServiceException.js';
3
+ import { parseErrorResponse, parseRetryAfter } from './errors.js';
4
4
  const log = debug('location-client:transport');
5
5
  /** Per-attempt timeout. Sits well under the API's own 25 s Lambda ceiling. */
6
6
  export const DEFAULT_TIMEOUT_MS = 10000;
package/package.json CHANGED
@@ -1,30 +1,43 @@
1
1
  {
2
2
  "name": "@chaosity/location-client",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Client library for Chaosity Location Service with AWS Location Service compatibility",
5
5
  "type": "module",
6
- "main": "dist/index.js",
6
+ "main": "dist/cjs/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "default": "./dist/index.js"
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/cjs/index.d.ts",
16
+ "default": "./dist/cjs/index.js"
17
+ }
12
18
  },
13
19
  "./server": {
14
- "types": "./dist/server/index.d.ts",
15
- "default": "./dist/server/index.js"
20
+ "import": {
21
+ "types": "./dist/server/index.d.ts",
22
+ "default": "./dist/server/index.js"
23
+ },
24
+ "require": {
25
+ "types": "./dist/cjs/server/index.d.ts",
26
+ "default": "./dist/cjs/server/index.js"
27
+ }
16
28
  }
17
29
  },
18
30
  "scripts": {
19
- "build": "tsc",
31
+ "build": "tsc && tsc -p tsconfig.cjs.json && node scripts/finish-cjs.mjs",
20
32
  "dev": "tsc --watch",
21
33
  "lint": "eslint . && prettier --check .",
22
34
  "lint:fix": "eslint --fix . && prettier --write .",
23
35
  "format": "prettier --write .",
24
36
  "test": "vitest run",
25
37
  "test:watch": "vitest",
26
- "prepublishOnly": "npm run build",
27
- "prepare": "husky"
38
+ "prepublishOnly": "npm run build && npm run smoke",
39
+ "prepare": "husky",
40
+ "smoke": "node scripts/smoke.mjs"
28
41
  },
29
42
  "keywords": [
30
43
  "aws",
@@ -47,19 +60,23 @@
47
60
  "dependencies": {
48
61
  "@aws-sdk/client-geo-places": "^3.0.0",
49
62
  "@aws/amazon-location-utilities-datatypes": "^1.0.0",
50
- "@maplibre/maplibre-gl-geocoder": "^1.9.4",
51
63
  "debug": "^4.4.3"
52
64
  },
53
65
  "peerDependencies": {
66
+ "@maplibre/maplibre-gl-geocoder": "^1.9.4",
54
67
  "maplibre-gl": "^5.0.0"
55
68
  },
56
69
  "peerDependenciesMeta": {
70
+ "@maplibre/maplibre-gl-geocoder": {
71
+ "optional": true
72
+ },
57
73
  "maplibre-gl": {
58
74
  "optional": true
59
75
  }
60
76
  },
61
77
  "devDependencies": {
62
78
  "@eslint/js": "^10.0.1",
79
+ "@maplibre/maplibre-gl-geocoder": "^1.9.4",
63
80
  "@types/debug": "^4.1.12",
64
81
  "@types/node": "^25.0.3",
65
82
  "@vitest/coverage-v8": "^3.0.0",
@@ -79,5 +96,10 @@
79
96
  "dist",
80
97
  "README.md",
81
98
  "LICENSE"
82
- ]
99
+ ],
100
+ "module": "dist/index.js",
101
+ "sideEffects": false,
102
+ "engines": {
103
+ "node": ">=20"
104
+ }
83
105
  }