radar-sdk-js 5.0.0-beta.5 → 5.0.0-beta.7

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 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.5/radar.min.js"></script>
60
+ <script src="https://js.radar.com/v5.0.0-beta.7/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.5/radar.min.js"></script>
141
+ <script src="https://js.radar.com/v5.0.0-beta.7/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.5/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.7/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.5/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.7/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.5/radar.min.js"></script>
218
+ <script src="https://js.radar.com/v5.0.0-beta.7/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,10 +1,19 @@
1
- import type { RadarTrackParams } from '../types';
1
+ import type { RadarConfigResponse, RadarTrackParams } from '../types';
2
+ /** options for customizing the config request (e.g. host, headers) */
3
+ interface ConfigRequestOptions {
4
+ /** override the API host */
5
+ host?: string;
6
+ /** additional headers to include in the request */
7
+ headers?: Record<string, string>;
8
+ }
2
9
  /** @internal SDK configuration API for fetching remote config */
3
10
  declare class ConfigAPI {
4
11
  /**
5
- * fetch remote SDK configuration from the Radar API
12
+ * fetch remote SDK configuration from the Radar API. Generic so plugins can extend the response shape.
13
+ *
6
14
  * @param params - optional tracking params for device/session identification
15
+ * @param options - optional request overrides (host, headers)
7
16
  */
8
- static getConfig(params?: RadarTrackParams): Promise<void>;
17
+ static getConfig<T extends RadarConfigResponse = RadarConfigResponse>(params?: RadarTrackParams, options?: ConfigRequestOptions): Promise<T>;
9
18
  }
10
19
  export default ConfigAPI;
@@ -1,4 +1,4 @@
1
- import { RadarForwardGeocodeParams, RadarReverseGeocodeParams, RadarGeocodeResponse, RadarIPGeocodeResponse } from '../types';
1
+ import type { RadarForwardGeocodeParams, RadarReverseGeocodeParams, RadarGeocodeResponse, RadarIPGeocodeResponse } from '../types';
2
2
  /** @internal geocoding API — use Radar.forwardGeocode / reverseGeocode / ipGeocode instead */
3
3
  declare class Geocoding {
4
4
  /**
package/dist/api.d.ts CHANGED
@@ -1,4 +1,4 @@
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
4
  /**
@@ -65,7 +65,7 @@ declare class Radar {
65
65
  /** geocode the device's IP address to a rough location */
66
66
  static ipGeocode(): Promise<RadarIPGeocodeResponse>;
67
67
  /** autocomplete partial addresses and place names */
68
- static autocomplete(params: RadarAutocompleteParams): Promise<RadarAutocompleteResponse>;
68
+ static autocomplete(params: RadarAutocompleteParams, requestId?: string): Promise<RadarAutocompleteResponse>;
69
69
  /** search for geofences near a location */
70
70
  static searchGeofences(params: RadarSearchGeofencesParams): Promise<RadarSearchGeofencesResponse>;
71
71
  /** search for places (POIs) near a location */
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RadarError } from './errors';
1
+ import type { RadarError } from './errors';
2
2
  import type { RadarOptions } from './types';
3
3
  /** global SDK configuration singleton */
4
4
  declare class Config {
package/dist/errors.d.ts CHANGED
@@ -1,71 +1,96 @@
1
- import type { RadarResponse } from "./http";
1
+ import type { RadarResponse } from './http';
2
2
  /** base error class for all Radar SDK errors */
3
- export declare class RadarError extends Error {
3
+ export declare abstract class RadarError extends Error {
4
4
  /** legacy status code string (e.g. `'ERROR_PUBLISHABLE_KEY'`) */
5
- status: string;
5
+ abstract readonly status: string;
6
+ abstract readonly name: string;
6
7
  constructor(message: string);
7
8
  }
8
9
  /** thrown when a publishable key is missing or invalid (e.g. secret key used) */
9
10
  export declare class RadarPublishableKeyError extends RadarError {
11
+ readonly name = "RadarPublishableKeyError";
12
+ readonly status = "ERROR_PUBLISHABLE_KEY";
10
13
  constructor(message: string);
11
14
  }
12
15
  /** thrown when the device location cannot be determined */
13
16
  export declare class RadarLocationError extends RadarError {
17
+ readonly name = "RadarLocationError";
18
+ readonly status = "ERROR_LOCATION";
14
19
  constructor(message: string);
15
20
  }
16
21
  /** thrown when location permissions are denied by the browser */
17
22
  export declare class RadarPermissionsError extends RadarError {
23
+ readonly name = "RadarPermissionsError";
24
+ readonly status = "ERROR_PERMISSIONS";
18
25
  constructor(message: string);
19
26
  }
20
27
  /** thrown on HTTP 400 Bad Request responses */
21
28
  export declare class RadarBadRequestError extends RadarError {
22
- code: number;
23
- response?: RadarResponse;
29
+ readonly name = "RadarBadRequestError";
30
+ readonly status = "ERROR_BAD_REQUEST";
31
+ readonly code = 400;
32
+ readonly response?: RadarResponse;
24
33
  constructor(response?: RadarResponse);
25
34
  }
26
35
  /** thrown on HTTP 401 Unauthorized responses */
27
36
  export declare class RadarUnauthorizedError extends RadarError {
28
- code: number;
29
- response?: RadarResponse;
37
+ readonly name = "RadarUnauthorizedError";
38
+ readonly status = "ERROR_UNAUTHORIZED";
39
+ readonly code = 401;
40
+ readonly response?: RadarResponse;
30
41
  constructor(response?: RadarResponse);
31
42
  }
32
43
  /** thrown on HTTP 402 Payment Required responses */
33
44
  export declare class RadarPaymentRequiredError extends RadarError {
34
- code: number;
35
- response?: RadarResponse;
45
+ readonly name = "RadarPaymentRequiredError";
46
+ readonly status = "ERROR_PAYMENT_REQUIRED";
47
+ readonly code = 402;
48
+ readonly response?: RadarResponse;
36
49
  constructor(response?: RadarResponse);
37
50
  }
38
51
  /** thrown on HTTP 403 Forbidden responses */
39
52
  export declare class RadarForbiddenError extends RadarError {
40
- code: number;
41
- response?: RadarResponse;
53
+ readonly name = "RadarForbiddenError";
54
+ readonly status = "ERROR_FORBIDDEN";
55
+ readonly code = 403;
56
+ readonly response?: RadarResponse;
42
57
  constructor(response?: RadarResponse);
43
58
  }
44
59
  /** thrown on HTTP 404 Not Found responses */
45
60
  export declare class RadarNotFoundError extends RadarError {
46
- code: number;
47
- response?: RadarResponse;
61
+ readonly name = "RadarNotFoundError";
62
+ readonly status = "ERROR_NOT_FOUND";
63
+ readonly code = 404;
64
+ readonly response?: RadarResponse;
48
65
  constructor(response?: RadarResponse);
49
66
  }
50
67
  /** thrown on HTTP 429 Rate Limit responses */
51
68
  export declare class RadarRateLimitError extends RadarError {
52
- code: number;
53
- response?: RadarResponse;
69
+ readonly name = "RadarRateLimitError";
70
+ readonly status = "ERROR_RATE_LIMIT";
71
+ readonly code = 429;
72
+ readonly response?: RadarResponse;
54
73
  /** rate limit type from the API response (e.g. `'hourly'`) */
55
- type?: string;
74
+ readonly type?: string;
56
75
  constructor(response?: RadarResponse);
57
76
  }
58
77
  /** thrown on HTTP 5xx server errors */
59
78
  export declare class RadarServerError extends RadarError {
60
- response?: RadarResponse;
79
+ readonly name = "RadarServerError";
80
+ readonly status = "ERROR_SERVER";
81
+ readonly response?: RadarResponse;
61
82
  constructor(response?: RadarResponse);
62
83
  }
63
84
  /** thrown when a request times out or the network is unavailable */
64
85
  export declare class RadarNetworkError extends RadarError {
86
+ readonly name = "RadarNetworkError";
87
+ readonly status = "ERROR_NETWORK";
65
88
  constructor();
66
89
  }
67
90
  /** thrown for unexpected/unclassified errors */
68
91
  export declare class RadarUnknownError extends RadarError {
69
- response?: RadarResponse;
92
+ readonly name = "RadarUnknownError";
93
+ readonly status = "ERROR_UNKNOWN";
94
+ readonly response?: RadarResponse;
70
95
  constructor(response?: RadarResponse);
71
96
  }
@@ -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
  }
@@ -18,6 +18,6 @@ declare class Navigator {
18
18
  */
19
19
  static getPermissionStatus(): Promise<LocationAuthorization>;
20
20
  /** check whether the browser reports being online */
21
- static online(): Boolean;
21
+ static online(): boolean;
22
22
  }
23
23
  export default Navigator;
package/dist/plugin.d.ts CHANGED
@@ -1,11 +1,4 @@
1
1
  import type Radar from './api';
2
- import type Config from './config';
3
- import type Http from './http';
4
- import type Storage from './storage';
5
- import type Device from './device';
6
- import type Session from './session';
7
- import type Logger from './logger';
8
- import type Navigator from './navigator';
9
2
  import type AddressesAPI from './api/addresses';
10
3
  import type ConfigAPI from './api/config';
11
4
  import type ContextAPI from './api/context';
@@ -15,7 +8,14 @@ import type RoutingAPI from './api/routing';
15
8
  import type SearchAPI from './api/search';
16
9
  import type TrackAPI from './api/track';
17
10
  import type TripsAPI from './api/trips';
11
+ import type Config from './config';
12
+ import type Device from './device';
18
13
  import type * as errors from './errors';
14
+ import type Http from './http';
15
+ import type Logger from './logger';
16
+ import type Navigator from './navigator';
17
+ import type Session from './session';
18
+ import type Storage from './storage';
19
19
  /** interface that all Radar plugins must implement */
20
20
  export interface RadarPlugin {
21
21
  /** unique plugin name (e.g. `'maps'`, `'autocomplete'`) */