radar-sdk-js 4.5.3 → 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.3/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.3/radar.css" rel="stylesheet">
77
- <script src="https://js.radar.com/v4.5.3/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.3/radar.css" rel="stylesheet">
102
- <script src="https://js.radar.com/v4.5.3/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.3/radar.css" rel="stylesheet">
134
- <script src="https://js.radar.com/v4.5.3/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,12 +393,12 @@ 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) => {
397
+ let locationAuthorization = 'NOT_DETERMINED';
388
398
  if (!navigator || !navigator.permissions) {
389
- return reject(new RadarLocationError('navigator.permissions is not available.'));
399
+ return resolve(locationAuthorization);
390
400
  }
391
401
  navigator.permissions.query({ name: 'geolocation' }).then((permissionsStatus) => {
392
- let locationAuthorization = 'NOT_DETERMINED';
393
402
  switch (permissionsStatus.state) {
394
403
  case 'granted':
395
404
  locationAuthorization = 'GRANTED_FOREGROUND';
@@ -408,7 +417,7 @@ class Navigator {
408
417
  }
409
418
  }
410
419
 
411
- var SDK_VERSION = '4.5.3';
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());
@@ -644,7 +653,14 @@ class ConfigAPI {
644
653
  const deviceId = params.deviceId || Device.getDeviceId();
645
654
  const installId = params.installId || Device.getInstallId();
646
655
  const sessionId = Session.getSessionId();
647
- const locationAuthorization = yield Navigator.getPermissionStatus();
656
+ // location authorization
657
+ let locationAuthorization;
658
+ try {
659
+ locationAuthorization = yield Navigator.getPermissionStatus();
660
+ }
661
+ catch (err) {
662
+ Logger.warn(`Location authorization error: ${err.message}`);
663
+ }
648
664
  const data = {
649
665
  deviceId,
650
666
  installId,
@@ -1190,13 +1206,7 @@ class TrackAPI {
1190
1206
  accuracy = deviceLocation.accuracy;
1191
1207
  }
1192
1208
  // location authorization
1193
- let locationAuthorization;
1194
- try {
1195
- locationAuthorization = yield Navigator.getPermissionStatus();
1196
- }
1197
- catch (err) {
1198
- Logger.warn(`Location authorization error: ${err.message}`);
1199
- }
1209
+ const locationAuthorization = yield Navigator.getPermissionStatus();
1200
1210
  // user indentification fields
1201
1211
  const userId = params.userId || Storage.getItem(Storage.USER_ID);
1202
1212
  const deviceId = params.deviceId || Device.getDeviceId();
@@ -1318,6 +1328,7 @@ class TrackAPI {
1318
1328
  }
1319
1329
 
1320
1330
  let tokenTimeoutId = null;
1331
+ let isTrackingVerified = true;
1321
1332
  let tokenCallback = null;
1322
1333
  let lastToken = null;
1323
1334
  let lastTokenNow = 0;
@@ -1326,86 +1337,96 @@ let expectedStateCode = null;
1326
1337
  class VerifyAPI {
1327
1338
  static trackVerified(params, encrypted = false) {
1328
1339
  return __awaiter(this, void 0, void 0, function* () {
1329
- const options = Config.get();
1330
- const { skipVerifyApp } = params;
1331
- // user indentification fields
1332
- const userId = params.userId || Storage.getItem(Storage.USER_ID);
1333
- const deviceId = Device.getDeviceId();
1334
- const installId = Device.getInstallId();
1335
- const sessionId = Session.getSessionId();
1336
- const description = params.description || Storage.getItem(Storage.DESCRIPTION);
1337
- // save userId
1338
- if (!userId) {
1339
- Logger.warn('userId not provided for trackVerified.');
1340
- }
1341
- else {
1342
- Storage.setItem(Storage.USER_ID, userId);
1343
- }
1344
- // other info
1345
- const metadata = params.metadata || Storage.getJSON(Storage.METADATA);
1346
- let trackRes;
1347
- if (skipVerifyApp) {
1348
- trackRes = yield TrackAPI.trackOnce({
1349
- userId: userId !== null && userId !== void 0 ? userId : undefined,
1350
- description: description !== null && description !== void 0 ? description : undefined,
1351
- metadata: metadata,
1352
- fraud: true,
1353
- });
1354
- }
1355
- else {
1356
- const body = Object.assign(Object.assign({}, params), { description,
1357
- deviceId, foreground: true, installId,
1358
- sessionId,
1359
- metadata, sdkVersion: SDK_VERSION, stopped: true, userId,
1360
- encrypted,
1361
- expectedCountryCode,
1362
- expectedStateCode });
1363
- let userAgent = navigator.userAgent;
1364
- const apple = userAgent && (userAgent.toLowerCase().includes('mac') || userAgent.toLowerCase().includes('iphone') || userAgent.toLowerCase().includes('ipod') || userAgent.toLowerCase().includes('ipad'));
1365
- const response = yield Http.request({
1366
- method: 'GET',
1367
- path: 'verify',
1368
- data: body,
1369
- host: apple ? 'https://radar-verify.com:52516' : 'http://localhost:52516',
1370
- });
1371
- let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response;
1372
- let location;
1373
- if (user && user.location && user.location.coordinates && user.locationAccuracy) {
1374
- location = {
1375
- latitude: user.location.coordinates[1],
1376
- longitude: user.location.coordinates[0],
1377
- accuracy: user.locationAccuracy,
1378
- };
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.');
1379
1352
  }
1380
- if (expiresAt) {
1381
- expiresAt = new Date(expiresAt);
1353
+ else {
1354
+ Storage.setItem(Storage.USER_ID, userId);
1382
1355
  }
1383
- trackRes = {
1384
- user,
1385
- events,
1386
- location,
1387
- token,
1388
- expiresAt,
1389
- expiresIn,
1390
- passed,
1391
- failureReasons,
1392
- _id,
1393
- };
1394
- if (options.debug) {
1395
- 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
+ });
1396
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);
1414
+ }
1415
+ return trackRes;
1397
1416
  }
1398
- lastToken = trackRes;
1399
- lastTokenNow = performance.now();
1400
- if (tokenCallback) {
1401
- tokenCallback(trackRes);
1417
+ catch (err) {
1418
+ Config.sendError(err);
1419
+ throw err;
1402
1420
  }
1403
- return trackRes;
1404
1421
  });
1405
1422
  }
1406
1423
  static startTrackingVerified(params) {
1424
+ isTrackingVerified = true;
1407
1425
  const scheduleNextIntervalWithLastToken = () => __awaiter(this, void 0, void 0, function* () {
1408
- const { interval } = params;
1426
+ let { interval } = params;
1427
+ if (!interval) {
1428
+ interval = 20;
1429
+ }
1409
1430
  let minInterval = interval;
1410
1431
  if (lastToken) {
1411
1432
  const lastTokenElapsed = (performance.now() - lastTokenNow) / 1000;
@@ -1422,7 +1443,9 @@ class VerifyAPI {
1422
1443
  if (tokenTimeoutId) {
1423
1444
  clearTimeout(tokenTimeoutId);
1424
1445
  }
1425
- tokenTimeoutId = setTimeout(doTrackVerified, minInterval * 1000);
1446
+ if (isTrackingVerified) {
1447
+ tokenTimeoutId = setTimeout(doTrackVerified, minInterval * 1000);
1448
+ }
1426
1449
  });
1427
1450
  const doTrackVerified = () => __awaiter(this, void 0, void 0, function* () {
1428
1451
  try {
@@ -1441,6 +1464,7 @@ class VerifyAPI {
1441
1464
  }
1442
1465
  }
1443
1466
  static stopTrackingVerified() {
1467
+ isTrackingVerified = false;
1444
1468
  if (tokenTimeoutId) {
1445
1469
  clearTimeout(tokenTimeoutId);
1446
1470
  }
@@ -1602,6 +1626,9 @@ let Radar$1 = class Radar {
1602
1626
  static onTokenUpdated(callback) {
1603
1627
  VerifyAPI.onTokenUpdated(callback);
1604
1628
  }
1629
+ static onError(callback) {
1630
+ Config.onError(callback);
1631
+ }
1605
1632
  /////////////////
1606
1633
  // Maps Platform
1607
1634
  /////////////////
package/dist/radar.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"radar.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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const _default: "4.5.3";
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.3",
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/config.ts CHANGED
@@ -19,7 +19,14 @@ class ConfigAPI {
19
19
  const deviceId = params.deviceId || Device.getDeviceId();
20
20
  const installId = params.installId || Device.getInstallId();
21
21
  const sessionId = Session.getSessionId();
22
- const locationAuthorization = await Navigator.getPermissionStatus();
22
+
23
+ // location authorization
24
+ let locationAuthorization;
25
+ try {
26
+ locationAuthorization = await Navigator.getPermissionStatus();
27
+ } catch (err: any) {
28
+ Logger.warn(`Location authorization error: ${err.message}`);
29
+ }
23
30
 
24
31
  const data = {
25
32
  deviceId,
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,14 +102,14 @@ 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
+ let locationAuthorization: LocationAuthorization = 'NOT_DETERMINED';
107
+
106
108
  if (!navigator || !navigator.permissions) {
107
- return reject(new RadarLocationError('navigator.permissions is not available.'));
109
+ return resolve(locationAuthorization);
108
110
  }
109
111
 
110
112
  navigator.permissions.query({ name: 'geolocation' }).then((permissionsStatus) => {
111
- let locationAuthorization: LocationAuthorization = 'NOT_DETERMINED';
112
-
113
113
  switch(permissionsStatus.state) {
114
114
  case 'granted':
115
115
  locationAuthorization = 'GRANTED_FOREGROUND'
@@ -124,7 +124,7 @@ class Navigator {
124
124
  break;
125
125
  }
126
126
 
127
- return resolve(locationAuthorization)
127
+ return resolve(locationAuthorization);
128
128
  });
129
129
  });
130
130
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '4.5.3';
1
+ export default '4.5.5-beta.0';