@chaosity/location-client 0.5.1 → 0.7.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 +73 -4
- 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 +42 -0
- package/dist/cjs/client/GeoPlacesClient.js +92 -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 +12 -0
- package/dist/cjs/maps/createTransformRequest.js +87 -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 +104 -0
- package/dist/cjs/server/LocationServiceConnector.js +270 -0
- package/dist/cjs/server/getClientConfig.d.ts +94 -0
- package/dist/cjs/server/getClientConfig.js +174 -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 +32 -0
- package/dist/cjs/transport/errors.js +120 -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 +53 -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 +6 -3
- package/dist/client/GeoPlacesClient.js +35 -11
- 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.d.ts +2 -0
- package/dist/maps/createTransformRequest.js +45 -1
- package/dist/maps/mapLanguage.d.ts +1 -1
- package/dist/maps/mapStyle.d.ts +1 -1
- package/dist/maps/mapStyle.js +2 -2
- package/dist/maps/staticMap.d.ts +1 -1
- package/dist/maps/staticMap.js +1 -1
- package/dist/server/LocationServiceConnector.d.ts +58 -9
- package/dist/server/LocationServiceConnector.js +217 -38
- package/dist/server/getClientConfig.d.ts +58 -4
- package/dist/server/getClientConfig.js +108 -66
- 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 +14 -1
- package/dist/transport/errors.js +16 -1
- package/dist/transport/http.js +2 -2
- package/dist/types/index.d.ts +19 -0
- package/package.json +33 -11
|
@@ -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;
|
|
@@ -24,6 +24,92 @@ function getTokenProvider(apiUrl, clientId, clientSecret) {
|
|
|
24
24
|
currentConfig = configKey;
|
|
25
25
|
return tokenProviderInstance;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Where the API lives, from the argument or the environment.
|
|
29
|
+
*
|
|
30
|
+
* Separate from the credentials because the two are independently overridable:
|
|
31
|
+
* a caller can hand `LocationServiceConnector` its own `token` and still expect
|
|
32
|
+
* `LOCATION_API_URL` to say where to send it.
|
|
33
|
+
*/
|
|
34
|
+
export function resolveApiUrl(explicit) {
|
|
35
|
+
return (explicit ||
|
|
36
|
+
process.env.LOCATION_API_URL ||
|
|
37
|
+
process.env.LOCATION_SERVICE_API_URL);
|
|
38
|
+
}
|
|
39
|
+
export function serverTokenSource(config = {}) {
|
|
40
|
+
log('[serverTokenSource] Starting with config:', {
|
|
41
|
+
hasApiUrl: !!config.apiUrl,
|
|
42
|
+
hasClientId: !!config.clientId,
|
|
43
|
+
});
|
|
44
|
+
// Auto-detect from environment with fallbacks
|
|
45
|
+
const apiUrl = resolveApiUrl(config.apiUrl);
|
|
46
|
+
const clientId = config.clientId ||
|
|
47
|
+
process.env.LOCATION_CLIENT_ID ||
|
|
48
|
+
process.env.LOCATION_SERVICE_CLIENT_ID;
|
|
49
|
+
const clientSecret = config.clientSecret ||
|
|
50
|
+
process.env.LOCATION_CLIENT_SECRET ||
|
|
51
|
+
process.env.LOCATION_SERVICE_CLIENT_SECRET;
|
|
52
|
+
log('[serverTokenSource] Resolved config:', {
|
|
53
|
+
apiUrl,
|
|
54
|
+
clientId: clientId?.substring(0, 10) + '...',
|
|
55
|
+
});
|
|
56
|
+
// Validate required values. A LocationServiceException like everything else
|
|
57
|
+
// this package throws — it used to be a bare `Error`, which was survivable
|
|
58
|
+
// while only `getClientConfig` could raise it and is not now that the
|
|
59
|
+
// connector reaches this path too.
|
|
60
|
+
if (!apiUrl || !clientId || !clientSecret) {
|
|
61
|
+
console.error('[location-client] Missing required configuration');
|
|
62
|
+
throw new LocationServiceException({
|
|
63
|
+
code: 'ValidationException',
|
|
64
|
+
message: 'Missing required configuration. Set environment variables: ' +
|
|
65
|
+
'LOCATION_API_URL, LOCATION_CLIENT_ID, LOCATION_CLIENT_SECRET',
|
|
66
|
+
details: { source: 'client' },
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
log('[serverTokenSource] Getting TokenProvider instance');
|
|
70
|
+
const provider = getTokenProvider(apiUrl, clientId, clientSecret);
|
|
71
|
+
return {
|
|
72
|
+
apiUrl,
|
|
73
|
+
async getToken(forceRefresh = false) {
|
|
74
|
+
log('[serverTokenSource] Fetching token (forceRefresh=%s)', forceRefresh);
|
|
75
|
+
let result;
|
|
76
|
+
try {
|
|
77
|
+
result = await provider.getToken(forceRefresh);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
// The provider now rejects rather than resolving with success:false, and
|
|
81
|
+
// the rejection is typed — so a store outage (503) can be reported as a
|
|
82
|
+
// store outage instead of as bad credentials.
|
|
83
|
+
if (error instanceof LocationServiceException) {
|
|
84
|
+
if (error.isAuth) {
|
|
85
|
+
throw new LocationServiceException({
|
|
86
|
+
code: 'InvalidCredentialsException',
|
|
87
|
+
message: `Authentication failed for client ID "${clientId}". ` +
|
|
88
|
+
`Verify LOCATION_CLIENT_ID and LOCATION_CLIENT_SECRET match your application in the developer portal.`,
|
|
89
|
+
statusCode: error.statusCode,
|
|
90
|
+
requestId: error.requestId,
|
|
91
|
+
cause: error,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
// TokenProvider rejects rather than returning a tokenless success, so this
|
|
99
|
+
// is unreachable in practice — it is here to keep the contract explicit at
|
|
100
|
+
// the type level rather than asserting non-null.
|
|
101
|
+
const token = result.token;
|
|
102
|
+
if (!token) {
|
|
103
|
+
throw new LocationServiceException({
|
|
104
|
+
code: 'InvalidCredentialsException',
|
|
105
|
+
message: 'Token provider returned no token',
|
|
106
|
+
details: { source: 'client' },
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return { ...result, token };
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
27
113
|
/**
|
|
28
114
|
* Get client configuration with OAuth2 authentication.
|
|
29
115
|
*
|
|
@@ -43,6 +129,21 @@ function getTokenProvider(apiUrl, clientId, clientSecret) {
|
|
|
43
129
|
* NEVER call from browser/client code as it exposes credentials.
|
|
44
130
|
* For SPA projects, create your own backend endpoint that calls this.
|
|
45
131
|
*
|
|
132
|
+
* ## The return value is PLAIN DATA, and has to stay that way
|
|
133
|
+
*
|
|
134
|
+
* `{ apiUrl, token, expiresAt }` — no methods, no closures. The reason is not
|
|
135
|
+
* style: the shape every sample uses is a Next.js Server Action that returns
|
|
136
|
+
* this straight to a Client Component (every `src/lib/actions/location.ts`
|
|
137
|
+
* under `location-service-samples/web`), and the RSC boundary
|
|
138
|
+
* serialises it. A function on this object is not serialisable and throws at
|
|
139
|
+
* the boundary, so "make getClientConfig return getToken" — which #36 proposed
|
|
140
|
+
* and this JSDoc used to promise two lines below — would break every Next.js
|
|
141
|
+
* consumer of the library.
|
|
142
|
+
*
|
|
143
|
+
* A caller that needs a token which REFRESHES wants one of:
|
|
144
|
+
* - `LocationServiceConnector`, which holds a live source internally (#36), or
|
|
145
|
+
* - `TokenProvider` directly, if it is managing its own lifecycle.
|
|
146
|
+
*
|
|
46
147
|
* @example
|
|
47
148
|
* // Auto-detect from environment
|
|
48
149
|
* const config = await getClientConfig()
|
|
@@ -50,74 +151,15 @@ function getTokenProvider(apiUrl, clientId, clientSecret) {
|
|
|
50
151
|
* // Or override specific values
|
|
51
152
|
* const config = await getClientConfig({ apiUrl: 'https://custom.api.com' })
|
|
52
153
|
*
|
|
53
|
-
* //
|
|
54
|
-
* const
|
|
55
|
-
* const connector = new LocationServiceConnector({ apiUrl: config.apiUrl, token })
|
|
154
|
+
* // The API rejected the token before its exp — revoked, or secret rotated
|
|
155
|
+
* const fresh = await getClientConfig({ forceRefresh: true })
|
|
56
156
|
*/
|
|
57
157
|
export async function getClientConfig(config = {}) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
hasClientId: !!config.clientId,
|
|
61
|
-
});
|
|
62
|
-
// Auto-detect from environment with fallbacks
|
|
63
|
-
const apiUrl = config.apiUrl ||
|
|
64
|
-
process.env.LOCATION_API_URL ||
|
|
65
|
-
process.env.LOCATION_SERVICE_API_URL;
|
|
66
|
-
const clientId = config.clientId ||
|
|
67
|
-
process.env.LOCATION_CLIENT_ID ||
|
|
68
|
-
process.env.LOCATION_SERVICE_CLIENT_ID;
|
|
69
|
-
const clientSecret = config.clientSecret ||
|
|
70
|
-
process.env.LOCATION_CLIENT_SECRET ||
|
|
71
|
-
process.env.LOCATION_SERVICE_CLIENT_SECRET;
|
|
72
|
-
log('[getClientConfig] Resolved config:', {
|
|
73
|
-
apiUrl,
|
|
74
|
-
clientId: clientId?.substring(0, 10) + '...',
|
|
75
|
-
});
|
|
76
|
-
// Validate required values
|
|
77
|
-
if (!apiUrl || !clientId || !clientSecret) {
|
|
78
|
-
console.error('[getClientConfig] Missing required configuration');
|
|
79
|
-
throw new Error('Missing required configuration. Set environment variables: ' +
|
|
80
|
-
'LOCATION_API_URL, LOCATION_CLIENT_ID, LOCATION_CLIENT_SECRET');
|
|
81
|
-
}
|
|
82
|
-
log('[getClientConfig] Getting TokenProvider instance');
|
|
83
|
-
const provider = getTokenProvider(apiUrl, clientId, clientSecret);
|
|
84
|
-
log('[getClientConfig] Fetching token');
|
|
85
|
-
let result;
|
|
86
|
-
try {
|
|
87
|
-
result = await provider.getToken();
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
// The provider now rejects rather than resolving with success:false, and the
|
|
91
|
-
// rejection is typed — so a store outage (503) can be reported as a store
|
|
92
|
-
// outage instead of as bad credentials.
|
|
93
|
-
if (error instanceof LocationServiceException) {
|
|
94
|
-
if (error.isAuth) {
|
|
95
|
-
throw new LocationServiceException({
|
|
96
|
-
code: 'InvalidCredentialsException',
|
|
97
|
-
message: `Authentication failed for client ID "${clientId}". ` +
|
|
98
|
-
`Verify LOCATION_CLIENT_ID and LOCATION_CLIENT_SECRET match your application in the developer portal.`,
|
|
99
|
-
statusCode: error.statusCode,
|
|
100
|
-
requestId: error.requestId,
|
|
101
|
-
cause: error,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
throw error;
|
|
107
|
-
}
|
|
108
|
-
// TokenProvider rejects rather than returning a tokenless success, so this is
|
|
109
|
-
// unreachable in practice — it is here to keep the contract explicit at the
|
|
110
|
-
// type level rather than asserting non-null.
|
|
111
|
-
if (!result.token) {
|
|
112
|
-
throw new LocationServiceException({
|
|
113
|
-
code: 'InvalidCredentialsException',
|
|
114
|
-
message: 'Token provider returned no token',
|
|
115
|
-
details: { source: 'client' },
|
|
116
|
-
});
|
|
117
|
-
}
|
|
158
|
+
const source = serverTokenSource(config);
|
|
159
|
+
const result = await source.getToken(config.forceRefresh);
|
|
118
160
|
log('[getClientConfig] Token fetched successfully, length:', result.token.length);
|
|
119
161
|
return {
|
|
120
|
-
apiUrl,
|
|
162
|
+
apiUrl: source.apiUrl,
|
|
121
163
|
token: result.token,
|
|
122
164
|
expiresAt: result.expiresAt,
|
|
123
165
|
};
|
package/dist/server/index.d.ts
CHANGED
|
@@ -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';
|
package/dist/server/index.js
CHANGED
|
@@ -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
|
*
|
|
@@ -12,6 +12,19 @@ import { LocationServiceException } from '../errors/LocationServiceException';
|
|
|
12
12
|
* { message: "Unauthorized" } API Gateway's own responses
|
|
13
13
|
*/
|
|
14
14
|
export declare function parseErrorResponse(status: number, statusText: string, body: string, headers?: Headers): LocationServiceException;
|
|
15
|
+
/**
|
|
16
|
+
* The API has rejected this token: a 401, and only a 401.
|
|
17
|
+
*
|
|
18
|
+
* The authorizer throws `Unauthorized` for a token it cannot verify or that has
|
|
19
|
+
* expired, and API Gateway turns that into a 401. Its other refusals — no
|
|
20
|
+
* domain configured for the application, an Origin the application does not
|
|
21
|
+
* allow — are a Deny policy or a service 403, and a fresh token changes
|
|
22
|
+
* neither. Retrying those would send, and bill, the same doomed request twice.
|
|
23
|
+
*
|
|
24
|
+
* Shared by both send paths so the browser client and the server connector
|
|
25
|
+
* cannot come to different conclusions about the same response.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isTokenRejected(err: unknown): boolean;
|
|
15
28
|
/**
|
|
16
29
|
* `Retry-After` is either delta-seconds or an HTTP date. Both are legal and the
|
|
17
30
|
* API sends the first; a date is handled so a proxy or gateway cannot surprise us.
|
package/dist/transport/errors.js
CHANGED
|
@@ -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
|
*
|
|
@@ -83,6 +83,21 @@ function statusCode(status) {
|
|
|
83
83
|
return status >= 500 ? 'InternalException' : 'ServiceException';
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* The API has rejected this token: a 401, and only a 401.
|
|
88
|
+
*
|
|
89
|
+
* The authorizer throws `Unauthorized` for a token it cannot verify or that has
|
|
90
|
+
* expired, and API Gateway turns that into a 401. Its other refusals — no
|
|
91
|
+
* domain configured for the application, an Origin the application does not
|
|
92
|
+
* allow — are a Deny policy or a service 403, and a fresh token changes
|
|
93
|
+
* neither. Retrying those would send, and bill, the same doomed request twice.
|
|
94
|
+
*
|
|
95
|
+
* Shared by both send paths so the browser client and the server connector
|
|
96
|
+
* cannot come to different conclusions about the same response.
|
|
97
|
+
*/
|
|
98
|
+
export function isTokenRejected(err) {
|
|
99
|
+
return err instanceof LocationServiceException && err.statusCode === 401;
|
|
100
|
+
}
|
|
86
101
|
/**
|
|
87
102
|
* `Retry-After` is either delta-seconds or an HTTP date. Both are legal and the
|
|
88
103
|
* API sends the first; a date is handled so a proxy or gateway cannot surprise us.
|
package/dist/transport/http.js
CHANGED
|
@@ -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/dist/types/index.d.ts
CHANGED
|
@@ -4,6 +4,25 @@ export interface ClientConfig {
|
|
|
4
4
|
/** Optional callback to get the current token dynamically. When provided,
|
|
5
5
|
* called on every request so token updates are reflected without recreating the client. */
|
|
6
6
|
getToken?: () => string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Asked for a replacement AFTER the API has rejected the current token with a
|
|
9
|
+
* 401, so the request can be retried once instead of failing.
|
|
10
|
+
*
|
|
11
|
+
* Separate from `getToken` because that one is synchronous by contract — it
|
|
12
|
+
* is read while a request is being built and cannot await anything, so it can
|
|
13
|
+
* only ever return the token already in hand. Nothing in this library could
|
|
14
|
+
* therefore recover from a token revoked, or a secret rotated, before its
|
|
15
|
+
* `exp`: every request failed until the refresh buffer elapsed on its own
|
|
16
|
+
* (#36).
|
|
17
|
+
*
|
|
18
|
+
* Returning `undefined` is not "no replacement": the client then re-reads
|
|
19
|
+
* `getToken`, because a provider refreshing in the background may have landed
|
|
20
|
+
* a new token while the failed request was in flight. What actually decides
|
|
21
|
+
* is the token that comes out of those two — if it is the one just rejected,
|
|
22
|
+
* or there is none, the retry is skipped rather than repeating a request that
|
|
23
|
+
* is going to fail again.
|
|
24
|
+
*/
|
|
25
|
+
refreshToken?: () => Promise<string | undefined>;
|
|
7
26
|
}
|
|
8
27
|
/**
|
|
9
28
|
* Minimal interface for AWS SDK command objects.
|
package/package.json
CHANGED
|
@@ -1,30 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chaosity/location-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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
|
-
"
|
|
11
|
-
|
|
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
|
-
"
|
|
15
|
-
|
|
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
|
}
|