radar-sdk-js 4.4.7 → 4.4.9-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.4.7/radar.min.js"></script>
59
+ <script src="https://js.radar.com/v4.4.9-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.4.7/radar.css" rel="stylesheet">
77
- <script src="https://js.radar.com/v4.4.7/radar.min.js"></script>
76
+ <link href="https://js.radar.com/v4.4.9-beta.0/radar.css" rel="stylesheet">
77
+ <script src="https://js.radar.com/v4.4.9-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.4.7/radar.css" rel="stylesheet">
102
- <script src="https://js.radar.com/v4.4.7/radar.min.js"></script>
101
+ <link href="https://js.radar.com/v4.4.9-beta.0/radar.css" rel="stylesheet">
102
+ <script src="https://js.radar.com/v4.4.9-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.4.7/radar.css" rel="stylesheet">
134
- <script src="https://js.radar.com/v4.4.7/radar.min.js"></script>
133
+ <link href="https://js.radar.com/v4.4.9-beta.0/radar.css" rel="stylesheet">
134
+ <script src="https://js.radar.com/v4.4.9-beta.0/radar.min.js"></script>
135
135
  </head>
136
136
 
137
137
  <body>
@@ -1,5 +1,6 @@
1
1
  import type { RadarStartTrackingVerifiedParams, RadarTrackVerifiedParams, RadarTrackVerifiedResponse } from '../types';
2
2
  declare class VerifyAPI {
3
+ static ipChanged(): Promise<boolean>;
3
4
  static trackVerified(params: RadarTrackVerifiedParams, encrypted?: Boolean): Promise<RadarTrackVerifiedResponse>;
4
5
  static startTrackingVerified(params: RadarStartTrackingVerifiedParams): Promise<void>;
5
6
  static stopTrackingVerified(): void;
package/dist/radar.js CHANGED
@@ -305,7 +305,7 @@ class RadarAutocompleteContainerNotFound extends RadarError {
305
305
 
306
306
  const DEFAULT_POSITION_OPTIONS = {
307
307
  maximumAge: 0,
308
- timeout: 1000 * 30,
308
+ timeout: 1000 * 10,
309
309
  enableHighAccuracy: true,
310
310
  };
311
311
  // set "enableHighAccuracy" for navigator only when desiredAccuracy is "high"
@@ -405,7 +405,7 @@ class Navigator {
405
405
  }
406
406
  }
407
407
 
408
- var SDK_VERSION = '4.4.7';
408
+ var SDK_VERSION = '4.4.9-beta.0';
409
409
 
410
410
  const inFlightRequests = new Map();
411
411
  class Http {
@@ -1247,27 +1247,8 @@ class TrackAPI {
1247
1247
  'X-Radar-Desktop-Device-Type': 'Web',
1248
1248
  },
1249
1249
  });
1250
- let sclVal = -1;
1251
- let cslVal = -1;
1252
- /*
1253
- try {
1254
- const [sclRes, csl] = await Promise.all([
1255
- Http.request({
1256
- host: `https://${pingHost}`,
1257
- method: 'GET',
1258
- path: 'ping',
1259
- }),
1260
- ping(`wss://${pingHost}`),
1261
- ]);
1262
- const { scl }: any = sclRes;
1263
- sclVal = scl;
1264
- cslVal = csl;
1265
- } catch (err) {
1266
- // do nothing, send scl = -1 and csl = -1
1267
- }
1268
- */
1269
1250
  const payload = {
1270
- payload: JSON.stringify(Object.assign(Object.assign({}, body), { scl: sclVal, csl: cslVal, lang,
1251
+ payload: JSON.stringify(Object.assign(Object.assign({}, body), { lang,
1271
1252
  langs })),
1272
1253
  };
1273
1254
  const reqToken = yield signJWT(payload, dk);
@@ -1282,15 +1263,6 @@ class TrackAPI {
1282
1263
  'X-Radar-Body-Is-Token': 'true',
1283
1264
  },
1284
1265
  });
1285
- if (options.debug && response && response.user) {
1286
- if (!response.user.metadata) {
1287
- response.user.metadata = {};
1288
- }
1289
- response.user.metadata['radar:debug'] = {
1290
- sclVal,
1291
- cslVal,
1292
- };
1293
- }
1294
1266
  let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response;
1295
1267
  const location = { latitude, longitude, accuracy };
1296
1268
  if (expiresAt) {
@@ -1338,8 +1310,24 @@ let lastToken = null;
1338
1310
  let lastTokenNow = 0;
1339
1311
  let expectedCountryCode = null;
1340
1312
  let expectedStateCode = null;
1313
+ let lastIp = null;
1341
1314
  class VerifyAPI {
1315
+ static ipChanged() {
1316
+ return __awaiter(this, void 0, void 0, function* () {
1317
+ const { ip } = yield Http.request({
1318
+ method: 'GET',
1319
+ path: 'ping',
1320
+ });
1321
+ const ipChanged = ip !== lastIp;
1322
+ if (ipChanged) {
1323
+ Logger.info(`IP changed from ${lastIp} to ${ip}`);
1324
+ }
1325
+ lastIp = ip;
1326
+ return ipChanged;
1327
+ });
1328
+ }
1342
1329
  static trackVerified(params, encrypted = false) {
1330
+ var _a, _b;
1343
1331
  return __awaiter(this, void 0, void 0, function* () {
1344
1332
  const options = Config.get();
1345
1333
  const { skipVerifyApp } = params;
@@ -1410,6 +1398,10 @@ class VerifyAPI {
1410
1398
  trackRes.response = response;
1411
1399
  }
1412
1400
  }
1401
+ if (params.ipChanges && ((_a = trackRes === null || trackRes === void 0 ? void 0 : trackRes.user) === null || _a === void 0 ? void 0 : _a.ip)) {
1402
+ lastIp = (_b = trackRes === null || trackRes === void 0 ? void 0 : trackRes.user) === null || _b === void 0 ? void 0 : _b.ip;
1403
+ Logger.info(`Setting ip to ${lastIp}`);
1404
+ }
1413
1405
  lastToken = trackRes;
1414
1406
  lastTokenNow = performance.now();
1415
1407
  if (tokenCallback) {
@@ -1420,9 +1412,19 @@ class VerifyAPI {
1420
1412
  }
1421
1413
  static startTrackingVerified(params) {
1422
1414
  return __awaiter(this, void 0, void 0, function* () {
1415
+ let { interval } = params;
1416
+ if (!interval) {
1417
+ interval = 60;
1418
+ Logger.info(`interval not provided, using 60 seconds`);
1419
+ }
1423
1420
  const doTrackVerified = () => __awaiter(this, void 0, void 0, function* () {
1424
- const trackRes = yield this.trackVerified(params);
1425
- const { interval } = params;
1421
+ let trackRes;
1422
+ try {
1423
+ trackRes = yield this.trackVerified(params);
1424
+ }
1425
+ catch (err) {
1426
+ Logger.error(`trackVerified error: ${err.message}`);
1427
+ }
1426
1428
  let expiresIn = 0;
1427
1429
  let minInterval = interval;
1428
1430
  if (trackRes) {
@@ -1454,7 +1456,11 @@ class VerifyAPI {
1454
1456
  static getVerifiedLocationToken(params) {
1455
1457
  return __awaiter(this, void 0, void 0, function* () {
1456
1458
  const lastTokenElapsed = (performance.now() - lastTokenNow) / 1000;
1457
- if (lastToken && lastToken.passed) {
1459
+ let ipChanged = false;
1460
+ if (params.ipChanges) {
1461
+ ipChanged = yield this.ipChanged();
1462
+ }
1463
+ if (lastToken && lastToken.passed && !ipChanged) {
1458
1464
  if (lastTokenElapsed < (lastToken.expiresIn || 0)) {
1459
1465
  return lastToken;
1460
1466
  }
@@ -2026,7 +2032,7 @@ class RadarMap extends maplibregl.Map {
2026
2032
  // configure map options
2027
2033
  const style = getStyle(config, radarMapOptions);
2028
2034
  const mapOptions = Object.assign({}, defaultRadarMapOptions, defaultMaplibreOptions, radarMapOptions, { style });
2029
- Logger.debug('map initailized with options', mapOptions);
2035
+ Logger.debug('map initialized with options', mapOptions);
2030
2036
  mapOptions.transformRequest = (url, resourceType) => {
2031
2037
  // this handles when a style is switched
2032
2038
  if (resourceType === 'Style' && isRadarStyle(url)) {
package/dist/radar.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"radar.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/types.d.ts CHANGED
@@ -59,10 +59,12 @@ export interface RadarTrackVerifiedParams {
59
59
  description?: string;
60
60
  metadata?: RadarMetadata;
61
61
  skipVerifyApp?: boolean;
62
+ ipChanges?: boolean;
62
63
  }
63
64
  export interface RadarStartTrackingVerifiedParams {
64
65
  interval: number;
65
66
  skipVerifyApp?: boolean;
67
+ ipChanges?: boolean;
66
68
  }
67
69
  export declare enum RadarEventConfidence {
68
70
  none = 0,
@@ -147,6 +149,7 @@ export interface RadarUser {
147
149
  dma?: RadarRegion;
148
150
  postalCode?: RadarRegion;
149
151
  fraud?: RadarFraud;
152
+ ip?: string;
150
153
  }
151
154
  export interface RadarTrackResponse extends RadarResponse {
152
155
  location?: Location;
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "4.4.7";
1
+ declare const _default: "4.4.9-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.4.7",
3
+ "version": "4.4.9-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
@@ -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,31 +108,9 @@ class TrackAPI {
109
108
  },
110
109
  });
111
110
 
112
- let sclVal = -1;
113
- let cslVal = -1;
114
- /*
115
- try {
116
- const [sclRes, csl] = await Promise.all([
117
- Http.request({
118
- host: `https://${pingHost}`,
119
- method: 'GET',
120
- path: 'ping',
121
- }),
122
- ping(`wss://${pingHost}`),
123
- ]);
124
- const { scl }: any = sclRes;
125
- sclVal = scl;
126
- cslVal = csl;
127
- } catch (err) {
128
- // do nothing, send scl = -1 and csl = -1
129
- }
130
- */
131
-
132
111
  const payload = {
133
112
  payload: JSON.stringify({
134
113
  ...body,
135
- scl: sclVal,
136
- csl: cslVal,
137
114
  lang,
138
115
  langs,
139
116
  }),
@@ -153,17 +130,6 @@ class TrackAPI {
153
130
  },
154
131
  });
155
132
 
156
- if (options.debug && response && response.user) {
157
- if (!response.user.metadata) {
158
- response.user.metadata = {};
159
- }
160
-
161
- response.user.metadata['radar:debug'] = {
162
- sclVal,
163
- cslVal,
164
- };
165
- }
166
-
167
133
  let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response;
168
134
  const location = { latitude, longitude, accuracy };
169
135
  if (expiresAt) {
package/src/api/verify.ts CHANGED
@@ -15,8 +15,25 @@ let lastToken: RadarTrackVerifiedResponse | null = null;
15
15
  let lastTokenNow: number = 0;
16
16
  let expectedCountryCode: string | null = null;
17
17
  let expectedStateCode: string | null = null;
18
+ let lastIp: string | null = null;
18
19
 
19
20
  class VerifyAPI {
21
+ static async ipChanged() {
22
+ const { ip }: any = await Http.request({
23
+ method: 'GET',
24
+ path: 'ping',
25
+ });
26
+
27
+ const ipChanged = ip !== lastIp;
28
+ if (ipChanged) {
29
+ Logger.info(`IP changed from ${lastIp} to ${ip}`);
30
+ }
31
+
32
+ lastIp = ip;
33
+
34
+ return ipChanged;
35
+ }
36
+
20
37
  static async trackVerified(params: RadarTrackVerifiedParams, encrypted: Boolean = false) {
21
38
  const options = Config.get();
22
39
 
@@ -104,6 +121,11 @@ class VerifyAPI {
104
121
  }
105
122
  }
106
123
 
124
+ if (params.ipChanges && trackRes?.user?.ip) {
125
+ lastIp = trackRes?.user?.ip;
126
+ Logger.info(`Setting ip to ${lastIp}`);
127
+ }
128
+
107
129
  lastToken = trackRes;
108
130
  lastTokenNow = performance.now();
109
131
 
@@ -115,10 +137,19 @@ class VerifyAPI {
115
137
  }
116
138
 
117
139
  static async startTrackingVerified(params: RadarStartTrackingVerifiedParams) {
118
- const doTrackVerified = async () => {
119
- const trackRes = await this.trackVerified(params);
140
+ let { interval } = params;
141
+ if (!interval) {
142
+ interval = 60;
143
+ Logger.info(`interval not provided, using 60 seconds`);
144
+ }
120
145
 
121
- const { interval } = params;
146
+ const doTrackVerified = async () => {
147
+ let trackRes;
148
+ try {
149
+ trackRes = await this.trackVerified(params);
150
+ } catch (err: any) {
151
+ Logger.error(`trackVerified error: ${err.message}`);
152
+ }
122
153
 
123
154
  let expiresIn = 0;
124
155
  let minInterval = interval;
@@ -159,7 +190,12 @@ class VerifyAPI {
159
190
  static async getVerifiedLocationToken(params: RadarTrackVerifiedParams) {
160
191
  const lastTokenElapsed = (performance.now() - lastTokenNow) / 1000;
161
192
 
162
- if (lastToken && lastToken.passed) {
193
+ let ipChanged = false;
194
+ if (params.ipChanges) {
195
+ ipChanged = await this.ipChanged();
196
+ }
197
+
198
+ if (lastToken && lastToken.passed && !ipChanged) {
163
199
  if (lastTokenElapsed < (lastToken.expiresIn || 0)) {
164
200
  return lastToken;
165
201
  }
package/src/navigator.ts CHANGED
@@ -11,7 +11,7 @@ interface PositionOptionOverrides {
11
11
 
12
12
  const DEFAULT_POSITION_OPTIONS: PositionOptions = {
13
13
  maximumAge: 0,
14
- timeout: 1000 * 30, // 30 seconds
14
+ timeout: 1000 * 10, // 10 seconds
15
15
  enableHighAccuracy: true,
16
16
  };
17
17
 
package/src/types.ts CHANGED
@@ -81,11 +81,13 @@ export interface RadarTrackVerifiedParams {
81
81
  description?: string;
82
82
  metadata?: RadarMetadata;
83
83
  skipVerifyApp?: boolean;
84
+ ipChanges?: boolean;
84
85
  }
85
86
 
86
87
  export interface RadarStartTrackingVerifiedParams {
87
88
  interval: number;
88
89
  skipVerifyApp?: boolean;
90
+ ipChanges?: boolean;
89
91
  }
90
92
 
91
93
  export enum RadarEventConfidence {
@@ -217,6 +219,7 @@ export interface RadarUser {
217
219
  dma?: RadarRegion;
218
220
  postalCode?: RadarRegion;
219
221
  fraud?: RadarFraud;
222
+ ip?: string;
220
223
  }
221
224
 
222
225
  export interface RadarTrackResponse extends RadarResponse {
@@ -96,7 +96,7 @@ class RadarMap extends maplibregl.Map {
96
96
  radarMapOptions,
97
97
  { style },
98
98
  );
99
- Logger.debug('map initailized with options', mapOptions);
99
+ Logger.debug('map initialized with options', mapOptions);
100
100
 
101
101
  (mapOptions as maplibregl.MapOptions).transformRequest = (url, resourceType) => {
102
102
  // this handles when a style is switched
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '4.4.7';
1
+ export default '4.4.9-beta.0';