radar-sdk-js 5.0.0-beta.4 → 5.0.0-beta.6

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 (48) hide show
  1. package/README.md +39 -30
  2. package/dist/api/addresses.d.ts +6 -0
  3. package/dist/api/config.d.ts +5 -0
  4. package/dist/api/context.d.ts +6 -0
  5. package/dist/api/conversions.d.ts +6 -0
  6. package/dist/api/geocoding.d.ts +16 -1
  7. package/dist/api/routing.d.ts +11 -0
  8. package/dist/api/search.d.ts +17 -0
  9. package/dist/api/track.d.ts +6 -0
  10. package/dist/api/trips.d.ts +17 -0
  11. package/dist/api.d.ts +44 -1
  12. package/dist/config.d.ts +10 -1
  13. package/dist/device.d.ts +9 -0
  14. package/dist/errors.d.ts +33 -17
  15. package/dist/http.d.ts +51 -13
  16. package/dist/iife-entry.d.ts +1 -1
  17. package/dist/logger.d.ts +5 -0
  18. package/dist/navigator.d.ts +14 -1
  19. package/dist/plugin.d.ts +23 -7
  20. package/dist/radar.js +557 -361
  21. package/dist/radar.js.map +1 -1
  22. package/dist/session.d.ts +5 -0
  23. package/dist/storage.d.ts +31 -0
  24. package/dist/types.d.ts +157 -16
  25. package/dist/version.d.ts +1 -1
  26. package/package.json +23 -16
  27. package/src/api/addresses.ts +9 -3
  28. package/src/api/config.ts +6 -2
  29. package/src/api/context.ts +10 -11
  30. package/src/api/conversions.ts +19 -13
  31. package/src/api/geocoding.ts +27 -11
  32. package/src/api/routing.ts +27 -31
  33. package/src/api/search.ts +36 -38
  34. package/src/api/track.ts +12 -25
  35. package/src/api/trips.ts +37 -27
  36. package/src/api.ts +59 -23
  37. package/src/config.ts +11 -2
  38. package/src/device.ts +20 -6
  39. package/src/errors.ts +34 -19
  40. package/src/http.ts +173 -161
  41. package/src/iife-entry.ts +3 -3
  42. package/src/logger.ts +6 -2
  43. package/src/navigator.ts +24 -12
  44. package/src/plugin.ts +23 -7
  45. package/src/session.ts +6 -1
  46. package/src/storage.ts +33 -4
  47. package/src/types.ts +164 -45
  48. package/src/version.ts +1 -1
package/README.md CHANGED
@@ -21,16 +21,18 @@
21
21
  </p>
22
22
 
23
23
  🔥 Try it! 🔥
24
- * <a href="https://radar.com/demo/js">Geofencing</a>
25
- * <a href="https://radar.com/demo/api">Maps APIs</a>
26
- * <a href="https://radar.com/documentation/maps/maps">Maps UI</a>
27
- * <a href="https://radar.com/documentation/maps/autocomplete">Autocomplete UI</a>
24
+
25
+ - <a href="https://radar.com/demo/js">Geofencing</a>
26
+ - <a href="https://radar.com/demo/api">Maps APIs</a>
27
+ - <a href="https://radar.com/documentation/maps/maps">Maps UI</a>
28
+ - <a href="https://radar.com/documentation/maps/autocomplete">Autocomplete UI</a>
28
29
 
29
30
  ## 🚀 Installation and Usage
30
31
 
31
32
  ### With npm
32
33
 
33
34
  Install the core SDK:
35
+
34
36
  ```bash
35
37
  # with npm
36
38
  npm install radar-sdk-js
@@ -40,21 +42,27 @@ yarn add radar-sdk-js
40
42
  ```
41
43
 
42
44
  Then import and initialize:
45
+
43
46
  ```js
44
47
  import Radar from 'radar-sdk-js';
45
48
 
46
49
  // initialize with your test or live publishable key
47
- Radar.initialize('prj_test_pk_...', { /* options */ });
50
+ Radar.initialize('prj_test_pk_...', {
51
+ /* options */
52
+ });
48
53
  ```
49
54
 
50
55
  ### With a script tag
51
56
 
52
57
  Add the following to your HTML:
58
+
53
59
  ```html
54
- <script src="https://js.radar.com/v5.0.0-beta.4/radar.min.js"></script>
60
+ <script src="https://js.radar.com/v5.0.0-beta.6/radar.min.js"></script>
55
61
 
56
62
  <script>
57
- Radar.initialize('prj_test_pk_...', { /* options */ });
63
+ Radar.initialize('prj_test_pk_...', {
64
+ /* options */
65
+ });
58
66
  </script>
59
67
  ```
60
68
 
@@ -99,19 +107,21 @@ Radar.initialize('prj_test_pk_...');
99
107
 
100
108
  Radar.ui.autocomplete({
101
109
  container: 'autocomplete',
102
- onSelection: (result) => { console.log(result); },
110
+ onSelection: (result) => {
111
+ console.log(result);
112
+ },
103
113
  });
104
114
  ```
105
115
 
106
116
  ### Fraud plugin (npm)
107
117
 
108
118
  ```bash
109
- npm install @radarlabs/fraud-plugin
119
+ npm install @radarlabs/plugin-fraud
110
120
  ```
111
121
 
112
122
  ```js
113
123
  import Radar from 'radar-sdk-js';
114
- import { createFraudPlugin } from '@radarlabs/fraud-plugin';
124
+ import { createFraudPlugin } from '@radarlabs/plugin-fraud';
115
125
 
116
126
  Radar.registerPlugin(createFraudPlugin());
117
127
  Radar.initialize('prj_live_pk_...');
@@ -125,10 +135,10 @@ Plugin CDN bundles auto-register with the core SDK when loaded. Load
125
135
  the core SDK first, then any plugins you need:
126
136
 
127
137
  ```html
128
- <link href="https://js.radar.com/maps/v5.0.0-beta.4/radar-maps.css" rel="stylesheet">
129
- <link href="https://js.radar.com/autocomplete/v5.0.0-beta.4/radar-autocomplete.css" rel="stylesheet">
138
+ <link href="https://js.radar.com/maps/v5.0.0-beta.4/radar-maps.css" rel="stylesheet" />
139
+ <link href="https://js.radar.com/autocomplete/v5.0.0-beta.4/radar-autocomplete.css" rel="stylesheet" />
130
140
 
131
- <script src="https://js.radar.com/v5.0.0-beta.4/radar.min.js"></script>
141
+ <script src="https://js.radar.com/v5.0.0-beta.6/radar.min.js"></script>
132
142
  <script src="https://js.radar.com/maps/v5.0.0-beta.4/radar-maps.min.js"></script>
133
143
  <script src="https://js.radar.com/autocomplete/v5.0.0-beta.4/radar-autocomplete.min.js"></script>
134
144
  <script src="https://js.radar.com/fraud/v5.0.0-beta.1/radar-fraud.min.js"></script>
@@ -144,8 +154,8 @@ by ID or element reference.
144
154
  ```html
145
155
  <html>
146
156
  <head>
147
- <link href="https://js.radar.com/maps/v5.0.0-beta.4/radar-maps.css" rel="stylesheet">
148
- <script src="https://js.radar.com/v5.0.0-beta.4/radar.min.js"></script>
157
+ <link href="https://js.radar.com/maps/v5.0.0-beta.4/radar-maps.css" rel="stylesheet" />
158
+ <script src="https://js.radar.com/v5.0.0-beta.6/radar.min.js"></script>
149
159
  <script src="https://js.radar.com/maps/v5.0.0-beta.4/radar-maps.min.js"></script>
150
160
  </head>
151
161
 
@@ -171,8 +181,8 @@ by ID or element reference.
171
181
  ```html
172
182
  <html>
173
183
  <head>
174
- <link href="https://js.radar.com/autocomplete/v5.0.0-beta.4/radar-autocomplete.css" rel="stylesheet">
175
- <script src="https://js.radar.com/v5.0.0-beta.4/radar.min.js"></script>
184
+ <link href="https://js.radar.com/autocomplete/v5.0.0-beta.4/radar-autocomplete.css" rel="stylesheet" />
185
+ <script src="https://js.radar.com/v5.0.0-beta.6/radar.min.js"></script>
176
186
  <script src="https://js.radar.com/autocomplete/v5.0.0-beta.4/radar-autocomplete.min.js"></script>
177
187
  </head>
178
188
 
@@ -182,7 +192,6 @@ by ID or element reference.
182
192
  <script>
183
193
  Radar.initialize('<RADAR_PUBLISHABLE_KEY>');
184
194
 
185
-
186
195
  // create autocomplete widget
187
196
  Radar.ui.autocomplete({
188
197
  container: 'autocomplete', // OR document.getElementById('autocomplete')
@@ -206,17 +215,16 @@ are needed for geofencing.
206
215
  ```html
207
216
  <html>
208
217
  <head>
209
- <script src="https://js.radar.com/v5.0.0-beta.4/radar.min.js"></script>
218
+ <script src="https://js.radar.com/v5.0.0-beta.6/radar.min.js"></script>
210
219
  </head>
211
220
 
212
221
  <body>
213
222
  <script>
214
223
  Radar.initialize('<RADAR_PUBLISHABLE_KEY>');
215
224
 
216
- Radar.trackOnce({ userId: 'example-user-id' })
217
- .then(({ location, user, events }) => {
218
- // do something with user location or events
219
- });
225
+ Radar.trackOnce({ userId: 'example-user-id' }).then(({ location, user, events }) => {
226
+ // do something with user location or events
227
+ });
220
228
  </script>
221
229
  </body>
222
230
  </html>
@@ -224,12 +232,12 @@ are needed for geofencing.
224
232
 
225
233
  ## Packages
226
234
 
227
- | Package | npm | Description |
228
- |---------|-----|-------------|
229
- | `radar-sdk-js` | [![npm](https://img.shields.io/npm/v/radar-sdk-js.svg)](https://www.npmjs.com/package/radar-sdk-js) | Core SDK — tracking, geocoding, search, routing |
230
- | `@radarlabs/plugin-maps` | [![npm](https://img.shields.io/npm/v/@radarlabs/plugin-maps.svg)](https://www.npmjs.com/package/@radarlabs/plugin-maps) | Maps UI — RadarMap, RadarMarker, RadarPopup (MapLibre GL) |
231
- | `@radarlabs/plugin-autocomplete` | [![npm](https://img.shields.io/npm/v/@radarlabs/plugin-autocomplete.svg)](https://www.npmjs.com/package/@radarlabs/plugin-autocomplete) | Autocomplete UI widget |
232
- | `@radarlabs/fraud-plugin` | | Fraud detection — verified tracking, location tokens |
235
+ | Package | npm | Description |
236
+ | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
237
+ | `radar-sdk-js` | [![npm](https://img.shields.io/npm/v/radar-sdk-js.svg)](https://www.npmjs.com/package/radar-sdk-js) | Core SDK — tracking, geocoding, search, routing |
238
+ | `@radarlabs/plugin-maps` | [![npm](https://img.shields.io/npm/v/@radarlabs/plugin-maps.svg)](https://www.npmjs.com/package/@radarlabs/plugin-maps) | Maps UI — RadarMap, RadarMarker, RadarPopup (MapLibre GL) |
239
+ | `@radarlabs/plugin-autocomplete` | [![npm](https://img.shields.io/npm/v/@radarlabs/plugin-autocomplete.svg)](https://www.npmjs.com/package/@radarlabs/plugin-autocomplete) | Autocomplete UI widget |
240
+ | `@radarlabs/plugin-fraud` | [![npm](https://img.shields.io/npm/v/@radarlabs/plugin-fraud.svg)](https://www.npmjs.com/package/@radarlabs/plugin-fraud) | Fraud detection — verified tracking, location tokens |
233
241
 
234
242
  ## Plugin system
235
243
 
@@ -241,7 +249,7 @@ plugins before or after calling `Radar.initialize()`:
241
249
  import Radar from 'radar-sdk-js';
242
250
  import { createMapsPlugin } from '@radarlabs/plugin-maps';
243
251
  import { createAutocompletePlugin } from '@radarlabs/plugin-autocomplete';
244
- import { createFraudPlugin } from '@radarlabs/fraud-plugin';
252
+ import { createFraudPlugin } from '@radarlabs/plugin-fraud';
245
253
 
246
254
  Radar.registerPlugin(createMapsPlugin());
247
255
  Radar.registerPlugin(createAutocompletePlugin());
@@ -257,6 +265,7 @@ import type { RadarPlugin, RadarPluginContext } from 'radar-sdk-js/plugin';
257
265
  ```
258
266
 
259
267
  ## 🔗 Other links
268
+
260
269
  - [Contributing](CONTRIBUTING.md)
261
270
  - [Migrating from 3.x to 4.x](https://github.com/radarlabs/radar-sdk-js/blob/v4-beta/MIGRATION.md)
262
271
  - [Migrating from 4.x to 5.x](MIGRATION.md)
@@ -1,5 +1,11 @@
1
1
  import type { RadarValidateAddressParams, RadarValidateAddressResponse } from '../types';
2
+ /** @internal address validation API — use {@link Radar.validateAddress} instead */
2
3
  declare class AddressesAPI {
4
+ /**
5
+ * validate a structured address
6
+ * @param params - address fields to validate
7
+ * @returns validated address and verification result
8
+ */
3
9
  static validateAddress(params: RadarValidateAddressParams): Promise<RadarValidateAddressResponse>;
4
10
  }
5
11
  export default AddressesAPI;
@@ -1,5 +1,10 @@
1
1
  import type { RadarTrackParams } from '../types';
2
+ /** @internal SDK configuration API for fetching remote config */
2
3
  declare class ConfigAPI {
4
+ /**
5
+ * fetch remote SDK configuration from the Radar API
6
+ * @param params - optional tracking params for device/session identification
7
+ */
3
8
  static getConfig(params?: RadarTrackParams): Promise<void>;
4
9
  }
5
10
  export default ConfigAPI;
@@ -1,5 +1,11 @@
1
1
  import type { RadarContextResponse, Location } from '../types';
2
+ /** @internal context API — use {@link Radar.getContext} instead */
2
3
  declare class ContextAPI {
4
+ /**
5
+ * get context (geofences, place, region) for a location
6
+ * @param location - coordinates to get context for
7
+ * @returns geofences, place, country, state, DMA, and postal code
8
+ */
3
9
  static getContext(location: Location): Promise<RadarContextResponse>;
4
10
  }
5
11
  export default ContextAPI;
@@ -1,5 +1,11 @@
1
1
  import type { RadarConversionParams, RadarConversionResponse } from '../types';
2
+ /** @internal conversions API — use {@link Radar.logConversion} instead */
2
3
  declare class ConversionsAPI {
4
+ /**
5
+ * log a conversion event
6
+ * @param params - conversion name, user info, and optional metadata/revenue
7
+ * @returns the created event
8
+ */
3
9
  static logConversion(params: RadarConversionParams): Promise<RadarConversionResponse>;
4
10
  }
5
11
  export default ConversionsAPI;
@@ -1,7 +1,22 @@
1
- import { RadarForwardGeocodeParams, RadarReverseGeocodeParams, RadarGeocodeResponse, RadarIPGeocodeResponse } from '../types';
1
+ import type { RadarForwardGeocodeParams, RadarReverseGeocodeParams, RadarGeocodeResponse, RadarIPGeocodeResponse } from '../types';
2
+ /** @internal geocoding API — use Radar.forwardGeocode / reverseGeocode / ipGeocode instead */
2
3
  declare class Geocoding {
4
+ /**
5
+ * geocode an address or place name to coordinates
6
+ * @param params - query string, optional layers and country filter
7
+ * @returns matching addresses
8
+ */
3
9
  static forwardGeocode(params: RadarForwardGeocodeParams): Promise<RadarGeocodeResponse>;
10
+ /**
11
+ * reverse geocode coordinates to addresses
12
+ * @param params - latitude/longitude, optional layers filter
13
+ * @returns matching addresses
14
+ */
4
15
  static reverseGeocode(params: RadarReverseGeocodeParams): Promise<RadarGeocodeResponse>;
16
+ /**
17
+ * geocode the device's IP address to a rough location
18
+ * @returns IP address, approximate address, and proxy info
19
+ */
5
20
  static ipGeocode(): Promise<RadarIPGeocodeResponse>;
6
21
  }
7
22
  export default Geocoding;
@@ -1,6 +1,17 @@
1
1
  import type { RadarDistanceParams, RadarRouteResponse, RadarMatrixParams, RadarMatrixResponse } from '../types';
2
+ /** @internal routing API — use Radar.distance / matrix instead */
2
3
  declare class RoutingAPI {
4
+ /**
5
+ * calculate travel distance and duration between two points
6
+ * @param params - origin, destination, modes, and units
7
+ * @returns routes with distance and duration per mode
8
+ */
3
9
  static distance(params: RadarDistanceParams): Promise<RadarRouteResponse>;
10
+ /**
11
+ * calculate a distance matrix between multiple origins and destinations
12
+ * @param params - origins, destinations, mode, and units
13
+ * @returns matrix of distances and durations
14
+ */
4
15
  static matrix(params: RadarMatrixParams): Promise<RadarMatrixResponse>;
5
16
  }
6
17
  export default RoutingAPI;
@@ -1,7 +1,24 @@
1
1
  import type { RadarAutocompleteParams, RadarAutocompleteResponse, RadarSearchPlacesParams, RadarSearchPlacesResponse, RadarSearchGeofencesParams, RadarSearchGeofencesResponse } from '../types';
2
+ /** @internal search API — use Radar.autocomplete / searchGeofences / searchPlaces instead */
2
3
  declare class SearchAPI {
4
+ /**
5
+ * autocomplete partial addresses and place names
6
+ * @param params - query and search configuration
7
+ * @param requestId - optional ID for deduplicating in-flight requests
8
+ * @returns matching addresses
9
+ */
3
10
  static autocomplete(params: RadarAutocompleteParams, requestId?: string): Promise<RadarAutocompleteResponse>;
11
+ /**
12
+ * search for geofences near a location
13
+ * @param params - location, radius, tags, and filters
14
+ * @returns matching geofences
15
+ */
4
16
  static searchGeofences(params: RadarSearchGeofencesParams): Promise<RadarSearchGeofencesResponse>;
17
+ /**
18
+ * search for places near a location
19
+ * @param params - location, radius, chains, categories, and groups
20
+ * @returns matching places
21
+ */
5
22
  static searchPlaces(params: RadarSearchPlacesParams): Promise<RadarSearchPlacesResponse>;
6
23
  }
7
24
  export default SearchAPI;
@@ -1,5 +1,11 @@
1
1
  import type { RadarTrackParams, RadarTrackResponse } from '../types';
2
+ /** @internal tracking API — use {@link Radar.trackOnce} instead */
2
3
  declare class TrackAPI {
4
+ /**
5
+ * track the user's current location once
6
+ * @param params - tracking parameters (location, user info, trip options)
7
+ * @returns tracked user, events, and location
8
+ */
3
9
  static trackOnce(params: RadarTrackParams): Promise<RadarTrackResponse>;
4
10
  }
5
11
  export default TrackAPI;
@@ -1,11 +1,28 @@
1
1
  import type { RadarTripOptions, RadarTripStatus, RadarTripResponse } from '../types';
2
+ /** @internal trips API — use Radar.startTrip / updateTrip / completeTrip / cancelTrip instead */
2
3
  declare class TripsAPI {
4
+ /** save trip options to localStorage, pass `undefined` to clear */
3
5
  static setTripOptions(tripOptions?: RadarTripOptions): void;
6
+ /** get saved trip options from localStorage */
4
7
  static getTripOptions(): RadarTripOptions;
8
+ /** remove saved trip options from localStorage */
5
9
  static clearTripOptions(): void;
10
+ /**
11
+ * start a new trip
12
+ * @param tripOptions - trip configuration and destination
13
+ * @returns the created trip and any triggered events
14
+ */
6
15
  static startTrip(tripOptions: RadarTripOptions): Promise<RadarTripResponse>;
16
+ /**
17
+ * update an in-progress trip
18
+ * @param tripOptions - updated trip configuration
19
+ * @param status - optional trip status override
20
+ * @returns the updated trip and any triggered events
21
+ */
7
22
  static updateTrip(tripOptions: RadarTripOptions, status?: RadarTripStatus): Promise<RadarTripResponse>;
23
+ /** complete the current trip and clear local trip options */
8
24
  static completeTrip(): Promise<RadarTripResponse>;
25
+ /** cancel the current trip and clear local trip options */
9
26
  static cancelTrip(): Promise<RadarTripResponse>;
10
27
  }
11
28
  export default TripsAPI;
package/dist/api.d.ts CHANGED
@@ -1,37 +1,80 @@
1
- import { RadarError } from './errors';
1
+ import type { RadarError } from './errors';
2
2
  import type { RadarPlugin } from './plugin';
3
3
  import type { Location, NavigatorPosition, RadarAutocompleteParams, RadarAutocompleteResponse, RadarContextResponse, RadarConversionParams, RadarConversionResponse, RadarDistanceParams, RadarForwardGeocodeParams, RadarGeocodeResponse, RadarIPGeocodeResponse, RadarMatrixParams, RadarMatrixResponse, RadarMetadata, RadarOptions, RadarReverseGeocodeParams, RadarRouteResponse, RadarSearchGeofencesParams, RadarSearchGeofencesResponse, RadarSearchPlacesParams, RadarSearchPlacesResponse, RadarTrackParams, RadarTrackResponse, RadarTripOptions, RadarTripResponse, RadarValidateAddressParams, RadarValidateAddressResponse } from './types';
4
+ /**
5
+ * main entry point for the Radar SDK. all methods are static — do not instantiate.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * Radar.initialize('prj_test_pk_...');
10
+ * const { user, events } = await Radar.trackOnce();
11
+ * ```
12
+ */
4
13
  declare class Radar {
5
14
  private static _plugins;
15
+ /** current SDK version string */
6
16
  static get VERSION(): string;
17
+ /** register one or more plugins (e.g. maps, autocomplete, fraud) */
7
18
  static registerPlugin(...plugins: RadarPlugin[]): void;
8
19
  private static _getPluginContext;
20
+ /**
21
+ * initialize the SDK with a publishable key. must be called before any other method.
22
+ * @param publishableKey - your Radar publishable key (starts with `prj_test_pk_` or `prj_live_pk_`)
23
+ * @param options - optional SDK configuration
24
+ * @throws {RadarPublishableKeyError} if the key is missing or is a secret key
25
+ */
9
26
  static initialize(publishableKey: string, options?: RadarOptions): void;
27
+ /** clear all SDK state and configuration */
10
28
  static clear(): void;
29
+ /** set the user ID for tracking. pass `undefined` to clear. */
11
30
  static setUserId(userId?: string): void;
31
+ /** set a description for the current user. pass `undefined` to clear. */
12
32
  static setDescription(description?: string): void;
33
+ /** set custom metadata for the current user. pass `undefined` to clear. */
13
34
  static setMetadata(metadata?: RadarMetadata): void;
35
+ /** get the device's current location using the browser geolocation API */
14
36
  static getLocation(): Promise<NavigatorPosition>;
37
+ /** track the user's current location once, returning location context and events */
15
38
  static trackOnce(params?: RadarTrackParams): Promise<RadarTrackResponse>;
39
+ /** get context (geofences, place, regions) for a location without tracking */
16
40
  static getContext(params: Location): Promise<RadarContextResponse>;
41
+ /** save trip options for tracking. pass `undefined` to clear */
17
42
  static setTripOptions(tripOptions?: RadarTripOptions): void;
43
+ /** clear saved trip options */
18
44
  static clearTripOptions(): void;
45
+ /** get the currently saved trip options */
19
46
  static getTripOptions(): RadarTripOptions;
47
+ /** start a new trip with the given options */
20
48
  static startTrip(tripOptions: RadarTripOptions): Promise<RadarTripResponse>;
49
+ /** update an in-progress trip */
21
50
  static updateTrip(tripOptions: RadarTripOptions): Promise<RadarTripResponse>;
51
+ /** complete the current trip and clear local trip options */
22
52
  static completeTrip(): Promise<RadarTripResponse>;
53
+ /** cancel the current trip and clear local trip options */
23
54
  static cancelTrip(): Promise<RadarTripResponse>;
55
+ /** log a conversion event */
24
56
  static logConversion(params: RadarConversionParams): Promise<RadarConversionResponse>;
57
+ /** set the product identifier for tracking requests. pass `undefined` to clear */
25
58
  static setProduct(product?: string): void;
59
+ /** register a global error callback invoked on SDK errors */
26
60
  static onError(callback: (error: RadarError) => void): void;
61
+ /** geocode an address or place name to coordinates */
27
62
  static forwardGeocode(params: RadarForwardGeocodeParams): Promise<RadarGeocodeResponse>;
63
+ /** reverse geocode coordinates to addresses */
28
64
  static reverseGeocode(params: RadarReverseGeocodeParams): Promise<RadarGeocodeResponse>;
65
+ /** geocode the device's IP address to a rough location */
29
66
  static ipGeocode(): Promise<RadarIPGeocodeResponse>;
67
+ /** autocomplete partial addresses and place names */
30
68
  static autocomplete(params: RadarAutocompleteParams): Promise<RadarAutocompleteResponse>;
69
+ /** search for geofences near a location */
31
70
  static searchGeofences(params: RadarSearchGeofencesParams): Promise<RadarSearchGeofencesResponse>;
71
+ /** search for places (POIs) near a location */
32
72
  static searchPlaces(params: RadarSearchPlacesParams): Promise<RadarSearchPlacesResponse>;
73
+ /** validate a structured address */
33
74
  static validateAddress(params: RadarValidateAddressParams): Promise<RadarValidateAddressResponse>;
75
+ /** calculate travel distance and duration between two points */
34
76
  static distance(params: RadarDistanceParams): Promise<RadarRouteResponse>;
77
+ /** calculate a distance matrix between multiple origins and destinations */
35
78
  static matrix(params: RadarMatrixParams): Promise<RadarMatrixResponse>;
36
79
  }
37
80
  export default Radar;
package/dist/config.d.ts CHANGED
@@ -1,8 +1,12 @@
1
- import { RadarError } from './errors';
1
+ import type { RadarError } from './errors';
2
2
  import type { RadarOptions } from './types';
3
+ /** global SDK configuration singleton */
3
4
  declare class Config {
5
+ /** current SDK options */
4
6
  static options: RadarOptions;
7
+ /** registered error callback, if any */
5
8
  static errorCallback: ((error: RadarError) => void) | null;
9
+ /** default option values applied during initialization */
6
10
  static defaultOptions: {
7
11
  live: boolean;
8
12
  logLevel: string;
@@ -10,10 +14,15 @@ declare class Config {
10
14
  version: string;
11
15
  debug: boolean;
12
16
  };
17
+ /** store SDK options (called by Radar.initialize) */
13
18
  static setup(options?: RadarOptions): void;
19
+ /** get the current SDK options */
14
20
  static get(): RadarOptions;
21
+ /** clear all SDK options and error callback */
15
22
  static clear(): void;
23
+ /** register a callback invoked on SDK errors */
16
24
  static onError(callback: (error: RadarError) => void): void;
25
+ /** dispatch an error to the registered callback */
17
26
  static sendError(error: any): void;
18
27
  }
19
28
  export default Config;
package/dist/device.d.ts CHANGED
@@ -1,5 +1,14 @@
1
+ /** device and install ID manager backed by localStorage */
1
2
  declare class Device {
3
+ /**
4
+ * get or generate a persistent device ID
5
+ * @returns the device UUID (persisted in localStorage)
6
+ */
2
7
  static getDeviceId(): string;
8
+ /**
9
+ * get or generate a persistent install ID
10
+ * @returns the install UUID (persisted in localStorage)
11
+ */
3
12
  static getInstallId(): string;
4
13
  }
5
14
  export default Device;
package/dist/errors.d.ts CHANGED
@@ -1,55 +1,71 @@
1
+ import type { RadarResponse } from './http';
2
+ /** base error class for all Radar SDK errors */
1
3
  export declare class RadarError extends Error {
4
+ /** legacy status code string (e.g. `'ERROR_PUBLISHABLE_KEY'`) */
2
5
  status: string;
3
6
  constructor(message: string);
4
7
  }
8
+ /** thrown when a publishable key is missing or invalid (e.g. secret key used) */
5
9
  export declare class RadarPublishableKeyError extends RadarError {
6
10
  constructor(message: string);
7
11
  }
12
+ /** thrown when the device location cannot be determined */
8
13
  export declare class RadarLocationError extends RadarError {
9
14
  constructor(message: string);
10
15
  }
16
+ /** thrown when location permissions are denied by the browser */
11
17
  export declare class RadarPermissionsError extends RadarError {
12
18
  constructor(message: string);
13
19
  }
20
+ /** thrown on HTTP 400 Bad Request responses */
14
21
  export declare class RadarBadRequestError extends RadarError {
15
22
  code: number;
16
- response?: any;
17
- constructor(response?: any);
23
+ response?: RadarResponse;
24
+ constructor(response?: RadarResponse);
18
25
  }
26
+ /** thrown on HTTP 401 Unauthorized responses */
19
27
  export declare class RadarUnauthorizedError extends RadarError {
20
28
  code: number;
21
- response?: any;
22
- constructor(response?: any);
29
+ response?: RadarResponse;
30
+ constructor(response?: RadarResponse);
23
31
  }
32
+ /** thrown on HTTP 402 Payment Required responses */
24
33
  export declare class RadarPaymentRequiredError extends RadarError {
25
34
  code: number;
26
- response?: any;
27
- constructor(response?: any);
35
+ response?: RadarResponse;
36
+ constructor(response?: RadarResponse);
28
37
  }
38
+ /** thrown on HTTP 403 Forbidden responses */
29
39
  export declare class RadarForbiddenError extends RadarError {
30
40
  code: number;
31
- response?: any;
32
- constructor(response?: any);
41
+ response?: RadarResponse;
42
+ constructor(response?: RadarResponse);
33
43
  }
44
+ /** thrown on HTTP 404 Not Found responses */
34
45
  export declare class RadarNotFoundError extends RadarError {
35
46
  code: number;
36
- response?: any;
37
- constructor(response?: any);
47
+ response?: RadarResponse;
48
+ constructor(response?: RadarResponse);
38
49
  }
50
+ /** thrown on HTTP 429 Rate Limit responses */
39
51
  export declare class RadarRateLimitError extends RadarError {
40
52
  code: number;
41
- response?: any;
42
- type: string;
43
- constructor(response?: any);
53
+ response?: RadarResponse;
54
+ /** rate limit type from the API response (e.g. `'hourly'`) */
55
+ type?: string;
56
+ constructor(response?: RadarResponse);
44
57
  }
58
+ /** thrown on HTTP 5xx server errors */
45
59
  export declare class RadarServerError extends RadarError {
46
- response?: any;
47
- constructor(response?: any);
60
+ response?: RadarResponse;
61
+ constructor(response?: RadarResponse);
48
62
  }
63
+ /** thrown when a request times out or the network is unavailable */
49
64
  export declare class RadarNetworkError extends RadarError {
50
65
  constructor();
51
66
  }
67
+ /** thrown for unexpected/unclassified errors */
52
68
  export declare class RadarUnknownError extends RadarError {
53
- response?: any;
54
- constructor(response?: any);
69
+ response?: RadarResponse;
70
+ constructor(response?: RadarResponse);
55
71
  }
package/dist/http.d.ts CHANGED
@@ -1,20 +1,58 @@
1
- export type HttpMethod = 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE';
2
- interface HttpResponse {
1
+ /** HTTP methods supported by the SDK */
2
+ type HttpMethod = 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE';
3
+ /** Shape of the `meta` field present in all Radar API responses */
4
+ interface RadarApiMeta {
5
+ error?: string;
6
+ message?: string;
7
+ type?: string;
8
+ }
9
+ /** Base shape all Radar API JSON responses share */
10
+ interface RadarApiResponse {
11
+ meta?: RadarApiMeta;
12
+ [key: string]: unknown;
13
+ }
14
+ /** Blob response shape returned when responseType is 'blob' */
15
+ interface RadarBlobResponse {
16
+ meta?: undefined;
3
17
  code: number;
4
- data: any;
18
+ data: Blob;
19
+ }
20
+ export type RadarResponse = RadarApiResponse | RadarBlobResponse;
21
+ /** Request configuration for Http.request */
22
+ interface HttpRequestOptions {
23
+ method: HttpMethod;
24
+ path: string;
25
+ data?: Record<string, any>;
26
+ host?: string;
27
+ version?: string;
28
+ headers?: Record<string, string>;
29
+ responseType?: 'blob' | 'json';
30
+ requestId?: string;
5
31
  }
32
+ /** fetch-based HTTP client for Radar API requests */
6
33
  declare class Http {
34
+ /** map of host patterns to custom error factories for intercepting network errors */
7
35
  static errorInterceptors: Map<string, (online: boolean) => Error>;
36
+ /**
37
+ * register a custom error factory for network errors matching a host pattern
38
+ * @param hostPattern - substring matched against the request host
39
+ * @param handler - factory that receives online status and returns an error
40
+ */
8
41
  static registerErrorInterceptor(hostPattern: string, handler: (online: boolean) => Error): void;
9
- static request({ method, path, data, host, version, headers, responseType, requestId, }: {
10
- method: HttpMethod;
11
- path: string;
12
- data?: any;
13
- host?: string;
14
- version?: string;
15
- headers?: Record<string, string>;
16
- responseType?: XMLHttpRequestResponseType;
17
- requestId?: string;
18
- }): Promise<HttpResponse>;
42
+ /**
43
+ * send an HTTP request to the Radar API
44
+ * @param options - request configuration
45
+ * @returns parsed response body, typed as `T`
46
+ * @throws {RadarPublishableKeyError} if publishable key is not set
47
+ * @throws {RadarBadRequestError} on 400 responses
48
+ * @throws {RadarUnauthorizedError} on 401 responses
49
+ * @throws {RadarNetworkError} on network failures
50
+ */
51
+ static request(options: HttpRequestOptions & {
52
+ responseType: 'blob';
53
+ }): Promise<RadarBlobResponse>;
54
+ static request<T extends Record<string, any> = RadarApiResponse>(options: HttpRequestOptions): Promise<T & {
55
+ meta?: RadarApiMeta;
56
+ }>;
19
57
  }
20
58
  export default Http;
@@ -1,4 +1,4 @@
1
- import RadarBase, { RadarError } from ".";
1
+ import RadarBase, { RadarError } from '.';
2
2
  declare class Radar extends RadarBase {
3
3
  static RadarError: typeof RadarError;
4
4
  }
package/dist/logger.d.ts CHANGED
@@ -1,7 +1,12 @@
1
+ /** leveled console logger controlled by SDK config */
1
2
  declare class Logger {
3
+ /** log a debug-level message (only when debug mode is enabled) */
2
4
  static debug(message: string, options?: any): void;
5
+ /** log an info-level message */
3
6
  static info(message: string): void;
7
+ /** log a warning-level message */
4
8
  static warn(message: string): void;
9
+ /** log an error-level message */
5
10
  static error(message: string): void;
6
11
  }
7
12
  export default Logger;