radar-sdk-js 5.0.0 → 5.1.0-beta.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/README.md +19 -23
- package/dist/api.d.ts +9 -3
- package/dist/config.d.ts +4 -0
- package/dist/dns-over-https.d.ts +29 -0
- package/dist/errors.d.ts +51 -1
- package/dist/http.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/logger.d.ts +2 -2
- package/dist/radar.js +366 -101
- package/dist/radar.js.map +1 -1
- package/dist/types.d.ts +26 -6
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/api.ts +48 -26
- package/src/config.ts +22 -0
- package/src/dns-over-https.ts +166 -0
- package/src/errors.ts +65 -2
- package/src/http.ts +194 -25
- package/src/index.ts +1 -0
- package/src/logger.ts +11 -12
- package/src/types.ts +30 -6
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -46,10 +46,8 @@ Then import and initialize:
|
|
|
46
46
|
```js
|
|
47
47
|
import Radar from 'radar-sdk-js';
|
|
48
48
|
|
|
49
|
-
// initialize with your
|
|
50
|
-
Radar.initialize('prj_test_pk_...'
|
|
51
|
-
/* options */
|
|
52
|
-
});
|
|
49
|
+
// initialize with your publishable key
|
|
50
|
+
Radar.initialize({ publishableKey: 'prj_test_pk_...' });
|
|
53
51
|
```
|
|
54
52
|
|
|
55
53
|
### With a script tag
|
|
@@ -57,12 +55,10 @@ Radar.initialize('prj_test_pk_...', {
|
|
|
57
55
|
Add the following to your HTML:
|
|
58
56
|
|
|
59
57
|
```html
|
|
60
|
-
<script src="https://js.radar.com/v5.0.
|
|
58
|
+
<script src="https://js.radar.com/v5.1.0-beta.1/radar.min.js"></script>
|
|
61
59
|
|
|
62
60
|
<script>
|
|
63
|
-
Radar.initialize('prj_test_pk_...'
|
|
64
|
-
/* options */
|
|
65
|
-
});
|
|
61
|
+
Radar.initialize({ publishableKey: 'prj_test_pk_...' });
|
|
66
62
|
</script>
|
|
67
63
|
```
|
|
68
64
|
|
|
@@ -84,7 +80,7 @@ import { createMapsPlugin } from '@radarlabs/plugin-maps';
|
|
|
84
80
|
import '@radarlabs/plugin-maps/dist/radar-maps.css';
|
|
85
81
|
|
|
86
82
|
Radar.registerPlugin(createMapsPlugin());
|
|
87
|
-
Radar.initialize('prj_test_pk_...');
|
|
83
|
+
Radar.initialize({ publishableKey: 'prj_test_pk_...' });
|
|
88
84
|
|
|
89
85
|
const map = Radar.ui.map({
|
|
90
86
|
container: 'map',
|
|
@@ -103,7 +99,7 @@ import { createAutocompletePlugin } from '@radarlabs/plugin-autocomplete';
|
|
|
103
99
|
import '@radarlabs/plugin-autocomplete/dist/radar-autocomplete.css';
|
|
104
100
|
|
|
105
101
|
Radar.registerPlugin(createAutocompletePlugin());
|
|
106
|
-
Radar.initialize('prj_test_pk_...');
|
|
102
|
+
Radar.initialize({ publishableKey: 'prj_test_pk_...' });
|
|
107
103
|
|
|
108
104
|
Radar.ui.autocomplete({
|
|
109
105
|
container: 'autocomplete',
|
|
@@ -124,7 +120,7 @@ import Radar from 'radar-sdk-js';
|
|
|
124
120
|
import { createFraudPlugin } from '@radarlabs/plugin-fraud';
|
|
125
121
|
|
|
126
122
|
Radar.registerPlugin(createFraudPlugin());
|
|
127
|
-
Radar.initialize('prj_live_pk_...');
|
|
123
|
+
Radar.initialize({ publishableKey: 'prj_live_pk_...' });
|
|
128
124
|
|
|
129
125
|
const { token, user, events } = await Radar.fraud.trackVerified();
|
|
130
126
|
```
|
|
@@ -136,11 +132,11 @@ the core SDK first, then any plugins you need:
|
|
|
136
132
|
|
|
137
133
|
```html
|
|
138
134
|
<link href="https://js.radar.com/maps/v1.0.0/radar-maps.css" rel="stylesheet" />
|
|
139
|
-
<link href="https://js.radar.com/autocomplete/v1.
|
|
135
|
+
<link href="https://js.radar.com/autocomplete/v1.1.0/radar-autocomplete.css" rel="stylesheet" />
|
|
140
136
|
|
|
141
|
-
<script src="https://js.radar.com/v5.0.
|
|
137
|
+
<script src="https://js.radar.com/v5.1.0-beta.1/radar.min.js"></script>
|
|
142
138
|
<script src="https://js.radar.com/maps/v1.0.0/radar-maps.min.js"></script>
|
|
143
|
-
<script src="https://js.radar.com/autocomplete/v1.
|
|
139
|
+
<script src="https://js.radar.com/autocomplete/v1.1.0/radar-autocomplete.min.js"></script>
|
|
144
140
|
<script src="https://js.radar.com/fraud/v1.0.0/radar-fraud.min.js"></script>
|
|
145
141
|
```
|
|
146
142
|
|
|
@@ -155,7 +151,7 @@ by ID or element reference.
|
|
|
155
151
|
<html>
|
|
156
152
|
<head>
|
|
157
153
|
<link href="https://js.radar.com/maps/v1.0.0/radar-maps.css" rel="stylesheet" />
|
|
158
|
-
<script src="https://js.radar.com/v5.0.
|
|
154
|
+
<script src="https://js.radar.com/v5.1.0-beta.1/radar.min.js"></script>
|
|
159
155
|
<script src="https://js.radar.com/maps/v1.0.0/radar-maps.min.js"></script>
|
|
160
156
|
</head>
|
|
161
157
|
|
|
@@ -163,7 +159,7 @@ by ID or element reference.
|
|
|
163
159
|
<div id="map" style="width: 100%; height: 500px;" />
|
|
164
160
|
|
|
165
161
|
<script>
|
|
166
|
-
Radar.initialize('<RADAR_PUBLISHABLE_KEY>');
|
|
162
|
+
Radar.initialize({ publishableKey: '<RADAR_PUBLISHABLE_KEY>' });
|
|
167
163
|
|
|
168
164
|
const map = Radar.ui.map({
|
|
169
165
|
container: 'map', // OR document.getElementById('map')
|
|
@@ -181,16 +177,16 @@ by ID or element reference.
|
|
|
181
177
|
```html
|
|
182
178
|
<html>
|
|
183
179
|
<head>
|
|
184
|
-
<link href="https://js.radar.com/autocomplete/v1.
|
|
185
|
-
<script src="https://js.radar.com/v5.0.
|
|
186
|
-
<script src="https://js.radar.com/autocomplete/v1.
|
|
180
|
+
<link href="https://js.radar.com/autocomplete/v1.1.0/radar-autocomplete.css" rel="stylesheet" />
|
|
181
|
+
<script src="https://js.radar.com/v5.1.0-beta.1/radar.min.js"></script>
|
|
182
|
+
<script src="https://js.radar.com/autocomplete/v1.1.0/radar-autocomplete.min.js"></script>
|
|
187
183
|
</head>
|
|
188
184
|
|
|
189
185
|
<body>
|
|
190
186
|
<div id="autocomplete" />
|
|
191
187
|
|
|
192
188
|
<script>
|
|
193
|
-
Radar.initialize('<RADAR_PUBLISHABLE_KEY>');
|
|
189
|
+
Radar.initialize({ publishableKey: '<RADAR_PUBLISHABLE_KEY>' });
|
|
194
190
|
|
|
195
191
|
// create autocomplete widget
|
|
196
192
|
Radar.ui.autocomplete({
|
|
@@ -215,12 +211,12 @@ are needed for geofencing.
|
|
|
215
211
|
```html
|
|
216
212
|
<html>
|
|
217
213
|
<head>
|
|
218
|
-
<script src="https://js.radar.com/v5.0.
|
|
214
|
+
<script src="https://js.radar.com/v5.1.0-beta.1/radar.min.js"></script>
|
|
219
215
|
</head>
|
|
220
216
|
|
|
221
217
|
<body>
|
|
222
218
|
<script>
|
|
223
|
-
Radar.initialize('<RADAR_PUBLISHABLE_KEY>');
|
|
219
|
+
Radar.initialize({ publishableKey: '<RADAR_PUBLISHABLE_KEY>' });
|
|
224
220
|
|
|
225
221
|
Radar.trackOnce({ userId: 'example-user-id' }).then(({ location, user, events }) => {
|
|
226
222
|
// do something with user location or events
|
|
@@ -254,7 +250,7 @@ import { createFraudPlugin } from '@radarlabs/plugin-fraud';
|
|
|
254
250
|
Radar.registerPlugin(createMapsPlugin());
|
|
255
251
|
Radar.registerPlugin(createAutocompletePlugin());
|
|
256
252
|
Radar.registerPlugin(createFraudPlugin());
|
|
257
|
-
Radar.initialize('prj_test_pk_...');
|
|
253
|
+
Radar.initialize({ publishableKey: 'prj_test_pk_...' });
|
|
258
254
|
```
|
|
259
255
|
|
|
260
256
|
If you're building a custom plugin, import the plugin types from the
|
package/dist/api.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as errors from './errors';
|
|
2
2
|
import type { RadarError } from './errors';
|
|
3
3
|
import type { RadarPlugin } from './plugin';
|
|
4
|
-
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
|
+
import type { Location, NavigatorPosition, RadarAutocompleteParams, RadarAutocompleteResponse, RadarContextResponse, RadarConversionParams, RadarConversionResponse, RadarDistanceParams, RadarForwardGeocodeParams, RadarGeocodeResponse, RadarIPGeocodeResponse, RadarMatrixParams, RadarMatrixResponse, RadarMetadata, RadarInitOptions, RadarOptions, RadarReverseGeocodeParams, RadarRouteResponse, RadarSearchGeofencesParams, RadarSearchGeofencesResponse, RadarSearchPlacesParams, RadarSearchPlacesResponse, RadarTrackParams, RadarTrackResponse, RadarTripOptions, RadarTripResponse, RadarValidateAddressParams, RadarValidateAddressResponse } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* main entry point for the Radar SDK. all methods are static — do not instantiate.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```ts
|
|
10
|
-
* Radar.initialize('prj_test_pk_...');
|
|
10
|
+
* Radar.initialize({ publishableKey: 'prj_test_pk_...' });
|
|
11
11
|
* const { user, events } = await Radar.trackOnce();
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
@@ -20,7 +20,13 @@ declare class Radar {
|
|
|
20
20
|
static registerPlugin(...plugins: RadarPlugin[]): void;
|
|
21
21
|
private static _getPluginContext;
|
|
22
22
|
/**
|
|
23
|
-
* initialize the SDK with
|
|
23
|
+
* initialize the SDK with an authToken or publishable key via options object.
|
|
24
|
+
* @param options - SDK configuration with `authToken` or `publishableKey`
|
|
25
|
+
* @throws {RadarPublishableKeyError} if credentials are missing or invalid
|
|
26
|
+
*/
|
|
27
|
+
static initialize(options: RadarInitOptions): void;
|
|
28
|
+
/**
|
|
29
|
+
* initialize the SDK with a publishable key string.
|
|
24
30
|
* @param publishableKey - your Radar publishable key (starts with `prj_test_pk_` or `prj_live_pk_`)
|
|
25
31
|
* @param options - optional SDK configuration
|
|
26
32
|
* @throws {RadarPublishableKeyError} if the key is missing or is a secret key
|
package/dist/config.d.ts
CHANGED
|
@@ -24,5 +24,9 @@ declare class Config {
|
|
|
24
24
|
static onError(callback: (error: RadarError) => void): void;
|
|
25
25
|
/** dispatch an error to the registered callback */
|
|
26
26
|
static sendError(error: any): void;
|
|
27
|
+
/** build standard Radar request headers (Authorization, Device-Type, SDK-Version).
|
|
28
|
+
* Callers must ensure credentials are set before calling (e.g. via Radar.initialize).
|
|
29
|
+
* */
|
|
30
|
+
static getDefaultHeaders(): Record<string, string>;
|
|
27
31
|
}
|
|
28
32
|
export default Config;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type DnsProbeResult = {
|
|
2
|
+
status: 'success';
|
|
3
|
+
hostname: string;
|
|
4
|
+
resolver: 'cloudflare-dns.com';
|
|
5
|
+
dnsStatus: number;
|
|
6
|
+
ipv4Answers: string[];
|
|
7
|
+
} | {
|
|
8
|
+
status: 'no_answers';
|
|
9
|
+
hostname: string;
|
|
10
|
+
resolver: 'cloudflare-dns.com';
|
|
11
|
+
dnsStatus: number;
|
|
12
|
+
answerCount: number;
|
|
13
|
+
note: string;
|
|
14
|
+
} | {
|
|
15
|
+
status: 'http_error';
|
|
16
|
+
hostname: string;
|
|
17
|
+
resolver: 'cloudflare-dns.com';
|
|
18
|
+
httpStatus: number;
|
|
19
|
+
} | {
|
|
20
|
+
status: 'fetch_error';
|
|
21
|
+
hostname: string;
|
|
22
|
+
resolver: 'cloudflare-dns.com';
|
|
23
|
+
errorMessage: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Runs at most one DoH probe per hostname per page load. Returns a promise you can await
|
|
27
|
+
* from `RadarNetworkError.dnsProbe` — does not block the throwing error path.
|
|
28
|
+
*/
|
|
29
|
+
export declare function scheduleDnsOverHttpsProbe(hostname: string | undefined, correlation: Record<string, unknown>): Promise<DnsProbeResult> | null;
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { DnsProbeResult } from './dns-over-https';
|
|
1
2
|
import type { RadarResponse } from './http';
|
|
3
|
+
export type { DnsProbeResult };
|
|
2
4
|
/** base error class for all Radar SDK errors */
|
|
3
5
|
export declare abstract class RadarError extends Error {
|
|
4
6
|
/** legacy status code string (e.g. `'ERROR_PUBLISHABLE_KEY'`) */
|
|
@@ -81,11 +83,59 @@ export declare class RadarServerError extends RadarError {
|
|
|
81
83
|
readonly response?: RadarResponse;
|
|
82
84
|
constructor(response?: RadarResponse);
|
|
83
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Diagnostics captured when fetch() rejects before any HTTP response is received.
|
|
88
|
+
* Safe to stringify for logs — does not include request headers or bodies.
|
|
89
|
+
*/
|
|
90
|
+
export interface RadarNetworkFailureDetails {
|
|
91
|
+
readonly phase: 'fetch';
|
|
92
|
+
readonly method: string;
|
|
93
|
+
readonly url: string;
|
|
94
|
+
readonly pathname: string;
|
|
95
|
+
readonly search: string;
|
|
96
|
+
/** hostname parsed from the request URL */
|
|
97
|
+
readonly apiHostname?: string;
|
|
98
|
+
/** document origin when in a browser */
|
|
99
|
+
readonly pageOrigin?: string;
|
|
100
|
+
/** document pathname when in a browser */
|
|
101
|
+
readonly pagePath?: string;
|
|
102
|
+
/** `navigator.userAgent` when available */
|
|
103
|
+
readonly userAgent?: string;
|
|
104
|
+
/** true when API hostname differs from the document hostname */
|
|
105
|
+
readonly crossSiteApiCall?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Wall-clock ms from immediately before `fetch()` until it rejected (rounded integer).
|
|
108
|
+
* Does not include JSON parse time when a response was received.
|
|
109
|
+
*/
|
|
110
|
+
readonly durationMs: number;
|
|
111
|
+
/** whether `navigator.onLine` was false at failure time */
|
|
112
|
+
readonly online: boolean;
|
|
113
|
+
/** true when failure was triggered by AbortController / user abort */
|
|
114
|
+
readonly aborted: boolean;
|
|
115
|
+
readonly errorName: string;
|
|
116
|
+
readonly errorMessage: string;
|
|
117
|
+
/** present when the environment threw an Error with a stack */
|
|
118
|
+
readonly errorStack?: string;
|
|
119
|
+
readonly connectionEffectiveType?: string;
|
|
120
|
+
readonly connectionDownlink?: number;
|
|
121
|
+
readonly connectionRtt?: number;
|
|
122
|
+
readonly connectionSaveData?: boolean;
|
|
123
|
+
readonly requestId?: string;
|
|
124
|
+
}
|
|
84
125
|
/** thrown when a request times out or the network is unavailable */
|
|
85
126
|
export declare class RadarNetworkError extends RadarError {
|
|
86
127
|
readonly name = "RadarNetworkError";
|
|
87
128
|
readonly status = "ERROR_NETWORK";
|
|
88
|
-
|
|
129
|
+
/** set when fetch() fails in the SDK HTTP client (omit for API `ERROR_NETWORK` responses) */
|
|
130
|
+
readonly details?: RadarNetworkFailureDetails;
|
|
131
|
+
/** original rejection from fetch; often a `TypeError` or `DOMException` */
|
|
132
|
+
readonly fetchError?: unknown;
|
|
133
|
+
/**
|
|
134
|
+
* Resolves when the optional Cloudflare DNS-over-HTTPS (A record) probe finishes.
|
|
135
|
+
* Only set for non-aborted fetch failures where a probe was scheduled (`null` if skipped in tests, no hostname, or a probe already ran for this host).
|
|
136
|
+
*/
|
|
137
|
+
readonly dnsProbe?: Promise<DnsProbeResult>;
|
|
138
|
+
constructor(message?: string, details?: RadarNetworkFailureDetails, fetchError?: unknown, dnsProbe?: Promise<DnsProbeResult> | null);
|
|
89
139
|
}
|
|
90
140
|
/** thrown for unexpected/unclassified errors */
|
|
91
141
|
export declare class RadarUnknownError extends RadarError {
|
package/dist/http.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ declare class Http {
|
|
|
43
43
|
* send an HTTP request to the Radar API
|
|
44
44
|
* @param options - request configuration
|
|
45
45
|
* @returns parsed response body, typed as `T`
|
|
46
|
-
* @throws {RadarPublishableKeyError} if publishable key is
|
|
46
|
+
* @throws {RadarPublishableKeyError} if neither publishable key nor authToken is set
|
|
47
47
|
* @throws {RadarBadRequestError} on 400 responses
|
|
48
48
|
* @throws {RadarUnauthorizedError} on 401 responses
|
|
49
49
|
* @throws {RadarNetworkError} on network failures
|
package/dist/index.d.ts
CHANGED
package/dist/logger.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare class Logger {
|
|
|
6
6
|
static info(message: string): void;
|
|
7
7
|
/** log a warning-level message */
|
|
8
8
|
static warn(message: string): void;
|
|
9
|
-
/** log an error-level message */
|
|
10
|
-
static error(message: string): void;
|
|
9
|
+
/** log an error-level message; optional second argument for structured diagnostics (printed as a separate console.error arg) */
|
|
10
|
+
static error(message: string, data?: unknown): void;
|
|
11
11
|
}
|
|
12
12
|
export default Logger;
|