radar-sdk-js 4.5.4 → 4.5.5-beta.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 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.5.4/radar.min.js"></script>
59
+ <script src="https://js.radar.com/v4.5.5-beta.0/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.5.4/radar.css" rel="stylesheet">
77
- <script src="https://js.radar.com/v4.5.4/radar.min.js"></script>
76
+ <link href="https://js.radar.com/v4.5.5-beta.0/radar.css" rel="stylesheet">
77
+ <script src="https://js.radar.com/v4.5.5-beta.0/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.5.4/radar.css" rel="stylesheet">
102
- <script src="https://js.radar.com/v4.5.4/radar.min.js"></script>
101
+ <link href="https://js.radar.com/v4.5.5-beta.0/radar.css" rel="stylesheet">
102
+ <script src="https://js.radar.com/v4.5.5-beta.0/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.5.4/radar.css" rel="stylesheet">
134
- <script src="https://js.radar.com/v4.5.4/radar.min.js"></script>
133
+ <link href="https://js.radar.com/v4.5.5-beta.0/radar.css" rel="stylesheet">
134
+ <script src="https://js.radar.com/v4.5.5-beta.0/radar.min.js"></script>
135
135
  </head>
136
136
 
137
137
  <body>
package/dist/api.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { RadarError } from './errors';
1
2
  import type { Location, RadarAutocompleteParams, RadarConversionParams, RadarDistanceParams, RadarForwardGeocodeParams, RadarMatrixParams, RadarMetadata, RadarOptions, RadarReverseGeocodeParams, RadarSearchGeofencesParams, RadarSearchPlacesParams, RadarStartTrackingVerifiedParams, RadarTrackParams, RadarTrackVerifiedParams, RadarTrackVerifiedResponse, RadarTripOptions, RadarValidateAddressParams } from './types';
2
3
  declare class Radar {
3
4
  static get VERSION(): string;
@@ -25,6 +26,7 @@ declare class Radar {
25
26
  static logConversion(params: RadarConversionParams): Promise<import("./types").RadarConversionResponse>;
26
27
  static setProduct(product?: string): void;
27
28
  static onTokenUpdated(callback: (token: RadarTrackVerifiedResponse) => void): void;
29
+ static onError(callback: (error: RadarError) => void): void;
28
30
  static forwardGeocode(params: RadarForwardGeocodeParams): Promise<import("./types").RadarGeocodeResponse>;
29
31
  static reverseGeocode(params: RadarReverseGeocodeParams): Promise<import("./types").RadarGeocodeResponse>;
30
32
  static ipGeocode(): Promise<import("./types").RadarIPGeocodeResponse>;
package/dist/config.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { RadarError } from './errors';
1
2
  import type { RadarOptions } from './types';
2
3
  declare class Config {
3
4
  static options: RadarOptions;
@@ -11,5 +12,7 @@ declare class Config {
11
12
  static setup(options?: RadarOptions): void;
12
13
  static get(): RadarOptions;
13
14
  static clear(): void;
15
+ static onError(callback: (error: RadarError) => void): void;
16
+ static sendError(error: any): void;
14
17
  }
15
18
  export default Config;
package/dist/errors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare class RadarError extends Error {
1
+ export declare class RadarError extends Error {
2
2
  status: string;
3
3
  constructor(message: string);
4
4
  }
@@ -59,4 +59,3 @@ export declare class RadarUnknownError extends RadarError {
59
59
  export declare class RadarAutocompleteContainerNotFound extends RadarError {
60
60
  constructor(message: string);
61
61
  }
62
- export {};
package/dist/radar.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import maplibregl from 'maplibre-gl';
2
2
 
3
+ let errorCallback = null;
3
4
  class Config {
4
5
  static setup(options = {}) {
5
6
  Config.options = options;
@@ -10,6 +11,14 @@ class Config {
10
11
  static clear() {
11
12
  Config.options = {};
12
13
  }
14
+ static onError(callback) {
15
+ errorCallback = callback;
16
+ }
17
+ static sendError(error) {
18
+ if (errorCallback && error) {
19
+ errorCallback(error);
20
+ }
21
+ }
13
22
  }
14
23
  Config.defaultOptions = {
15
24
  live: false,
@@ -384,7 +393,7 @@ class Navigator {
384
393
  }
385
394
  static getPermissionStatus() {
386
395
  return __awaiter(this, void 0, void 0, function* () {
387
- return new Promise((resolve, reject) => {
396
+ return new Promise((resolve) => {
388
397
  let locationAuthorization = 'NOT_DETERMINED';
389
398
  if (!navigator || !navigator.permissions) {
390
399
  return resolve(locationAuthorization);
@@ -408,7 +417,7 @@ class Navigator {
408
417
  }
409
418
  }
410
419
 
411
- var SDK_VERSION = '4.5.4';
420
+ var SDK_VERSION = '4.5.5-beta.0';
412
421
 
413
422
  const inFlightRequests = new Map();
414
423
  class Http {
@@ -537,7 +546,7 @@ class Http {
537
546
  };
538
547
  xhr.onerror = function () {
539
548
  if (host && (host === 'http://localhost:52516' || host === 'https://radar-verify.com:52516')) {
540
- reject(new RadarVerifyAppError());
549
+ reject(navigator.onLine ? new RadarVerifyAppError() : new RadarNetworkError());
541
550
  }
542
551
  else {
543
552
  reject(new RadarNetworkError());
@@ -545,7 +554,7 @@ class Http {
545
554
  };
546
555
  xhr.ontimeout = function () {
547
556
  if (host && (host === 'http://localhost:52516' || host === 'https://radar-verify.com:52516')) {
548
- reject(new RadarVerifyAppError());
557
+ reject(navigator.onLine ? new RadarVerifyAppError() : new RadarNetworkError());
549
558
  }
550
559
  else {
551
560
  reject(new RadarNetworkError());
@@ -1197,13 +1206,7 @@ class TrackAPI {
1197
1206
  accuracy = deviceLocation.accuracy;
1198
1207
  }
1199
1208
  // location authorization
1200
- let locationAuthorization;
1201
- try {
1202
- locationAuthorization = yield Navigator.getPermissionStatus();
1203
- }
1204
- catch (err) {
1205
- Logger.warn(`Location authorization error: ${err.message}`);
1206
- }
1209
+ const locationAuthorization = yield Navigator.getPermissionStatus();
1207
1210
  // user indentification fields
1208
1211
  const userId = params.userId || Storage.getItem(Storage.USER_ID);
1209
1212
  const deviceId = params.deviceId || Device.getDeviceId();
@@ -1325,6 +1328,7 @@ class TrackAPI {
1325
1328
  }
1326
1329
 
1327
1330
  let tokenTimeoutId = null;
1331
+ let isTrackingVerified = true;
1328
1332
  let tokenCallback = null;
1329
1333
  let lastToken = null;
1330
1334
  let lastTokenNow = 0;
@@ -1333,86 +1337,96 @@ let expectedStateCode = null;
1333
1337
  class VerifyAPI {
1334
1338
  static trackVerified(params, encrypted = false) {
1335
1339
  return __awaiter(this, void 0, void 0, function* () {
1336
- const options = Config.get();
1337
- const { skipVerifyApp } = params;
1338
- // user indentification fields
1339
- const userId = params.userId || Storage.getItem(Storage.USER_ID);
1340
- const deviceId = Device.getDeviceId();
1341
- const installId = Device.getInstallId();
1342
- const sessionId = Session.getSessionId();
1343
- const description = params.description || Storage.getItem(Storage.DESCRIPTION);
1344
- // save userId
1345
- if (!userId) {
1346
- Logger.warn('userId not provided for trackVerified.');
1347
- }
1348
- else {
1349
- Storage.setItem(Storage.USER_ID, userId);
1350
- }
1351
- // other info
1352
- const metadata = params.metadata || Storage.getJSON(Storage.METADATA);
1353
- let trackRes;
1354
- if (skipVerifyApp) {
1355
- trackRes = yield TrackAPI.trackOnce({
1356
- userId: userId !== null && userId !== void 0 ? userId : undefined,
1357
- description: description !== null && description !== void 0 ? description : undefined,
1358
- metadata: metadata,
1359
- fraud: true,
1360
- });
1361
- }
1362
- else {
1363
- const body = Object.assign(Object.assign({}, params), { description,
1364
- deviceId, foreground: true, installId,
1365
- sessionId,
1366
- metadata, sdkVersion: SDK_VERSION, stopped: true, userId,
1367
- encrypted,
1368
- expectedCountryCode,
1369
- expectedStateCode });
1370
- let userAgent = navigator.userAgent;
1371
- const apple = userAgent && (userAgent.toLowerCase().includes('mac') || userAgent.toLowerCase().includes('iphone') || userAgent.toLowerCase().includes('ipod') || userAgent.toLowerCase().includes('ipad'));
1372
- const response = yield Http.request({
1373
- method: 'GET',
1374
- path: 'verify',
1375
- data: body,
1376
- host: apple ? 'https://radar-verify.com:52516' : 'http://localhost:52516',
1377
- });
1378
- let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response;
1379
- let location;
1380
- if (user && user.location && user.location.coordinates && user.locationAccuracy) {
1381
- location = {
1382
- latitude: user.location.coordinates[1],
1383
- longitude: user.location.coordinates[0],
1384
- accuracy: user.locationAccuracy,
1385
- };
1340
+ try {
1341
+ const options = Config.get();
1342
+ const { skipVerifyApp } = params;
1343
+ // user indentification fields
1344
+ const userId = params.userId || Storage.getItem(Storage.USER_ID);
1345
+ const deviceId = Device.getDeviceId();
1346
+ const installId = Device.getInstallId();
1347
+ const sessionId = Session.getSessionId();
1348
+ const description = params.description || Storage.getItem(Storage.DESCRIPTION);
1349
+ // save userId
1350
+ if (!userId) {
1351
+ Logger.warn('userId not provided for trackVerified.');
1386
1352
  }
1387
- if (expiresAt) {
1388
- expiresAt = new Date(expiresAt);
1353
+ else {
1354
+ Storage.setItem(Storage.USER_ID, userId);
1389
1355
  }
1390
- trackRes = {
1391
- user,
1392
- events,
1393
- location,
1394
- token,
1395
- expiresAt,
1396
- expiresIn,
1397
- passed,
1398
- failureReasons,
1399
- _id,
1400
- };
1401
- if (options.debug) {
1402
- trackRes.response = response;
1356
+ // other info
1357
+ const metadata = params.metadata || Storage.getJSON(Storage.METADATA);
1358
+ let trackRes;
1359
+ if (skipVerifyApp) {
1360
+ trackRes = yield TrackAPI.trackOnce({
1361
+ userId: userId !== null && userId !== void 0 ? userId : undefined,
1362
+ description: description !== null && description !== void 0 ? description : undefined,
1363
+ metadata: metadata,
1364
+ fraud: true,
1365
+ });
1366
+ }
1367
+ else {
1368
+ const body = Object.assign(Object.assign({}, params), { description,
1369
+ deviceId, foreground: true, installId,
1370
+ sessionId,
1371
+ metadata, sdkVersion: SDK_VERSION, stopped: true, userId,
1372
+ encrypted,
1373
+ expectedCountryCode,
1374
+ expectedStateCode });
1375
+ let userAgent = navigator.userAgent;
1376
+ const apple = userAgent && (userAgent.toLowerCase().includes('mac') || userAgent.toLowerCase().includes('iphone') || userAgent.toLowerCase().includes('ipod') || userAgent.toLowerCase().includes('ipad'));
1377
+ const response = yield Http.request({
1378
+ method: 'GET',
1379
+ path: 'verify',
1380
+ data: body,
1381
+ host: apple ? 'https://radar-verify.com:52516' : 'http://localhost:52516',
1382
+ });
1383
+ let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response;
1384
+ let location;
1385
+ if (user && user.location && user.location.coordinates && user.locationAccuracy) {
1386
+ location = {
1387
+ latitude: user.location.coordinates[1],
1388
+ longitude: user.location.coordinates[0],
1389
+ accuracy: user.locationAccuracy,
1390
+ };
1391
+ }
1392
+ if (expiresAt) {
1393
+ expiresAt = new Date(expiresAt);
1394
+ }
1395
+ trackRes = {
1396
+ user,
1397
+ events,
1398
+ location,
1399
+ token,
1400
+ expiresAt,
1401
+ expiresIn,
1402
+ passed,
1403
+ failureReasons,
1404
+ _id,
1405
+ };
1406
+ if (options.debug) {
1407
+ trackRes.response = response;
1408
+ }
1409
+ }
1410
+ lastToken = trackRes;
1411
+ lastTokenNow = performance.now();
1412
+ if (tokenCallback) {
1413
+ tokenCallback(trackRes);
1403
1414
  }
1415
+ return trackRes;
1404
1416
  }
1405
- lastToken = trackRes;
1406
- lastTokenNow = performance.now();
1407
- if (tokenCallback) {
1408
- tokenCallback(trackRes);
1417
+ catch (err) {
1418
+ Config.sendError(err);
1419
+ throw err;
1409
1420
  }
1410
- return trackRes;
1411
1421
  });
1412
1422
  }
1413
1423
  static startTrackingVerified(params) {
1424
+ isTrackingVerified = true;
1414
1425
  const scheduleNextIntervalWithLastToken = () => __awaiter(this, void 0, void 0, function* () {
1415
- const { interval } = params;
1426
+ let { interval } = params;
1427
+ if (!interval) {
1428
+ interval = 20;
1429
+ }
1416
1430
  let minInterval = interval;
1417
1431
  if (lastToken) {
1418
1432
  const lastTokenElapsed = (performance.now() - lastTokenNow) / 1000;
@@ -1429,7 +1443,9 @@ class VerifyAPI {
1429
1443
  if (tokenTimeoutId) {
1430
1444
  clearTimeout(tokenTimeoutId);
1431
1445
  }
1432
- tokenTimeoutId = setTimeout(doTrackVerified, minInterval * 1000);
1446
+ if (isTrackingVerified) {
1447
+ tokenTimeoutId = setTimeout(doTrackVerified, minInterval * 1000);
1448
+ }
1433
1449
  });
1434
1450
  const doTrackVerified = () => __awaiter(this, void 0, void 0, function* () {
1435
1451
  try {
@@ -1448,6 +1464,7 @@ class VerifyAPI {
1448
1464
  }
1449
1465
  }
1450
1466
  static stopTrackingVerified() {
1467
+ isTrackingVerified = false;
1451
1468
  if (tokenTimeoutId) {
1452
1469
  clearTimeout(tokenTimeoutId);
1453
1470
  }
@@ -1609,6 +1626,9 @@ let Radar$1 = class Radar {
1609
1626
  static onTokenUpdated(callback) {
1610
1627
  VerifyAPI.onTokenUpdated(callback);
1611
1628
  }
1629
+ static onError(callback) {
1630
+ Config.onError(callback);
1631
+ }
1612
1632
  /////////////////
1613
1633
  // Maps Platform
1614
1634
  /////////////////
package/dist/radar.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"radar.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "4.5.4";
1
+ declare const _default: "4.5.5-beta.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.4",
3
+ "version": "4.5.5-beta.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",
package/src/api/track.ts CHANGED
@@ -8,7 +8,6 @@ import Session from '../session';
8
8
  import Storage from '../storage';
9
9
  import TripsAPI from './trips';
10
10
  import { signJWT } from '../util/jwt';
11
- import { ping } from '../util/net';
12
11
 
13
12
  import type { RadarTrackParams, RadarTrackResponse, RadarTrackVerifiedResponse } from '../types';
14
13
 
@@ -33,12 +32,7 @@ class TrackAPI {
33
32
  }
34
33
 
35
34
  // location authorization
36
- let locationAuthorization;
37
- try {
38
- locationAuthorization = await Navigator.getPermissionStatus();
39
- } catch (err: any) {
40
- Logger.warn(`Location authorization error: ${err.message}`);
41
- }
35
+ const locationAuthorization = await Navigator.getPermissionStatus();
42
36
 
43
37
  // user indentification fields
44
38
  const userId = params.userId || Storage.getItem(Storage.USER_ID);
package/src/api/verify.ts CHANGED
@@ -7,9 +7,11 @@ import Session from '../session';
7
7
  import Storage from '../storage';
8
8
  import TrackAPI from './track';
9
9
 
10
+ import type { RadarError } from '../errors';
10
11
  import type { RadarStartTrackingVerifiedParams, RadarTrackVerifiedParams, RadarTrackVerifiedResponse } from '../types';
11
12
 
12
13
  let tokenTimeoutId: any | null = null;
14
+ let isTrackingVerified = true;
13
15
  let tokenCallback: ((token: RadarTrackVerifiedResponse) => void) | null = null;
14
16
  let lastToken: RadarTrackVerifiedResponse | null = null;
15
17
  let lastTokenNow: number = 0;
@@ -18,105 +20,116 @@ let expectedStateCode: string | null = null;
18
20
 
19
21
  class VerifyAPI {
20
22
  static async trackVerified(params: RadarTrackVerifiedParams, encrypted: Boolean = false) {
21
- const options = Config.get();
22
-
23
- const { skipVerifyApp } = params;
24
-
25
- // user indentification fields
26
- const userId = params.userId || Storage.getItem(Storage.USER_ID);
27
- const deviceId = Device.getDeviceId();
28
- const installId = Device.getInstallId();
29
- const sessionId = Session.getSessionId();
30
- const description = params.description || Storage.getItem(Storage.DESCRIPTION);
31
-
32
- // save userId
33
- if (!userId) {
34
- Logger.warn('userId not provided for trackVerified.');
35
- } else {
36
- Storage.setItem(Storage.USER_ID, userId);
37
- }
23
+ try {
24
+ const options = Config.get();
25
+
26
+ const { skipVerifyApp } = params;
27
+
28
+ // user indentification fields
29
+ const userId = params.userId || Storage.getItem(Storage.USER_ID);
30
+ const deviceId = Device.getDeviceId();
31
+ const installId = Device.getInstallId();
32
+ const sessionId = Session.getSessionId();
33
+ const description = params.description || Storage.getItem(Storage.DESCRIPTION);
34
+
35
+ // save userId
36
+ if (!userId) {
37
+ Logger.warn('userId not provided for trackVerified.');
38
+ } else {
39
+ Storage.setItem(Storage.USER_ID, userId);
40
+ }
38
41
 
39
- // other info
40
- const metadata = params.metadata || Storage.getJSON(Storage.METADATA);
41
-
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,
65
- };
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,
42
+ // other info
43
+ const metadata = params.metadata || Storage.getJSON(Storage.METADATA);
44
+
45
+ let trackRes: RadarTrackVerifiedResponse;
46
+ if (skipVerifyApp) {
47
+ trackRes = await TrackAPI.trackOnce({
48
+ userId: userId ?? undefined,
49
+ description: description ?? undefined,
50
+ metadata: metadata,
51
+ fraud: true,
52
+ });
53
+ } else {
54
+ const body = {
55
+ ...params,
56
+ description,
57
+ deviceId,
58
+ foreground: true,
59
+ installId,
60
+ sessionId,
61
+ metadata,
62
+ sdkVersion: SDK_VERSION,
63
+ stopped: true,
64
+ userId,
65
+ encrypted,
66
+ expectedCountryCode,
67
+ expectedStateCode,
84
68
  };
69
+
70
+ let userAgent = navigator.userAgent;
71
+ const apple = userAgent && (userAgent.toLowerCase().includes('mac') || userAgent.toLowerCase().includes('iphone') || userAgent.toLowerCase().includes('ipod') || userAgent.toLowerCase().includes('ipad'));
72
+
73
+ const response: any = await Http.request({
74
+ method: 'GET',
75
+ path: 'verify',
76
+ data: body,
77
+ host: apple ? 'https://radar-verify.com:52516' : 'http://localhost:52516',
78
+ });
79
+
80
+ let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response;
81
+ let location;
82
+ if (user && user.location && user.location.coordinates && user.locationAccuracy) {
83
+ location = {
84
+ latitude: user.location.coordinates[1],
85
+ longitude: user.location.coordinates[0],
86
+ accuracy: user.locationAccuracy,
87
+ };
88
+ }
89
+ if (expiresAt) {
90
+ expiresAt = new Date(expiresAt);
91
+ }
92
+
93
+ trackRes = {
94
+ user,
95
+ events,
96
+ location,
97
+ token,
98
+ expiresAt,
99
+ expiresIn,
100
+ passed,
101
+ failureReasons,
102
+ _id,
103
+ } as RadarTrackVerifiedResponse;
104
+
105
+ if (options.debug) {
106
+ trackRes.response = response;
107
+ }
85
108
  }
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
- }
105
- }
106
109
 
107
- lastToken = trackRes;
108
- lastTokenNow = performance.now();
110
+ lastToken = trackRes;
111
+ lastTokenNow = performance.now();
109
112
 
110
- if (tokenCallback) {
111
- tokenCallback(trackRes);
112
- }
113
+ if (tokenCallback) {
114
+ tokenCallback(trackRes);
115
+ }
113
116
 
114
- return trackRes;
117
+ return trackRes;
118
+ } catch (err: any) {
119
+ Config.sendError(err);
120
+ throw err;
121
+ }
115
122
  }
116
123
 
117
124
  static startTrackingVerified(params: RadarStartTrackingVerifiedParams) {
125
+ isTrackingVerified = true;
126
+
118
127
  const scheduleNextIntervalWithLastToken = async () => {
119
- const { interval } = params;
128
+ let { interval } = params;
129
+
130
+ if (!interval) {
131
+ interval = 20;
132
+ }
120
133
 
121
134
  let minInterval = interval;
122
135
 
@@ -141,8 +154,10 @@ class VerifyAPI {
141
154
  clearTimeout(tokenTimeoutId);
142
155
  }
143
156
 
144
- tokenTimeoutId = setTimeout(doTrackVerified, minInterval * 1000);
145
- }
157
+ if (isTrackingVerified) {
158
+ tokenTimeoutId = setTimeout(doTrackVerified, minInterval * 1000);
159
+ }
160
+ };
146
161
 
147
162
  const doTrackVerified = async () => {
148
163
  try {
@@ -162,6 +177,8 @@ class VerifyAPI {
162
177
  }
163
178
 
164
179
  static stopTrackingVerified() {
180
+ isTrackingVerified = false;
181
+
165
182
  if (tokenTimeoutId) {
166
183
  clearTimeout(tokenTimeoutId);
167
184
  }
package/src/api.ts CHANGED
@@ -2,7 +2,7 @@ import Config from './config';
2
2
  import Logger from './logger';
3
3
  import Storage from './storage';
4
4
  import Navigator from './navigator';
5
- import { RadarPublishableKeyError } from './errors';
5
+ import { RadarError, RadarPublishableKeyError } from './errors';
6
6
 
7
7
  import AddressesAPI from './api/addresses';
8
8
  import ConfigAPI from './api/config';
@@ -201,10 +201,14 @@ class Radar {
201
201
  ///////////////////////
202
202
  // Listeners
203
203
  ///////////////////////
204
+
204
205
  public static onTokenUpdated(callback: (token: RadarTrackVerifiedResponse) => void) {
205
206
  VerifyAPI.onTokenUpdated(callback);
206
207
  }
207
208
 
209
+ public static onError(callback: (error: RadarError) => void) {
210
+ Config.onError(callback);
211
+ }
208
212
 
209
213
  /////////////////
210
214
  // Maps Platform
package/src/config.ts CHANGED
@@ -1,5 +1,8 @@
1
+ import { RadarError } from './errors';
1
2
  import type { RadarOptions } from './types';
2
3
 
4
+ let errorCallback: ((error: RadarError) => void) | null = null;
5
+
3
6
  class Config {
4
7
  static options: RadarOptions;
5
8
 
@@ -22,6 +25,16 @@ class Config {
22
25
  public static clear() {
23
26
  Config.options = {};
24
27
  }
28
+
29
+ public static onError(callback: (error: RadarError) => void) {
30
+ errorCallback = callback;
31
+ }
32
+
33
+ public static sendError(error: any) {
34
+ if (errorCallback && error) {
35
+ errorCallback(error);
36
+ }
37
+ }
25
38
  }
26
39
 
27
40
  export default Config
package/src/errors.ts CHANGED
@@ -1,4 +1,4 @@
1
- class RadarError extends Error {
1
+ export class RadarError extends Error {
2
2
  status: string;
3
3
 
4
4
  constructor(message: string) {
package/src/http.ts CHANGED
@@ -187,7 +187,7 @@ class Http {
187
187
 
188
188
  xhr.onerror = function () {
189
189
  if (host && (host === 'http://localhost:52516' || host === 'https://radar-verify.com:52516')) {
190
- reject(new RadarVerifyAppError());
190
+ reject(navigator.onLine ? new RadarVerifyAppError() : new RadarNetworkError());
191
191
  } else {
192
192
  reject(new RadarNetworkError());
193
193
  }
@@ -195,7 +195,7 @@ class Http {
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());
198
+ reject(navigator.onLine ? new RadarVerifyAppError() : new RadarNetworkError());
199
199
  } else {
200
200
  reject(new RadarNetworkError());
201
201
  }
package/src/navigator.ts CHANGED
@@ -102,7 +102,7 @@ class Navigator {
102
102
  }
103
103
 
104
104
  public static async getPermissionStatus(): Promise<LocationAuthorization> {
105
- return new Promise((resolve, reject) => {
105
+ return new Promise((resolve) => {
106
106
  let locationAuthorization: LocationAuthorization = 'NOT_DETERMINED';
107
107
 
108
108
  if (!navigator || !navigator.permissions) {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '4.5.4';
1
+ export default '4.5.5-beta.0';