radar-sdk-js 4.3.5-beta.0 → 4.3.5
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 +7 -7
- package/dist/api/verify.d.ts +6 -1
- package/dist/index.d.ts +7 -2
- package/dist/radar.js +94 -18
- package/dist/radar.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/api/track.ts +3 -5
- package/src/api/verify.ts +83 -6
- package/src/index.ts +28 -4
- package/src/types.ts +7 -1
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ Radar.initialize('prj_test_pk_...', { /* options */ });
|
|
|
56
56
|
|
|
57
57
|
Add the following script in your `html` file
|
|
58
58
|
```html
|
|
59
|
-
<script src="https://js.radar.com/v4.3.5
|
|
59
|
+
<script src="https://js.radar.com/v4.3.5/radar.min.js"></script>
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
Then initialize the Radar SDK
|
|
@@ -73,8 +73,8 @@ To create a map, first initialize the Radar SDK with your publishable key. Then
|
|
|
73
73
|
```html
|
|
74
74
|
<html>
|
|
75
75
|
<head>
|
|
76
|
-
<link href="https://js.radar.com/v4.3.5
|
|
77
|
-
<script src="https://js.radar.com/v4.3.5
|
|
76
|
+
<link href="https://js.radar.com/v4.3.5/radar.css" rel="stylesheet">
|
|
77
|
+
<script src="https://js.radar.com/v4.3.5/radar.min.js"></script>
|
|
78
78
|
</head>
|
|
79
79
|
|
|
80
80
|
<body>
|
|
@@ -98,8 +98,8 @@ To create an autocomplete input, first initialize the Radar SDK with your publis
|
|
|
98
98
|
```html
|
|
99
99
|
<html>
|
|
100
100
|
<head>
|
|
101
|
-
<link href="https://js.radar.com/v4.3.5
|
|
102
|
-
<script src="https://js.radar.com/v4.3.5
|
|
101
|
+
<link href="https://js.radar.com/v4.3.5/radar.css" rel="stylesheet">
|
|
102
|
+
<script src="https://js.radar.com/v4.3.5/radar.min.js"></script>
|
|
103
103
|
</head>
|
|
104
104
|
|
|
105
105
|
<body>
|
|
@@ -130,8 +130,8 @@ To power [geofencing](https://radar.com/documentation/geofencing/overview) exper
|
|
|
130
130
|
```html
|
|
131
131
|
<html>
|
|
132
132
|
<head>
|
|
133
|
-
<link href="https://js.radar.com/v4.3.5
|
|
134
|
-
<script src="https://js.radar.com/v4.3.5
|
|
133
|
+
<link href="https://js.radar.com/v4.3.5/radar.css" rel="stylesheet">
|
|
134
|
+
<script src="https://js.radar.com/v4.3.5/radar.min.js"></script>
|
|
135
135
|
</head>
|
|
136
136
|
|
|
137
137
|
<body>
|
package/dist/api/verify.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import type { RadarTrackParams, RadarTrackVerifiedResponse } from '../types';
|
|
1
|
+
import type { RadarStartTrackingVerifiedParams, RadarTrackParams, RadarTrackVerifiedResponse } from '../types';
|
|
2
2
|
declare class VerifyAPI {
|
|
3
3
|
static trackVerified(params: RadarTrackParams, encrypted?: Boolean): Promise<RadarTrackVerifiedResponse>;
|
|
4
|
+
static startTrackingVerified(params: RadarStartTrackingVerifiedParams): Promise<void>;
|
|
5
|
+
static stopTrackingVerified(): void;
|
|
6
|
+
static getVerifiedLocationToken(): Promise<RadarTrackVerifiedResponse>;
|
|
7
|
+
static setExpectedJurisdiction(countryCode?: string, stateCode?: string): void;
|
|
8
|
+
static onTokenUpdated(callback: (token: RadarTrackVerifiedResponse) => void): void;
|
|
4
9
|
}
|
|
5
10
|
export default VerifyAPI;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import MapUI from './ui/map';
|
|
2
2
|
import AutocompleteUI from './ui/autocomplete';
|
|
3
|
-
import type { Location, RadarAutocompleteParams, RadarConversionParams, RadarDistanceParams, RadarForwardGeocodeParams, RadarMatrixParams, RadarMetadata, RadarOptions, RadarReverseGeocodeParams, RadarSearchGeofencesParams, RadarSearchPlacesParams, RadarTrackParams, RadarTripOptions, RadarValidateAddressParams } from './types';
|
|
3
|
+
import type { Location, RadarAutocompleteParams, RadarConversionParams, RadarDistanceParams, RadarForwardGeocodeParams, RadarMatrixParams, RadarMetadata, RadarOptions, RadarReverseGeocodeParams, RadarSearchGeofencesParams, RadarSearchPlacesParams, RadarStartTrackingVerifiedParams, RadarTrackParams, RadarTrackVerifiedResponse, RadarTripOptions, RadarValidateAddressParams } from './types';
|
|
4
4
|
import 'maplibre-gl/dist/maplibre-gl.css';
|
|
5
5
|
import '../styles/radar.css';
|
|
6
6
|
declare class Radar {
|
|
@@ -18,7 +18,11 @@ declare class Radar {
|
|
|
18
18
|
static setMetadata(metadata?: RadarMetadata): void;
|
|
19
19
|
static getLocation(): Promise<import("./types").NavigatorPosition>;
|
|
20
20
|
static trackOnce(params?: RadarTrackParams): Promise<import("./types").RadarTrackResponse>;
|
|
21
|
-
static trackVerified(params?: RadarTrackParams): Promise<
|
|
21
|
+
static trackVerified(params?: RadarTrackParams): Promise<RadarTrackVerifiedResponse>;
|
|
22
|
+
static startTrackingVerified(params: RadarStartTrackingVerifiedParams): Promise<void>;
|
|
23
|
+
static stopTrackingVerified(): void;
|
|
24
|
+
static getVerifiedLocationToken(): Promise<RadarTrackVerifiedResponse>;
|
|
25
|
+
static setExpectedJurisdiction(countryCode?: string, stateCode?: string): void;
|
|
22
26
|
static getContext(params: Location): Promise<import("./types").RadarContextResponse>;
|
|
23
27
|
static setTripOptions(tripOptions?: RadarTripOptions): void;
|
|
24
28
|
static clearTripOptions(): void;
|
|
@@ -28,6 +32,7 @@ declare class Radar {
|
|
|
28
32
|
static completeTrip(): Promise<import("./types").RadarTripResponse>;
|
|
29
33
|
static cancelTrip(): Promise<import("./types").RadarTripResponse>;
|
|
30
34
|
static logConversion(params: RadarConversionParams): Promise<import("./types").RadarConversionResponse>;
|
|
35
|
+
static onTokenUpdated(callback: (token: RadarTrackVerifiedResponse) => void): void;
|
|
31
36
|
static forwardGeocode(params: RadarForwardGeocodeParams): Promise<import("./types").RadarGeocodeResponse>;
|
|
32
37
|
static reverseGeocode(params: RadarReverseGeocodeParams): Promise<import("./types").RadarGeocodeResponse>;
|
|
33
38
|
static ipGeocode(): Promise<import("./types").RadarIPGeocodeResponse>;
|
package/dist/radar.js
CHANGED
|
@@ -405,7 +405,7 @@ class Navigator {
|
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
-
var SDK_VERSION = '4.3.5
|
|
408
|
+
var SDK_VERSION = '4.3.5';
|
|
409
409
|
|
|
410
410
|
const inFlightRequests = new Map();
|
|
411
411
|
class Http {
|
|
@@ -1212,7 +1212,6 @@ const ping = (host) => {
|
|
|
1212
1212
|
|
|
1213
1213
|
class TrackAPI {
|
|
1214
1214
|
static trackOnce(params) {
|
|
1215
|
-
var _a, _b, _c;
|
|
1216
1215
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1217
1216
|
const options = Config.get();
|
|
1218
1217
|
let { latitude, longitude, accuracy, desiredAccuracy, fraud } = params;
|
|
@@ -1334,14 +1333,10 @@ class TrackAPI {
|
|
|
1334
1333
|
cslVal,
|
|
1335
1334
|
};
|
|
1336
1335
|
}
|
|
1337
|
-
let { user, events, token, expiresAt } = response;
|
|
1336
|
+
let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response;
|
|
1338
1337
|
const location = { latitude, longitude, accuracy };
|
|
1339
|
-
let passed;
|
|
1340
|
-
let expiresIn;
|
|
1341
1338
|
if (expiresAt) {
|
|
1342
1339
|
expiresAt = new Date(expiresAt);
|
|
1343
|
-
passed = ((_a = user === null || user === void 0 ? void 0 : user.fraud) === null || _a === void 0 ? void 0 : _a.passed) && ((_b = user === null || user === void 0 ? void 0 : user.country) === null || _b === void 0 ? void 0 : _b.passed) && ((_c = user === null || user === void 0 ? void 0 : user.state) === null || _c === void 0 ? void 0 : _c.passed);
|
|
1344
|
-
expiresIn = (expiresAt.getTime() - Date.now()) / 1000;
|
|
1345
1340
|
}
|
|
1346
1341
|
const trackRes = {
|
|
1347
1342
|
user,
|
|
@@ -1351,6 +1346,8 @@ class TrackAPI {
|
|
|
1351
1346
|
expiresAt,
|
|
1352
1347
|
expiresIn,
|
|
1353
1348
|
passed,
|
|
1349
|
+
failureReasons,
|
|
1350
|
+
_id,
|
|
1354
1351
|
};
|
|
1355
1352
|
if (options.debug) {
|
|
1356
1353
|
trackRes.response = response;
|
|
@@ -1377,9 +1374,14 @@ class TrackAPI {
|
|
|
1377
1374
|
}
|
|
1378
1375
|
}
|
|
1379
1376
|
|
|
1377
|
+
let tokenTimeoutId = null;
|
|
1378
|
+
let tokenCallback = null;
|
|
1379
|
+
let lastToken = null;
|
|
1380
|
+
let lastTokenNow = 0;
|
|
1381
|
+
let expectedCountryCode = null;
|
|
1382
|
+
let expectedStateCode = null;
|
|
1380
1383
|
class VerifyAPI {
|
|
1381
1384
|
static trackVerified(params, encrypted = false) {
|
|
1382
|
-
var _a, _b, _c;
|
|
1383
1385
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1384
1386
|
const options = Config.get();
|
|
1385
1387
|
// user indentification fields
|
|
@@ -1401,7 +1403,9 @@ class VerifyAPI {
|
|
|
1401
1403
|
deviceId, foreground: true, installId,
|
|
1402
1404
|
sessionId,
|
|
1403
1405
|
metadata, sdkVersion: SDK_VERSION, stopped: true, userId,
|
|
1404
|
-
encrypted
|
|
1406
|
+
encrypted,
|
|
1407
|
+
expectedCountryCode,
|
|
1408
|
+
expectedStateCode });
|
|
1405
1409
|
let userAgent = navigator.userAgent;
|
|
1406
1410
|
const apple = userAgent && (userAgent.toLowerCase().includes('mac') || userAgent.toLowerCase().includes('iphone') || userAgent.toLowerCase().includes('ipod') || userAgent.toLowerCase().includes('ipad'));
|
|
1407
1411
|
const response = yield Http.request({
|
|
@@ -1410,7 +1414,7 @@ class VerifyAPI {
|
|
|
1410
1414
|
data: body,
|
|
1411
1415
|
host: apple ? 'https://radar-verify.com:52516' : 'http://localhost:52516',
|
|
1412
1416
|
});
|
|
1413
|
-
let { user, events, token, expiresAt } = response;
|
|
1417
|
+
let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response;
|
|
1414
1418
|
let location;
|
|
1415
1419
|
if (user && user.location && user.location.coordinates && user.locationAccuracy) {
|
|
1416
1420
|
location = {
|
|
@@ -1419,12 +1423,8 @@ class VerifyAPI {
|
|
|
1419
1423
|
accuracy: user.locationAccuracy,
|
|
1420
1424
|
};
|
|
1421
1425
|
}
|
|
1422
|
-
let passed;
|
|
1423
|
-
let expiresIn;
|
|
1424
1426
|
if (expiresAt) {
|
|
1425
1427
|
expiresAt = new Date(expiresAt);
|
|
1426
|
-
passed = ((_a = user === null || user === void 0 ? void 0 : user.fraud) === null || _a === void 0 ? void 0 : _a.passed) && ((_b = user === null || user === void 0 ? void 0 : user.country) === null || _b === void 0 ? void 0 : _b.passed) && ((_c = user === null || user === void 0 ? void 0 : user.state) === null || _c === void 0 ? void 0 : _c.passed);
|
|
1427
|
-
expiresIn = (expiresAt.getTime() - Date.now()) / 1000;
|
|
1428
1428
|
}
|
|
1429
1429
|
const trackRes = {
|
|
1430
1430
|
user,
|
|
@@ -1434,13 +1434,71 @@ class VerifyAPI {
|
|
|
1434
1434
|
expiresAt,
|
|
1435
1435
|
expiresIn,
|
|
1436
1436
|
passed,
|
|
1437
|
+
failureReasons,
|
|
1438
|
+
_id,
|
|
1437
1439
|
};
|
|
1438
1440
|
if (options.debug) {
|
|
1439
1441
|
trackRes.response = response;
|
|
1440
1442
|
}
|
|
1443
|
+
lastToken = trackRes;
|
|
1444
|
+
lastTokenNow = performance.now();
|
|
1445
|
+
if (tokenCallback) {
|
|
1446
|
+
tokenCallback(trackRes);
|
|
1447
|
+
}
|
|
1441
1448
|
return trackRes;
|
|
1442
1449
|
});
|
|
1443
1450
|
}
|
|
1451
|
+
static startTrackingVerified(params) {
|
|
1452
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1453
|
+
const doTrackVerified = () => __awaiter(this, void 0, void 0, function* () {
|
|
1454
|
+
const trackRes = yield this.trackVerified({});
|
|
1455
|
+
const { interval } = params;
|
|
1456
|
+
let expiresIn = 0;
|
|
1457
|
+
let minInterval = interval;
|
|
1458
|
+
if (trackRes) {
|
|
1459
|
+
expiresIn = (trackRes.expiresIn || expiresIn);
|
|
1460
|
+
// if expiresIn is shorter than interval, override interval
|
|
1461
|
+
minInterval = Math.min(expiresIn, interval);
|
|
1462
|
+
}
|
|
1463
|
+
// re-request early to maximize the likelihood that a cached token is available
|
|
1464
|
+
if (minInterval > 20) {
|
|
1465
|
+
minInterval = minInterval - 10;
|
|
1466
|
+
}
|
|
1467
|
+
// min interval is 10 seconds
|
|
1468
|
+
if (minInterval < 10) {
|
|
1469
|
+
minInterval = 10;
|
|
1470
|
+
}
|
|
1471
|
+
if (tokenTimeoutId) {
|
|
1472
|
+
clearTimeout(tokenTimeoutId);
|
|
1473
|
+
}
|
|
1474
|
+
tokenTimeoutId = setTimeout(doTrackVerified, minInterval * 1000);
|
|
1475
|
+
});
|
|
1476
|
+
doTrackVerified();
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
static stopTrackingVerified() {
|
|
1480
|
+
if (tokenTimeoutId) {
|
|
1481
|
+
clearTimeout(tokenTimeoutId);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
static getVerifiedLocationToken() {
|
|
1485
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1486
|
+
const lastTokenElapsed = (performance.now() - lastTokenNow) / 1000;
|
|
1487
|
+
if (lastToken) {
|
|
1488
|
+
if (lastTokenElapsed < (lastToken.expiresIn || 0)) {
|
|
1489
|
+
return lastToken;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
return this.trackVerified({});
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
static setExpectedJurisdiction(countryCode, stateCode) {
|
|
1496
|
+
expectedCountryCode = countryCode || null;
|
|
1497
|
+
expectedStateCode = stateCode || null;
|
|
1498
|
+
}
|
|
1499
|
+
static onTokenUpdated(callback) {
|
|
1500
|
+
tokenCallback = callback;
|
|
1501
|
+
}
|
|
1444
1502
|
}
|
|
1445
1503
|
|
|
1446
1504
|
const RADAR_LOGO_URL = 'https://api.radar.io/maps/static/images/logo.svg';
|
|
@@ -2329,7 +2387,7 @@ class Radar {
|
|
|
2329
2387
|
Config.clear();
|
|
2330
2388
|
}
|
|
2331
2389
|
///////////////////////
|
|
2332
|
-
//
|
|
2390
|
+
// Geofencing Platform
|
|
2333
2391
|
///////////////////////
|
|
2334
2392
|
static setUserId(userId) {
|
|
2335
2393
|
if (!userId) {
|
|
@@ -2366,6 +2424,18 @@ class Radar {
|
|
|
2366
2424
|
static trackVerified(params = {}) {
|
|
2367
2425
|
return VerifyAPI.trackVerified(params);
|
|
2368
2426
|
}
|
|
2427
|
+
static startTrackingVerified(params) {
|
|
2428
|
+
return VerifyAPI.startTrackingVerified(params);
|
|
2429
|
+
}
|
|
2430
|
+
static stopTrackingVerified() {
|
|
2431
|
+
return VerifyAPI.stopTrackingVerified();
|
|
2432
|
+
}
|
|
2433
|
+
static getVerifiedLocationToken() {
|
|
2434
|
+
return VerifyAPI.getVerifiedLocationToken();
|
|
2435
|
+
}
|
|
2436
|
+
static setExpectedJurisdiction(countryCode, stateCode) {
|
|
2437
|
+
VerifyAPI.setExpectedJurisdiction(countryCode, stateCode);
|
|
2438
|
+
}
|
|
2369
2439
|
static getContext(params) {
|
|
2370
2440
|
return ContextAPI.getContext(params);
|
|
2371
2441
|
}
|
|
@@ -2393,9 +2463,15 @@ class Radar {
|
|
|
2393
2463
|
static logConversion(params) {
|
|
2394
2464
|
return ConversionsAPI.logConversion(params);
|
|
2395
2465
|
}
|
|
2396
|
-
|
|
2397
|
-
//
|
|
2398
|
-
|
|
2466
|
+
///////////////////////
|
|
2467
|
+
// listeners
|
|
2468
|
+
///////////////////////
|
|
2469
|
+
static onTokenUpdated(callback) {
|
|
2470
|
+
VerifyAPI.onTokenUpdated(callback);
|
|
2471
|
+
}
|
|
2472
|
+
///////////////////////
|
|
2473
|
+
// Maps Platform
|
|
2474
|
+
///////////////////////
|
|
2399
2475
|
static forwardGeocode(params) {
|
|
2400
2476
|
return Geocoding.forwardGeocode(params);
|
|
2401
2477
|
}
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/types.d.ts
CHANGED
|
@@ -54,6 +54,9 @@ export interface RadarTrackParams {
|
|
|
54
54
|
desiredAccuracy?: 'high' | 'medium' | 'low';
|
|
55
55
|
fraud?: boolean;
|
|
56
56
|
}
|
|
57
|
+
export interface RadarStartTrackingVerifiedParams {
|
|
58
|
+
interval: number;
|
|
59
|
+
}
|
|
57
60
|
export declare enum RadarEventConfidence {
|
|
58
61
|
none = 0,
|
|
59
62
|
low = 1,
|
|
@@ -148,6 +151,8 @@ export interface RadarTrackVerifiedResponse extends RadarTrackResponse {
|
|
|
148
151
|
expiresAt?: Date;
|
|
149
152
|
expiresIn?: number;
|
|
150
153
|
passed?: boolean;
|
|
154
|
+
failureReasons?: string[];
|
|
155
|
+
_id?: string;
|
|
151
156
|
}
|
|
152
157
|
export interface RadarContextResponse extends RadarResponse {
|
|
153
158
|
location?: Location;
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "4.3.5
|
|
1
|
+
declare const _default: "4.3.5";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED
package/src/api/track.ts
CHANGED
|
@@ -162,14 +162,10 @@ class TrackAPI {
|
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
let { user, events, token, expiresAt } = response;
|
|
165
|
+
let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response;
|
|
166
166
|
const location = { latitude, longitude, accuracy };
|
|
167
|
-
let passed;
|
|
168
|
-
let expiresIn;
|
|
169
167
|
if (expiresAt) {
|
|
170
168
|
expiresAt = new Date(expiresAt);
|
|
171
|
-
passed = user?.fraud?.passed && user?.country?.passed && user?.state?.passed;
|
|
172
|
-
expiresIn = (expiresAt.getTime() - Date.now()) / 1000;
|
|
173
169
|
}
|
|
174
170
|
|
|
175
171
|
const trackRes = {
|
|
@@ -180,6 +176,8 @@ class TrackAPI {
|
|
|
180
176
|
expiresAt,
|
|
181
177
|
expiresIn,
|
|
182
178
|
passed,
|
|
179
|
+
failureReasons,
|
|
180
|
+
_id,
|
|
183
181
|
} as RadarTrackVerifiedResponse;
|
|
184
182
|
|
|
185
183
|
if (options.debug) {
|
package/src/api/verify.ts
CHANGED
|
@@ -6,7 +6,14 @@ import Logger from '../logger';
|
|
|
6
6
|
import Session from '../session';
|
|
7
7
|
import Storage from '../storage';
|
|
8
8
|
|
|
9
|
-
import type { RadarTrackParams, RadarTrackVerifiedResponse } from '../types';
|
|
9
|
+
import type { RadarStartTrackingVerifiedParams, RadarTrackParams, RadarTrackVerifiedResponse } from '../types';
|
|
10
|
+
|
|
11
|
+
let tokenTimeoutId: any | null = null;
|
|
12
|
+
let tokenCallback: ((token: RadarTrackVerifiedResponse) => void) | null = null;
|
|
13
|
+
let lastToken: RadarTrackVerifiedResponse | null = null;
|
|
14
|
+
let lastTokenNow: number = 0;
|
|
15
|
+
let expectedCountryCode: string | null = null;
|
|
16
|
+
let expectedStateCode: string | null = null;
|
|
10
17
|
|
|
11
18
|
class VerifyAPI {
|
|
12
19
|
static async trackVerified(params: RadarTrackParams, encrypted: Boolean = false) {
|
|
@@ -41,6 +48,8 @@ class VerifyAPI {
|
|
|
41
48
|
stopped: true,
|
|
42
49
|
userId,
|
|
43
50
|
encrypted,
|
|
51
|
+
expectedCountryCode,
|
|
52
|
+
expectedStateCode,
|
|
44
53
|
};
|
|
45
54
|
|
|
46
55
|
let userAgent = navigator.userAgent;
|
|
@@ -53,7 +62,7 @@ class VerifyAPI {
|
|
|
53
62
|
host: apple ? 'https://radar-verify.com:52516' : 'http://localhost:52516',
|
|
54
63
|
});
|
|
55
64
|
|
|
56
|
-
let { user, events, token, expiresAt } = response;
|
|
65
|
+
let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response;
|
|
57
66
|
let location;
|
|
58
67
|
if (user && user.location && user.location.coordinates && user.locationAccuracy) {
|
|
59
68
|
location = {
|
|
@@ -62,12 +71,8 @@ class VerifyAPI {
|
|
|
62
71
|
accuracy: user.locationAccuracy,
|
|
63
72
|
};
|
|
64
73
|
}
|
|
65
|
-
let passed;
|
|
66
|
-
let expiresIn;
|
|
67
74
|
if (expiresAt) {
|
|
68
75
|
expiresAt = new Date(expiresAt);
|
|
69
|
-
passed = user?.fraud?.passed && user?.country?.passed && user?.state?.passed;
|
|
70
|
-
expiresIn = (expiresAt.getTime() - Date.now()) / 1000;
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
const trackRes = {
|
|
@@ -78,14 +83,86 @@ class VerifyAPI {
|
|
|
78
83
|
expiresAt,
|
|
79
84
|
expiresIn,
|
|
80
85
|
passed,
|
|
86
|
+
failureReasons,
|
|
87
|
+
_id,
|
|
81
88
|
} as RadarTrackVerifiedResponse;
|
|
82
89
|
|
|
83
90
|
if (options.debug) {
|
|
84
91
|
trackRes.response = response;
|
|
85
92
|
}
|
|
86
93
|
|
|
94
|
+
lastToken = trackRes;
|
|
95
|
+
lastTokenNow = performance.now();
|
|
96
|
+
|
|
97
|
+
if (tokenCallback) {
|
|
98
|
+
tokenCallback(trackRes);
|
|
99
|
+
}
|
|
100
|
+
|
|
87
101
|
return trackRes;
|
|
88
102
|
}
|
|
103
|
+
|
|
104
|
+
static async startTrackingVerified(params: RadarStartTrackingVerifiedParams) {
|
|
105
|
+
const doTrackVerified = async () => {
|
|
106
|
+
const trackRes = await this.trackVerified({});
|
|
107
|
+
|
|
108
|
+
const { interval } = params;
|
|
109
|
+
|
|
110
|
+
let expiresIn = 0;
|
|
111
|
+
let minInterval = interval;
|
|
112
|
+
|
|
113
|
+
if (trackRes) {
|
|
114
|
+
expiresIn = (trackRes.expiresIn || expiresIn);
|
|
115
|
+
|
|
116
|
+
// if expiresIn is shorter than interval, override interval
|
|
117
|
+
minInterval = Math.min(expiresIn, interval);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// re-request early to maximize the likelihood that a cached token is available
|
|
121
|
+
if (minInterval > 20) {
|
|
122
|
+
minInterval = minInterval - 10;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// min interval is 10 seconds
|
|
126
|
+
if (minInterval < 10) {
|
|
127
|
+
minInterval = 10;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (tokenTimeoutId) {
|
|
131
|
+
clearTimeout(tokenTimeoutId);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
tokenTimeoutId = setTimeout(doTrackVerified, minInterval * 1000);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
doTrackVerified();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
static stopTrackingVerified() {
|
|
141
|
+
if (tokenTimeoutId) {
|
|
142
|
+
clearTimeout(tokenTimeoutId);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static async getVerifiedLocationToken() {
|
|
147
|
+
const lastTokenElapsed = (performance.now() - lastTokenNow) / 1000;
|
|
148
|
+
|
|
149
|
+
if (lastToken) {
|
|
150
|
+
if (lastTokenElapsed < (lastToken.expiresIn || 0)) {
|
|
151
|
+
return lastToken;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return this.trackVerified({});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static setExpectedJurisdiction(countryCode?: string, stateCode?: string) {
|
|
159
|
+
expectedCountryCode = countryCode || null;
|
|
160
|
+
expectedStateCode = stateCode || null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static onTokenUpdated(callback: (token: RadarTrackVerifiedResponse) => void) {
|
|
164
|
+
tokenCallback = callback;
|
|
165
|
+
}
|
|
89
166
|
}
|
|
90
167
|
|
|
91
168
|
export default VerifyAPI;
|
package/src/index.ts
CHANGED
|
@@ -32,7 +32,9 @@ import type {
|
|
|
32
32
|
RadarReverseGeocodeParams,
|
|
33
33
|
RadarSearchGeofencesParams,
|
|
34
34
|
RadarSearchPlacesParams,
|
|
35
|
+
RadarStartTrackingVerifiedParams,
|
|
35
36
|
RadarTrackParams,
|
|
37
|
+
RadarTrackVerifiedResponse,
|
|
36
38
|
RadarTripOptions,
|
|
37
39
|
RadarValidateAddressParams,
|
|
38
40
|
} from './types';
|
|
@@ -105,7 +107,7 @@ class Radar {
|
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
///////////////////////
|
|
108
|
-
//
|
|
110
|
+
// Geofencing Platform
|
|
109
111
|
///////////////////////
|
|
110
112
|
|
|
111
113
|
public static setUserId(userId?: string) {
|
|
@@ -148,6 +150,22 @@ class Radar {
|
|
|
148
150
|
return VerifyAPI.trackVerified(params);
|
|
149
151
|
}
|
|
150
152
|
|
|
153
|
+
public static startTrackingVerified(params: RadarStartTrackingVerifiedParams) {
|
|
154
|
+
return VerifyAPI.startTrackingVerified(params);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public static stopTrackingVerified() {
|
|
158
|
+
return VerifyAPI.stopTrackingVerified();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public static getVerifiedLocationToken() {
|
|
162
|
+
return VerifyAPI.getVerifiedLocationToken();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public static setExpectedJurisdiction(countryCode?: string, stateCode?: string) {
|
|
166
|
+
VerifyAPI.setExpectedJurisdiction(countryCode, stateCode);
|
|
167
|
+
}
|
|
168
|
+
|
|
151
169
|
public static getContext(params: Location) {
|
|
152
170
|
return ContextAPI.getContext(params);
|
|
153
171
|
}
|
|
@@ -184,10 +202,16 @@ class Radar {
|
|
|
184
202
|
return ConversionsAPI.logConversion(params);
|
|
185
203
|
}
|
|
186
204
|
|
|
205
|
+
///////////////////////
|
|
206
|
+
// listeners
|
|
207
|
+
///////////////////////
|
|
208
|
+
public static onTokenUpdated(callback: (token: RadarTrackVerifiedResponse) => void) {
|
|
209
|
+
VerifyAPI.onTokenUpdated(callback);
|
|
210
|
+
}
|
|
187
211
|
|
|
188
|
-
|
|
189
|
-
//
|
|
190
|
-
|
|
212
|
+
///////////////////////
|
|
213
|
+
// Maps Platform
|
|
214
|
+
///////////////////////
|
|
191
215
|
|
|
192
216
|
public static forwardGeocode(params: RadarForwardGeocodeParams) {
|
|
193
217
|
return GeocodingAPI.forwardGeocode(params);
|
package/src/types.ts
CHANGED
|
@@ -76,6 +76,10 @@ export interface RadarTrackParams {
|
|
|
76
76
|
fraud?: boolean;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
export interface RadarStartTrackingVerifiedParams {
|
|
80
|
+
interval: number;
|
|
81
|
+
}
|
|
82
|
+
|
|
79
83
|
export enum RadarEventConfidence {
|
|
80
84
|
none = 0,
|
|
81
85
|
low = 1,
|
|
@@ -218,9 +222,11 @@ export interface RadarTrackVerifiedResponse extends RadarTrackResponse {
|
|
|
218
222
|
expiresAt?: Date;
|
|
219
223
|
expiresIn?: number;
|
|
220
224
|
passed?: boolean;
|
|
225
|
+
failureReasons?: string[];
|
|
226
|
+
_id?: string;
|
|
221
227
|
}
|
|
222
228
|
|
|
223
|
-
export interface RadarContextResponse
|
|
229
|
+
export interface RadarContextResponse extends RadarResponse {
|
|
224
230
|
location?: Location;
|
|
225
231
|
geofences?: RadarGeofence[];
|
|
226
232
|
place?: RadarPlace;
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '4.3.5
|
|
1
|
+
export default '4.3.5';
|