radar-sdk-js 4.5.0-beta.0 → 4.5.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 +8 -8
- package/dist/api/verify.d.ts +6 -4
- package/dist/api.d.ts +5 -4
- package/dist/logger.d.ts +1 -1
- package/dist/radar.js +235 -257
- package/dist/radar.js.map +1 -1
- package/dist/types.d.ts +31 -14
- package/dist/ui/RadarMap.d.ts +0 -1
- package/dist/ui/RadarMarker.d.ts +0 -2
- package/dist/ui/autocomplete.d.ts +4 -2
- package/dist/version.d.ts +1 -1
- package/package.json +13 -3
- package/src/api/geocoding.ts +2 -1
- package/src/api/search.ts +4 -0
- package/src/api/track.ts +0 -32
- package/src/api/verify.ts +110 -76
- package/src/api.ts +11 -6
- package/src/http.ts +6 -2
- package/src/logger.ts +2 -2
- package/src/navigator.ts +1 -1
- package/src/types.ts +38 -15
- package/src/ui/RadarLogoControl.ts +1 -0
- package/src/ui/RadarMap.ts +1 -12
- package/src/ui/RadarMarker.ts +81 -100
- package/src/ui/autocomplete.ts +34 -6
- package/src/version.ts +1 -1
package/dist/radar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radar.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"radar.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/types.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface RadarResponse {
|
|
|
27
27
|
response?: any;
|
|
28
28
|
}
|
|
29
29
|
export type RadarTravelMode = 'car' | 'foot' | 'bike' | 'motorbike' | 'truck';
|
|
30
|
-
export type RadarAvoidOption = 'tolls' | 'highways' | 'ferries';
|
|
30
|
+
export type RadarAvoidOption = 'tolls' | 'highways' | 'ferries' | 'borderCrossings';
|
|
31
31
|
export interface RadarTripOptions {
|
|
32
32
|
userId?: string;
|
|
33
33
|
externalId?: string;
|
|
@@ -54,8 +54,15 @@ export interface RadarTrackParams {
|
|
|
54
54
|
desiredAccuracy?: 'high' | 'medium' | 'low';
|
|
55
55
|
fraud?: boolean;
|
|
56
56
|
}
|
|
57
|
+
export interface RadarTrackVerifiedParams {
|
|
58
|
+
userId?: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
metadata?: RadarMetadata;
|
|
61
|
+
skipVerifyApp?: boolean;
|
|
62
|
+
}
|
|
57
63
|
export interface RadarStartTrackingVerifiedParams {
|
|
58
64
|
interval: number;
|
|
65
|
+
skipVerifyApp?: boolean;
|
|
59
66
|
}
|
|
60
67
|
export declare enum RadarEventConfidence {
|
|
61
68
|
none = 0,
|
|
@@ -188,7 +195,7 @@ export interface RadarCustomEvent {
|
|
|
188
195
|
export interface RadarConversionResponse extends RadarResponse {
|
|
189
196
|
event: RadarCustomEvent;
|
|
190
197
|
}
|
|
191
|
-
export type RadarGeocodeLayer = 'place' | 'address' | 'postalCode' | 'locality' | 'county' | 'state' | 'country' | 'coarse' | 'fine';
|
|
198
|
+
export type RadarGeocodeLayer = 'place' | 'address' | 'postalCode' | 'locality' | 'neighborhood' | 'county' | 'state' | 'country' | 'coarse' | 'fine';
|
|
192
199
|
export interface RadarAddress {
|
|
193
200
|
addressLabel?: string;
|
|
194
201
|
borough?: string;
|
|
@@ -214,9 +221,21 @@ export interface RadarAddress {
|
|
|
214
221
|
stateCode?: string;
|
|
215
222
|
street?: string;
|
|
216
223
|
}
|
|
224
|
+
export interface RadarTimeZone {
|
|
225
|
+
id: string;
|
|
226
|
+
name: string;
|
|
227
|
+
code: string;
|
|
228
|
+
currentTime: string;
|
|
229
|
+
utcOffset: number;
|
|
230
|
+
dstOffset: number;
|
|
231
|
+
}
|
|
217
232
|
export interface RadarAutocompleteAddress extends RadarAddress {
|
|
218
233
|
unit?: string;
|
|
219
234
|
}
|
|
235
|
+
export interface RadarGeocodeAddress extends RadarAddress {
|
|
236
|
+
unit?: string;
|
|
237
|
+
timeZone?: RadarTimeZone;
|
|
238
|
+
}
|
|
220
239
|
export type RadarValidationRecordType = 'S' | 'R' | 'P' | 'M' | 'H' | 'G' | 'F' | undefined;
|
|
221
240
|
export type RadarValidationPropertyType = 'commercial' | 'residential' | undefined;
|
|
222
241
|
export type RadarVerificationStatus = 'verified' | 'partially verified' | 'ambiguous' | 'unverified';
|
|
@@ -232,6 +251,7 @@ export interface RadarForwardGeocodeParams {
|
|
|
232
251
|
query: string;
|
|
233
252
|
layers?: RadarGeocodeLayer[];
|
|
234
253
|
country?: string;
|
|
254
|
+
lang?: string;
|
|
235
255
|
}
|
|
236
256
|
export interface RadarReverseGeocodeParams {
|
|
237
257
|
latitude?: number;
|
|
@@ -239,11 +259,11 @@ export interface RadarReverseGeocodeParams {
|
|
|
239
259
|
layers?: RadarGeocodeLayer[];
|
|
240
260
|
}
|
|
241
261
|
export interface RadarGeocodeResponse extends RadarResponse {
|
|
242
|
-
addresses:
|
|
262
|
+
addresses: RadarGeocodeAddress[];
|
|
243
263
|
}
|
|
244
264
|
export interface RadarIPGeocodeResponse extends RadarResponse {
|
|
245
265
|
ip: string;
|
|
246
|
-
address?:
|
|
266
|
+
address?: RadarGeocodeAddress;
|
|
247
267
|
proxy?: boolean;
|
|
248
268
|
}
|
|
249
269
|
export interface RadarAutocompleteParams {
|
|
@@ -255,6 +275,8 @@ export interface RadarAutocompleteParams {
|
|
|
255
275
|
/** @deprecated this is always true, regardless of the value passed here */
|
|
256
276
|
expandUnits?: boolean;
|
|
257
277
|
mailable?: boolean;
|
|
278
|
+
lang?: string;
|
|
279
|
+
postalCode?: string;
|
|
258
280
|
}
|
|
259
281
|
export interface RadarAutocompleteResponse extends RadarResponse {
|
|
260
282
|
addresses: RadarAutocompleteAddress[];
|
|
@@ -273,13 +295,14 @@ export interface RadarSearchPlace extends RadarPlace {
|
|
|
273
295
|
export interface RadarSearchPlacesResponse extends RadarResponse {
|
|
274
296
|
places: RadarSearchPlace[];
|
|
275
297
|
}
|
|
298
|
+
export type RadarDistanceGeometryType = 'polyline' | 'polyline5' | 'polyline6' | 'linestring';
|
|
276
299
|
export interface RadarDistanceParams {
|
|
277
300
|
origin?: Location | string;
|
|
278
301
|
destination: Location | string;
|
|
279
302
|
modes: RadarTravelMode[] | string;
|
|
280
303
|
units?: 'metric' | 'imperial';
|
|
281
|
-
geometry?:
|
|
282
|
-
geometryPoints?:
|
|
304
|
+
geometry?: RadarDistanceGeometryType;
|
|
305
|
+
geometryPoints?: number;
|
|
283
306
|
avoid?: RadarAvoidOption[] | string;
|
|
284
307
|
}
|
|
285
308
|
export interface RadarRouteDistance {
|
|
@@ -405,17 +428,12 @@ export interface RadarPolygonOptions {
|
|
|
405
428
|
'border-opacity'?: number;
|
|
406
429
|
};
|
|
407
430
|
}
|
|
408
|
-
export interface RadarAutocompleteUIOptions {
|
|
431
|
+
export interface RadarAutocompleteUIOptions extends Omit<RadarAutocompleteParams, 'query'> {
|
|
409
432
|
container: string | HTMLElement;
|
|
410
|
-
near?: string | Location;
|
|
411
433
|
debounceMS?: number;
|
|
434
|
+
/** @deprecated use minCharacters instead */
|
|
412
435
|
threshold?: number;
|
|
413
436
|
minCharacters?: number;
|
|
414
|
-
limit?: number;
|
|
415
|
-
layers?: RadarGeocodeLayer[];
|
|
416
|
-
countryCode?: string;
|
|
417
|
-
expandUnits?: boolean;
|
|
418
|
-
mailable?: boolean;
|
|
419
437
|
placeholder?: string;
|
|
420
438
|
onSelection?: (selection: any) => void;
|
|
421
439
|
onRequest?: (params: RadarAutocompleteParams) => void;
|
|
@@ -430,7 +448,6 @@ export interface RadarAutocompleteUIOptions {
|
|
|
430
448
|
hideResultsOnBlur?: boolean;
|
|
431
449
|
}
|
|
432
450
|
export interface RadarAutocompleteConfig extends RadarAutocompleteUIOptions {
|
|
433
|
-
container: string | HTMLElement;
|
|
434
451
|
debounceMS: number;
|
|
435
452
|
threshold: number;
|
|
436
453
|
minCharacters: number;
|
package/dist/ui/RadarMap.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import type { RadarMapOptions, RadarLineOptions, RadarPolylineOptions, RadarPoly
|
|
|
7
7
|
declare class RadarMap extends maplibregl.Map {
|
|
8
8
|
_markers: RadarMarker[];
|
|
9
9
|
_features: RadarMapFeature[];
|
|
10
|
-
_defaultMarker?: string;
|
|
11
10
|
constructor(radarMapOptions: RadarMapOptions);
|
|
12
11
|
addMarker(marker: RadarMarker): void;
|
|
13
12
|
removeMarker(marker: RadarMarker): void;
|
package/dist/ui/RadarMarker.d.ts
CHANGED
|
@@ -2,10 +2,8 @@ import maplibregl from 'maplibre-gl';
|
|
|
2
2
|
import type RadarMap from './RadarMap';
|
|
3
3
|
import type { RadarMarkerOptions } from '../types';
|
|
4
4
|
declare class RadarMarker extends maplibregl.Marker {
|
|
5
|
-
_options: RadarMarkerOptions;
|
|
6
5
|
_map: RadarMap;
|
|
7
6
|
constructor(markerOptions: RadarMarkerOptions);
|
|
8
|
-
getCustomImage(markerOptions: RadarMarkerOptions): void;
|
|
9
7
|
addTo(map: RadarMap): this;
|
|
10
8
|
remove(): this;
|
|
11
9
|
}
|
|
@@ -28,10 +28,12 @@ declare class AutocompleteUI {
|
|
|
28
28
|
setPlaceholder(placeholder: string): this;
|
|
29
29
|
setDisabled(disabled: boolean): this;
|
|
30
30
|
setResponsive(responsive: boolean): this;
|
|
31
|
-
setWidth(width: number | string): this;
|
|
32
|
-
setMaxHeight(height: number | string): this;
|
|
31
|
+
setWidth(width: number | string | null): this;
|
|
32
|
+
setMaxHeight(height: number | string | null): this;
|
|
33
33
|
setMinCharacters(minCharacters: number): this;
|
|
34
34
|
setLimit(limit: number): this;
|
|
35
|
+
setLang(lang: string | null): this;
|
|
36
|
+
setPostalCode(postalCode: string | null): this;
|
|
35
37
|
setShowMarkers(showMarkers: boolean): this;
|
|
36
38
|
setMarkerColor(color: string): this;
|
|
37
39
|
setHideResultsOnBlur(hideResultsOnBlur: boolean): this;
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "4.5.0
|
|
1
|
+
declare const _default: "4.5.0";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "radar-sdk-js",
|
|
3
|
-
"version": "4.5.0
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "Web Javascript SDK for Radar, location infrastructure for mobile and web apps.",
|
|
5
5
|
"homepage": "https://radar.com",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
"test": "jest --collect-coverage --runInBand",
|
|
24
24
|
"test:watch": "jest --watch",
|
|
25
25
|
"demo": "npm run build && node ./demo/server.cjs",
|
|
26
|
-
"compile-site": "node ./scripts/compile-site.cjs"
|
|
26
|
+
"compile-site": "node ./scripts/compile-site.cjs",
|
|
27
|
+
"spell-check": "cspell **/*.md -c cspell.json",
|
|
28
|
+
"prepare": "husky"
|
|
27
29
|
},
|
|
28
30
|
"author": "",
|
|
29
31
|
"license": "ISC",
|
|
@@ -33,11 +35,14 @@
|
|
|
33
35
|
"@rollup/plugin-node-resolve": "^15.1.0",
|
|
34
36
|
"@rollup/plugin-terser": "^0.4.3",
|
|
35
37
|
"@types/jest": "^29.5.1",
|
|
38
|
+
"cspell": "^8.15.3",
|
|
36
39
|
"express": "^4.18.2",
|
|
37
40
|
"express-handlebars": "^7.0.7",
|
|
38
41
|
"handlebars": "^4.7.7",
|
|
42
|
+
"husky": "^9.1.6",
|
|
39
43
|
"jest": "^29.5.0",
|
|
40
44
|
"jest-environment-jsdom": "^29.5.0",
|
|
45
|
+
"lint-staged": "^15.2.10",
|
|
41
46
|
"maplibre-gl": "^4.3.2",
|
|
42
47
|
"mock-xmlhttprequest": "^8.2.0",
|
|
43
48
|
"nodemon": "^2.0.22",
|
|
@@ -52,6 +57,11 @@
|
|
|
52
57
|
"@types/geojson": "^7946.0.10"
|
|
53
58
|
},
|
|
54
59
|
"peerDependencies": {
|
|
55
|
-
"maplibre-gl": "^2.4.0 || ^3.0.0 || ^4.0.0"
|
|
60
|
+
"maplibre-gl": "^2.4.0 || ^3.0.0 || ^4.0.0 || ^5.0.1"
|
|
61
|
+
},
|
|
62
|
+
"husky": {
|
|
63
|
+
"hooks": {
|
|
64
|
+
"pre-commit": "lint-staged"
|
|
65
|
+
}
|
|
56
66
|
}
|
|
57
67
|
}
|
package/src/api/geocoding.ts
CHANGED
|
@@ -13,7 +13,7 @@ class Geocoding {
|
|
|
13
13
|
static async forwardGeocode(params: RadarForwardGeocodeParams): Promise<RadarGeocodeResponse> {
|
|
14
14
|
const options = Config.get();
|
|
15
15
|
|
|
16
|
-
const { query, layers, country } = params;
|
|
16
|
+
const { query, layers, country, lang } = params;
|
|
17
17
|
|
|
18
18
|
const response: any = await Http.request({
|
|
19
19
|
method: 'GET',
|
|
@@ -22,6 +22,7 @@ class Geocoding {
|
|
|
22
22
|
query,
|
|
23
23
|
layers,
|
|
24
24
|
country,
|
|
25
|
+
lang,
|
|
25
26
|
},
|
|
26
27
|
});
|
|
27
28
|
|
package/src/api/search.ts
CHANGED
|
@@ -23,6 +23,8 @@ class SearchAPI {
|
|
|
23
23
|
countryCode,
|
|
24
24
|
expandUnits,
|
|
25
25
|
mailable,
|
|
26
|
+
lang,
|
|
27
|
+
postalCode,
|
|
26
28
|
} = params;
|
|
27
29
|
|
|
28
30
|
// near can be provided as a string or Location object
|
|
@@ -44,6 +46,8 @@ class SearchAPI {
|
|
|
44
46
|
countryCode,
|
|
45
47
|
expandUnits,
|
|
46
48
|
mailable,
|
|
49
|
+
lang,
|
|
50
|
+
postalCode,
|
|
47
51
|
},
|
|
48
52
|
requestId,
|
|
49
53
|
});
|
package/src/api/track.ts
CHANGED
|
@@ -89,7 +89,6 @@ class TrackAPI {
|
|
|
89
89
|
let response: any;
|
|
90
90
|
if (fraud) {
|
|
91
91
|
const host = 'https://api-verified.radar.io';
|
|
92
|
-
const pingHost = 'ping.radar-verify.com';
|
|
93
92
|
|
|
94
93
|
const lang = navigator.language;
|
|
95
94
|
const langs = navigator.languages;
|
|
@@ -109,29 +108,9 @@ class TrackAPI {
|
|
|
109
108
|
},
|
|
110
109
|
});
|
|
111
110
|
|
|
112
|
-
let sclVal = -1;
|
|
113
|
-
let cslVal = -1;
|
|
114
|
-
try {
|
|
115
|
-
const [sclRes, csl] = await Promise.all([
|
|
116
|
-
Http.request({
|
|
117
|
-
host: `https://${pingHost}`,
|
|
118
|
-
method: 'GET',
|
|
119
|
-
path: 'ping',
|
|
120
|
-
}),
|
|
121
|
-
ping(`wss://${pingHost}`),
|
|
122
|
-
]);
|
|
123
|
-
const { scl }: any = sclRes;
|
|
124
|
-
sclVal = scl;
|
|
125
|
-
cslVal = csl;
|
|
126
|
-
} catch (err) {
|
|
127
|
-
// do nothing, send scl = -1 and csl = -1
|
|
128
|
-
}
|
|
129
|
-
|
|
130
111
|
const payload = {
|
|
131
112
|
payload: JSON.stringify({
|
|
132
113
|
...body,
|
|
133
|
-
scl: sclVal,
|
|
134
|
-
csl: cslVal,
|
|
135
114
|
lang,
|
|
136
115
|
langs,
|
|
137
116
|
}),
|
|
@@ -151,17 +130,6 @@ class TrackAPI {
|
|
|
151
130
|
},
|
|
152
131
|
});
|
|
153
132
|
|
|
154
|
-
if (options.debug && response && response.user) {
|
|
155
|
-
if (!response.user.metadata) {
|
|
156
|
-
response.user.metadata = {};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
response.user.metadata['radar:debug'] = {
|
|
160
|
-
sclVal,
|
|
161
|
-
cslVal,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
133
|
let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response;
|
|
166
134
|
const location = { latitude, longitude, accuracy };
|
|
167
135
|
if (expiresAt) {
|
package/src/api/verify.ts
CHANGED
|
@@ -5,8 +5,9 @@ import Http from '../http';
|
|
|
5
5
|
import Logger from '../logger';
|
|
6
6
|
import Session from '../session';
|
|
7
7
|
import Storage from '../storage';
|
|
8
|
+
import TrackAPI from './track';
|
|
8
9
|
|
|
9
|
-
import type { RadarStartTrackingVerifiedParams,
|
|
10
|
+
import type { RadarStartTrackingVerifiedParams, RadarTrackVerifiedParams, RadarTrackVerifiedResponse } from '../types';
|
|
10
11
|
|
|
11
12
|
let tokenTimeoutId: any | null = null;
|
|
12
13
|
let tokenCallback: ((token: RadarTrackVerifiedResponse) => void) | null = null;
|
|
@@ -16,13 +17,15 @@ let expectedCountryCode: string | null = null;
|
|
|
16
17
|
let expectedStateCode: string | null = null;
|
|
17
18
|
|
|
18
19
|
class VerifyAPI {
|
|
19
|
-
static async trackVerified(params:
|
|
20
|
+
static async trackVerified(params: RadarTrackVerifiedParams, encrypted: Boolean = false) {
|
|
20
21
|
const options = Config.get();
|
|
21
22
|
|
|
23
|
+
const { skipVerifyApp } = params;
|
|
24
|
+
|
|
22
25
|
// user indentification fields
|
|
23
26
|
const userId = params.userId || Storage.getItem(Storage.USER_ID);
|
|
24
|
-
const deviceId =
|
|
25
|
-
const installId =
|
|
27
|
+
const deviceId = Device.getDeviceId();
|
|
28
|
+
const installId = Device.getInstallId();
|
|
26
29
|
const sessionId = Session.getSessionId();
|
|
27
30
|
const description = params.description || Storage.getItem(Storage.DESCRIPTION);
|
|
28
31
|
|
|
@@ -36,59 +39,69 @@ class VerifyAPI {
|
|
|
36
39
|
// other info
|
|
37
40
|
const metadata = params.metadata || Storage.getJSON(Storage.METADATA);
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
host: apple ? 'https://radar-verify.com:52516' : 'http://localhost:52516',
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response;
|
|
66
|
-
let location;
|
|
67
|
-
if (user && user.location && user.location.coordinates && user.locationAccuracy) {
|
|
68
|
-
location = {
|
|
69
|
-
latitude: user.location.coordinates[1],
|
|
70
|
-
longitude: user.location.coordinates[0],
|
|
71
|
-
accuracy: user.locationAccuracy,
|
|
42
|
+
let trackRes: RadarTrackVerifiedResponse;
|
|
43
|
+
if (skipVerifyApp) {
|
|
44
|
+
trackRes = await TrackAPI.trackOnce({
|
|
45
|
+
userId: userId ?? undefined,
|
|
46
|
+
description: description ?? undefined,
|
|
47
|
+
metadata: metadata,
|
|
48
|
+
fraud: true,
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
const body = {
|
|
52
|
+
...params,
|
|
53
|
+
description,
|
|
54
|
+
deviceId,
|
|
55
|
+
foreground: true,
|
|
56
|
+
installId,
|
|
57
|
+
sessionId,
|
|
58
|
+
metadata,
|
|
59
|
+
sdkVersion: SDK_VERSION,
|
|
60
|
+
stopped: true,
|
|
61
|
+
userId,
|
|
62
|
+
encrypted,
|
|
63
|
+
expectedCountryCode,
|
|
64
|
+
expectedStateCode,
|
|
72
65
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
expiresIn,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
66
|
+
|
|
67
|
+
let userAgent = navigator.userAgent;
|
|
68
|
+
const apple = userAgent && (userAgent.toLowerCase().includes('mac') || userAgent.toLowerCase().includes('iphone') || userAgent.toLowerCase().includes('ipod') || userAgent.toLowerCase().includes('ipad'));
|
|
69
|
+
|
|
70
|
+
const response: any = await Http.request({
|
|
71
|
+
method: 'GET',
|
|
72
|
+
path: 'verify',
|
|
73
|
+
data: body,
|
|
74
|
+
host: apple ? 'https://radar-verify.com:52516' : 'http://localhost:52516',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response;
|
|
78
|
+
let location;
|
|
79
|
+
if (user && user.location && user.location.coordinates && user.locationAccuracy) {
|
|
80
|
+
location = {
|
|
81
|
+
latitude: user.location.coordinates[1],
|
|
82
|
+
longitude: user.location.coordinates[0],
|
|
83
|
+
accuracy: user.locationAccuracy,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (expiresAt) {
|
|
87
|
+
expiresAt = new Date(expiresAt);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
trackRes = {
|
|
91
|
+
user,
|
|
92
|
+
events,
|
|
93
|
+
location,
|
|
94
|
+
token,
|
|
95
|
+
expiresAt,
|
|
96
|
+
expiresIn,
|
|
97
|
+
passed,
|
|
98
|
+
failureReasons,
|
|
99
|
+
_id,
|
|
100
|
+
} as RadarTrackVerifiedResponse;
|
|
101
|
+
|
|
102
|
+
if (options.debug) {
|
|
103
|
+
trackRes.response = response;
|
|
104
|
+
}
|
|
92
105
|
}
|
|
93
106
|
|
|
94
107
|
lastToken = trackRes;
|
|
@@ -101,26 +114,23 @@ class VerifyAPI {
|
|
|
101
114
|
return trackRes;
|
|
102
115
|
}
|
|
103
116
|
|
|
104
|
-
static
|
|
105
|
-
const
|
|
106
|
-
const trackRes = await this.trackVerified({});
|
|
107
|
-
|
|
117
|
+
static startTrackingVerified(params: RadarStartTrackingVerifiedParams) {
|
|
118
|
+
const scheduleNextIntervalWithLastToken = async () => {
|
|
108
119
|
const { interval } = params;
|
|
109
120
|
|
|
110
|
-
let expiresIn = 0;
|
|
111
121
|
let minInterval = interval;
|
|
112
122
|
|
|
113
|
-
if (
|
|
114
|
-
|
|
123
|
+
if (lastToken) {
|
|
124
|
+
const lastTokenElapsed = (performance.now() - lastTokenNow) / 1000;
|
|
125
|
+
|
|
126
|
+
const expiresIn = (lastToken.expiresIn || 0);
|
|
115
127
|
|
|
116
128
|
// if expiresIn is shorter than interval, override interval
|
|
117
|
-
|
|
129
|
+
// re-request early to maximize the likelihood that a cached token is available
|
|
130
|
+
minInterval = Math.min(expiresIn - lastTokenElapsed, interval);
|
|
118
131
|
}
|
|
119
132
|
|
|
120
|
-
|
|
121
|
-
if (minInterval > 20) {
|
|
122
|
-
minInterval = minInterval - 10;
|
|
123
|
-
}
|
|
133
|
+
minInterval = minInterval - 10;
|
|
124
134
|
|
|
125
135
|
// min interval is 10 seconds
|
|
126
136
|
if (minInterval < 10) {
|
|
@@ -132,9 +142,23 @@ class VerifyAPI {
|
|
|
132
142
|
}
|
|
133
143
|
|
|
134
144
|
tokenTimeoutId = setTimeout(doTrackVerified, minInterval * 1000);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const doTrackVerified = async () => {
|
|
148
|
+
try {
|
|
149
|
+
await this.trackVerified(params);
|
|
150
|
+
} catch (err: any) {
|
|
151
|
+
Logger.error(`trackVerified error: ${err.message}`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
scheduleNextIntervalWithLastToken();
|
|
135
155
|
};
|
|
136
156
|
|
|
137
|
-
|
|
157
|
+
if (this.isLastTokenValid()) {
|
|
158
|
+
scheduleNextIntervalWithLastToken();
|
|
159
|
+
} else {
|
|
160
|
+
doTrackVerified();
|
|
161
|
+
}
|
|
138
162
|
}
|
|
139
163
|
|
|
140
164
|
static stopTrackingVerified() {
|
|
@@ -143,16 +167,26 @@ class VerifyAPI {
|
|
|
143
167
|
}
|
|
144
168
|
}
|
|
145
169
|
|
|
146
|
-
static async getVerifiedLocationToken() {
|
|
147
|
-
|
|
170
|
+
static async getVerifiedLocationToken(params: RadarTrackVerifiedParams) {
|
|
171
|
+
if (this.isLastTokenValid()) {
|
|
172
|
+
return lastToken;
|
|
173
|
+
}
|
|
148
174
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
175
|
+
return this.trackVerified(params);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
static clearVerifiedLocationToken() {
|
|
179
|
+
lastToken = null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
static isLastTokenValid() {
|
|
183
|
+
if (!lastToken) {
|
|
184
|
+
return false;
|
|
153
185
|
}
|
|
154
186
|
|
|
155
|
-
|
|
187
|
+
const lastTokenElapsed = (performance.now() - lastTokenNow) / 1000;
|
|
188
|
+
|
|
189
|
+
return lastToken.passed && lastTokenElapsed < (lastToken.expiresIn || 0);
|
|
156
190
|
}
|
|
157
191
|
|
|
158
192
|
static setExpectedJurisdiction(countryCode?: string, stateCode?: string) {
|
package/src/api.ts
CHANGED
|
@@ -31,6 +31,7 @@ import type {
|
|
|
31
31
|
RadarSearchPlacesParams,
|
|
32
32
|
RadarStartTrackingVerifiedParams,
|
|
33
33
|
RadarTrackParams,
|
|
34
|
+
RadarTrackVerifiedParams,
|
|
34
35
|
RadarTrackVerifiedResponse,
|
|
35
36
|
RadarTripOptions,
|
|
36
37
|
RadarValidateAddressParams,
|
|
@@ -75,7 +76,7 @@ class Radar {
|
|
|
75
76
|
|
|
76
77
|
Logger.info(`initialized with ${live ? 'live' : 'test'} publishableKey.`);
|
|
77
78
|
if (options.debug) {
|
|
78
|
-
Logger.
|
|
79
|
+
Logger.debug('using options', options);
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
// NOTE(jasonl): this allows us to run jest tests
|
|
@@ -129,20 +130,24 @@ class Radar {
|
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
132
|
|
|
132
|
-
public static trackVerified(params:
|
|
133
|
+
public static trackVerified(params: RadarTrackVerifiedParams = {}) {
|
|
133
134
|
return VerifyAPI.trackVerified(params);
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
public static startTrackingVerified(params: RadarStartTrackingVerifiedParams) {
|
|
137
|
-
|
|
138
|
+
VerifyAPI.startTrackingVerified(params);
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
public static stopTrackingVerified() {
|
|
141
|
-
|
|
142
|
+
VerifyAPI.stopTrackingVerified();
|
|
142
143
|
}
|
|
143
144
|
|
|
144
|
-
public static getVerifiedLocationToken() {
|
|
145
|
-
return VerifyAPI.getVerifiedLocationToken();
|
|
145
|
+
public static getVerifiedLocationToken(params: RadarTrackVerifiedParams = {}) {
|
|
146
|
+
return VerifyAPI.getVerifiedLocationToken(params);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public static clearVerifiedLocationToken() {
|
|
150
|
+
VerifyAPI.clearVerifiedLocationToken();
|
|
146
151
|
}
|
|
147
152
|
|
|
148
153
|
public static setExpectedJurisdiction(countryCode?: string, stateCode?: string) {
|
package/src/http.ts
CHANGED
|
@@ -189,12 +189,16 @@ class Http {
|
|
|
189
189
|
if (host && (host === 'http://localhost:52516' || host === 'https://radar-verify.com:52516')) {
|
|
190
190
|
reject(new RadarVerifyAppError());
|
|
191
191
|
} else {
|
|
192
|
-
reject(new
|
|
192
|
+
reject(new RadarNetworkError());
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
xhr.ontimeout = function () {
|
|
197
|
-
|
|
197
|
+
if (host && (host === 'http://localhost:52516' || host === 'https://radar-verify.com:52516')) {
|
|
198
|
+
reject(new RadarVerifyAppError());
|
|
199
|
+
} else {
|
|
200
|
+
reject(new RadarNetworkError());
|
|
201
|
+
}
|
|
198
202
|
}
|
|
199
203
|
|
|
200
204
|
xhr.send(JSON.stringify(body));
|
package/src/logger.ts
CHANGED
|
@@ -27,9 +27,9 @@ const getLevel = (): number => {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
class Logger {
|
|
30
|
-
public static debug(message: string) {
|
|
30
|
+
public static debug(message: string, options?: any) {
|
|
31
31
|
if (getLevel() === LOG_LEVELS.debug) {
|
|
32
|
-
console.log(`Radar SDK (debug): ${message.trim()}
|
|
32
|
+
console.log(`Radar SDK (debug): ${message.trim()}`, options);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|