radar-sdk-js 4.2.1-beta.1 → 4.2.1-beta.2
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/http.d.ts +1 -2
- package/dist/radar.js +1873 -1590
- package/dist/radar.js.map +1 -1
- package/dist/types.d.ts +4 -8
- package/dist/ui/map.d.ts +2 -4
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/api/track.ts +26 -26
- package/src/http.ts +20 -33
- package/src/types.ts +4 -9
- package/src/ui/map.ts +141 -9
- package/src/version.ts +1 -1
- package/dist/ui/RadarLogoControl.d.ts +0 -6
- package/dist/ui/RadarMap.d.ts +0 -10
- package/dist/ui/RadarMarker.d.ts +0 -13
- package/src/ui/RadarLogoControl.ts +0 -24
- package/src/ui/RadarMap.ts +0 -130
- package/src/ui/RadarMarker.ts +0 -140
package/dist/radar.js
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import maplibregl from 'maplibre-gl';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Config.options = options;
|
|
3
|
+
var Config = /** @class */ (function () {
|
|
4
|
+
function Config() {
|
|
6
5
|
}
|
|
7
|
-
|
|
6
|
+
Config.setup = function (options) {
|
|
7
|
+
if (options === void 0) { options = {}; }
|
|
8
|
+
Config.options = options;
|
|
9
|
+
};
|
|
10
|
+
Config.get = function () {
|
|
8
11
|
return Config.options || {};
|
|
9
|
-
}
|
|
10
|
-
|
|
12
|
+
};
|
|
13
|
+
Config.clear = function () {
|
|
11
14
|
Config.options = {};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
};
|
|
16
|
+
Config.defaultOptions = {
|
|
17
|
+
live: false,
|
|
18
|
+
logLevel: 'error',
|
|
19
|
+
host: 'https://api.radar.io',
|
|
20
|
+
version: 'v1',
|
|
21
|
+
debug: false,
|
|
22
|
+
};
|
|
23
|
+
return Config;
|
|
24
|
+
}());
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
var LOG_LEVELS = {
|
|
23
27
|
none: 0,
|
|
24
28
|
error: 1,
|
|
25
29
|
warn: 2,
|
|
@@ -27,12 +31,12 @@ const LOG_LEVELS = {
|
|
|
27
31
|
debug: 4,
|
|
28
32
|
};
|
|
29
33
|
// get the numeric level for logLevel option
|
|
30
|
-
|
|
34
|
+
var getLevel = function () {
|
|
31
35
|
// disable logging in tests
|
|
32
36
|
if (window && window.RADAR_TEST_ENV) {
|
|
33
37
|
return LOG_LEVELS.none;
|
|
34
38
|
}
|
|
35
|
-
|
|
39
|
+
var _a = Config.get(), logLevel = _a.logLevel, debug = _a.debug;
|
|
36
40
|
if (debug) {
|
|
37
41
|
return LOG_LEVELS.debug;
|
|
38
42
|
}
|
|
@@ -41,64 +45,101 @@ const getLevel = () => {
|
|
|
41
45
|
}
|
|
42
46
|
return LOG_LEVELS.error; // default to error-level logging if not set
|
|
43
47
|
};
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
var Logger = /** @class */ (function () {
|
|
49
|
+
function Logger() {
|
|
50
|
+
}
|
|
51
|
+
Logger.debug = function (message) {
|
|
46
52
|
if (getLevel() === LOG_LEVELS.debug) {
|
|
47
|
-
console.log(
|
|
53
|
+
console.log("Radar SDK (debug): ".concat(message.trim()));
|
|
48
54
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
55
|
+
};
|
|
56
|
+
Logger.info = function (message) {
|
|
51
57
|
if (getLevel() >= LOG_LEVELS.info) {
|
|
52
|
-
console.log(
|
|
58
|
+
console.log("Radar SDK: ".concat(message.trim()));
|
|
53
59
|
}
|
|
54
|
-
}
|
|
55
|
-
|
|
60
|
+
};
|
|
61
|
+
Logger.warn = function (message) {
|
|
56
62
|
if (getLevel() >= LOG_LEVELS.warn) {
|
|
57
|
-
console.warn(
|
|
63
|
+
console.warn("Radar SDK: ".concat(message.trim()));
|
|
58
64
|
}
|
|
59
|
-
}
|
|
60
|
-
|
|
65
|
+
};
|
|
66
|
+
Logger.error = function (message) {
|
|
61
67
|
if (getLevel() >= LOG_LEVELS.error) {
|
|
62
|
-
console.error(
|
|
68
|
+
console.error("Radar SDK: ".concat(message.trim()));
|
|
63
69
|
}
|
|
64
|
-
}
|
|
65
|
-
|
|
70
|
+
};
|
|
71
|
+
return Logger;
|
|
72
|
+
}());
|
|
66
73
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
74
|
+
var Storage = /** @class */ (function () {
|
|
75
|
+
function Storage() {
|
|
76
|
+
}
|
|
77
|
+
Object.defineProperty(Storage, "USER_ID", {
|
|
78
|
+
// local storage key definitions for identifying track users
|
|
79
|
+
get: function () {
|
|
80
|
+
return 'radar-userId';
|
|
81
|
+
},
|
|
82
|
+
enumerable: false,
|
|
83
|
+
configurable: true
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(Storage, "DEVICE_ID", {
|
|
86
|
+
get: function () {
|
|
87
|
+
return 'radar-deviceId';
|
|
88
|
+
},
|
|
89
|
+
enumerable: false,
|
|
90
|
+
configurable: true
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(Storage, "INSTALL_ID", {
|
|
93
|
+
get: function () {
|
|
94
|
+
return 'radar-installId';
|
|
95
|
+
},
|
|
96
|
+
enumerable: false,
|
|
97
|
+
configurable: true
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(Storage, "SESSION_ID", {
|
|
100
|
+
get: function () {
|
|
101
|
+
return 'radar-sessionId';
|
|
102
|
+
},
|
|
103
|
+
enumerable: false,
|
|
104
|
+
configurable: true
|
|
105
|
+
});
|
|
106
|
+
Object.defineProperty(Storage, "DESCRIPTION", {
|
|
107
|
+
get: function () {
|
|
108
|
+
return 'radar-description';
|
|
109
|
+
},
|
|
110
|
+
enumerable: false,
|
|
111
|
+
configurable: true
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(Storage, "METADATA", {
|
|
114
|
+
get: function () {
|
|
115
|
+
return 'radar-metadata';
|
|
116
|
+
},
|
|
117
|
+
enumerable: false,
|
|
118
|
+
configurable: true
|
|
119
|
+
});
|
|
120
|
+
Object.defineProperty(Storage, "CACHED_LOCATION", {
|
|
121
|
+
get: function () {
|
|
122
|
+
return 'radar-cached-location';
|
|
123
|
+
},
|
|
124
|
+
enumerable: false,
|
|
125
|
+
configurable: true
|
|
126
|
+
});
|
|
127
|
+
Object.defineProperty(Storage, "TRIP_OPTIONS", {
|
|
128
|
+
get: function () {
|
|
129
|
+
return 'radar-trip-options';
|
|
130
|
+
},
|
|
131
|
+
enumerable: false,
|
|
132
|
+
configurable: true
|
|
133
|
+
});
|
|
134
|
+
Storage.getStorage = function () {
|
|
135
|
+
var storage = window === null || window === void 0 ? void 0 : window.localStorage;
|
|
95
136
|
if (!storage) {
|
|
96
137
|
Logger.warn('localStorage not available.');
|
|
97
138
|
}
|
|
98
139
|
return storage;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
140
|
+
};
|
|
141
|
+
Storage.setItem = function (key, value) {
|
|
142
|
+
var storage = this.getStorage();
|
|
102
143
|
if (!storage) {
|
|
103
144
|
return;
|
|
104
145
|
}
|
|
@@ -106,20 +147,20 @@ class Storage {
|
|
|
106
147
|
return;
|
|
107
148
|
}
|
|
108
149
|
storage.setItem(key, value);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
150
|
+
};
|
|
151
|
+
Storage.getItem = function (key) {
|
|
152
|
+
var storage = this.getStorage();
|
|
112
153
|
if (!storage) {
|
|
113
154
|
return null;
|
|
114
155
|
}
|
|
115
|
-
|
|
156
|
+
var value = storage.getItem(key);
|
|
116
157
|
if (value !== undefined && value !== null) {
|
|
117
158
|
return value;
|
|
118
159
|
}
|
|
119
160
|
return null;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
161
|
+
};
|
|
162
|
+
Storage.getJSON = function (key) {
|
|
163
|
+
var item = this.getItem(key);
|
|
123
164
|
if (!item) {
|
|
124
165
|
return null;
|
|
125
166
|
}
|
|
@@ -127,25 +168,26 @@ class Storage {
|
|
|
127
168
|
return JSON.parse(item);
|
|
128
169
|
}
|
|
129
170
|
catch (err) {
|
|
130
|
-
Logger.warn(
|
|
171
|
+
Logger.warn("could not getJSON from storage for key: ".concat(key));
|
|
131
172
|
return null;
|
|
132
173
|
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
174
|
+
};
|
|
175
|
+
Storage.removeItem = function (key) {
|
|
176
|
+
var storage = this.getStorage();
|
|
136
177
|
if (!storage) {
|
|
137
178
|
return null;
|
|
138
179
|
}
|
|
139
180
|
storage.removeItem(key);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
181
|
+
};
|
|
182
|
+
Storage.clear = function () {
|
|
183
|
+
var storage = this.getStorage();
|
|
143
184
|
if (!storage) {
|
|
144
185
|
return null;
|
|
145
186
|
}
|
|
146
187
|
storage.clear();
|
|
147
|
-
}
|
|
148
|
-
|
|
188
|
+
};
|
|
189
|
+
return Storage;
|
|
190
|
+
}());
|
|
149
191
|
|
|
150
192
|
/******************************************************************************
|
|
151
193
|
Copyright (c) Microsoft Corporation.
|
|
@@ -163,6 +205,31 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
163
205
|
***************************************************************************** */
|
|
164
206
|
/* global Reflect, Promise */
|
|
165
207
|
|
|
208
|
+
var extendStatics = function(d, b) {
|
|
209
|
+
extendStatics = Object.setPrototypeOf ||
|
|
210
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
211
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
212
|
+
return extendStatics(d, b);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
function __extends(d, b) {
|
|
216
|
+
if (typeof b !== "function" && b !== null)
|
|
217
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
218
|
+
extendStatics(d, b);
|
|
219
|
+
function __() { this.constructor = d; }
|
|
220
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
var __assign = function() {
|
|
224
|
+
__assign = Object.assign || function __assign(t) {
|
|
225
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
226
|
+
s = arguments[i];
|
|
227
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
228
|
+
}
|
|
229
|
+
return t;
|
|
230
|
+
};
|
|
231
|
+
return __assign.apply(this, arguments);
|
|
232
|
+
};
|
|
166
233
|
|
|
167
234
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
168
235
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -172,1024 +239,1307 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
172
239
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
173
240
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
174
241
|
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function __generator(thisArg, body) {
|
|
245
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
246
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
247
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
248
|
+
function step(op) {
|
|
249
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
250
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
251
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
252
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
253
|
+
switch (op[0]) {
|
|
254
|
+
case 0: case 1: t = op; break;
|
|
255
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
256
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
257
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
258
|
+
default:
|
|
259
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
260
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
261
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
262
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
263
|
+
if (t[2]) _.ops.pop();
|
|
264
|
+
_.trys.pop(); continue;
|
|
265
|
+
}
|
|
266
|
+
op = body.call(thisArg, _);
|
|
267
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
268
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
269
|
+
}
|
|
175
270
|
}
|
|
176
271
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
272
|
+
var RadarError = /** @class */ (function (_super) {
|
|
273
|
+
__extends(RadarError, _super);
|
|
274
|
+
function RadarError(message) {
|
|
275
|
+
var _this = _super.call(this, message) || this;
|
|
276
|
+
_this.status = ''; // to be overridden (support for legacy status)
|
|
277
|
+
return _this;
|
|
278
|
+
}
|
|
279
|
+
return RadarError;
|
|
280
|
+
}(Error));
|
|
281
|
+
var RadarPublishableKeyError = /** @class */ (function (_super) {
|
|
282
|
+
__extends(RadarPublishableKeyError, _super);
|
|
283
|
+
function RadarPublishableKeyError(message) {
|
|
284
|
+
var _this = _super.call(this, message) || this;
|
|
285
|
+
_this.name = 'RadarPublishableKeyError';
|
|
286
|
+
_this.status = 'ERROR_PUBLISHABLE_KEY';
|
|
287
|
+
return _this;
|
|
288
|
+
}
|
|
289
|
+
return RadarPublishableKeyError;
|
|
290
|
+
}(RadarError));
|
|
291
|
+
var RadarLocationError = /** @class */ (function (_super) {
|
|
292
|
+
__extends(RadarLocationError, _super);
|
|
293
|
+
function RadarLocationError(message) {
|
|
294
|
+
var _this = _super.call(this, message) || this;
|
|
295
|
+
_this.name = 'RadarLocationError';
|
|
296
|
+
_this.status = 'ERROR_LOCATION';
|
|
297
|
+
return _this;
|
|
298
|
+
}
|
|
299
|
+
return RadarLocationError;
|
|
300
|
+
}(RadarError));
|
|
301
|
+
var RadarPermissionsError = /** @class */ (function (_super) {
|
|
302
|
+
__extends(RadarPermissionsError, _super);
|
|
303
|
+
function RadarPermissionsError(message) {
|
|
304
|
+
var _this = _super.call(this, message) || this;
|
|
305
|
+
_this.name = 'RadarPermissionsError';
|
|
306
|
+
_this.status = 'ERROR_PERMISSIONS';
|
|
307
|
+
return _this;
|
|
308
|
+
}
|
|
309
|
+
return RadarPermissionsError;
|
|
310
|
+
}(RadarError));
|
|
311
|
+
var RadarVerifyAppError = /** @class */ (function (_super) {
|
|
312
|
+
__extends(RadarVerifyAppError, _super);
|
|
313
|
+
function RadarVerifyAppError() {
|
|
314
|
+
var _this = _super.call(this, 'Radar Verify app not running.') || this;
|
|
315
|
+
_this.name = 'RadarVerifyAppError';
|
|
316
|
+
_this.status = 'ERROR_VERIFY_APP';
|
|
317
|
+
return _this;
|
|
318
|
+
}
|
|
319
|
+
return RadarVerifyAppError;
|
|
320
|
+
}(RadarError));
|
|
211
321
|
// HTTP Errors
|
|
212
|
-
|
|
213
|
-
|
|
322
|
+
var RadarBadRequestError = /** @class */ (function (_super) {
|
|
323
|
+
__extends(RadarBadRequestError, _super);
|
|
324
|
+
function RadarBadRequestError(response) {
|
|
325
|
+
var _this = this;
|
|
214
326
|
var _a;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
327
|
+
_this = _super.call(this, ((_a = response === null || response === void 0 ? void 0 : response.meta) === null || _a === void 0 ? void 0 : _a.message) || 'Bad request.') || this;
|
|
328
|
+
_this.name = 'RadarBadRequestError';
|
|
329
|
+
_this.code = 400;
|
|
330
|
+
_this.response = response;
|
|
331
|
+
_this.status = 'ERROR_BAD_REQUEST';
|
|
332
|
+
return _this;
|
|
333
|
+
}
|
|
334
|
+
return RadarBadRequestError;
|
|
335
|
+
}(RadarError));
|
|
336
|
+
var RadarUnauthorizedError = /** @class */ (function (_super) {
|
|
337
|
+
__extends(RadarUnauthorizedError, _super);
|
|
338
|
+
function RadarUnauthorizedError(response) {
|
|
339
|
+
var _this = this;
|
|
224
340
|
var _a;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
341
|
+
_this = _super.call(this, ((_a = response === null || response === void 0 ? void 0 : response.meta) === null || _a === void 0 ? void 0 : _a.message) || 'Unauthorized.') || this;
|
|
342
|
+
_this.name = 'RadarUnauthorizedError';
|
|
343
|
+
_this.code = 401;
|
|
344
|
+
_this.response = response;
|
|
345
|
+
_this.status = 'ERROR_UNAUTHORIZED';
|
|
346
|
+
return _this;
|
|
347
|
+
}
|
|
348
|
+
return RadarUnauthorizedError;
|
|
349
|
+
}(RadarError));
|
|
350
|
+
var RadarPaymentRequiredError = /** @class */ (function (_super) {
|
|
351
|
+
__extends(RadarPaymentRequiredError, _super);
|
|
352
|
+
function RadarPaymentRequiredError(response) {
|
|
353
|
+
var _this = this;
|
|
234
354
|
var _a;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
355
|
+
_this = _super.call(this, ((_a = response === null || response === void 0 ? void 0 : response.meta) === null || _a === void 0 ? void 0 : _a.message) || 'Payment required.') || this;
|
|
356
|
+
_this.name = 'RadarPaymentRequiredError';
|
|
357
|
+
_this.code = 402;
|
|
358
|
+
_this.response = response;
|
|
359
|
+
_this.status = 'ERROR_PAYMENT_REQUIRED';
|
|
360
|
+
return _this;
|
|
361
|
+
}
|
|
362
|
+
return RadarPaymentRequiredError;
|
|
363
|
+
}(RadarError));
|
|
364
|
+
var RadarForbiddenError = /** @class */ (function (_super) {
|
|
365
|
+
__extends(RadarForbiddenError, _super);
|
|
366
|
+
function RadarForbiddenError(response) {
|
|
367
|
+
var _this = this;
|
|
244
368
|
var _a;
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
|
|
369
|
+
_this = _super.call(this, ((_a = response === null || response === void 0 ? void 0 : response.meta) === null || _a === void 0 ? void 0 : _a.message) || 'Forbidden.') || this;
|
|
370
|
+
_this.name = 'RadarForbiddenError';
|
|
371
|
+
_this.code = 403;
|
|
372
|
+
_this.response = response;
|
|
373
|
+
_this.status = 'ERROR_FORBIDDEN';
|
|
374
|
+
return _this;
|
|
375
|
+
}
|
|
376
|
+
return RadarForbiddenError;
|
|
377
|
+
}(RadarError));
|
|
378
|
+
var RadarNotFoundError = /** @class */ (function (_super) {
|
|
379
|
+
__extends(RadarNotFoundError, _super);
|
|
380
|
+
function RadarNotFoundError(response) {
|
|
381
|
+
var _this = this;
|
|
254
382
|
var _a;
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
383
|
+
_this = _super.call(this, ((_a = response === null || response === void 0 ? void 0 : response.meta) === null || _a === void 0 ? void 0 : _a.message) || 'Not found.') || this;
|
|
384
|
+
_this.name = 'RadarNotFoundError';
|
|
385
|
+
_this.code = 404;
|
|
386
|
+
_this.response = response;
|
|
387
|
+
_this.status = 'ERROR_NOT_FOUND';
|
|
388
|
+
return _this;
|
|
389
|
+
}
|
|
390
|
+
return RadarNotFoundError;
|
|
391
|
+
}(RadarError));
|
|
392
|
+
var RadarRateLimitError = /** @class */ (function (_super) {
|
|
393
|
+
__extends(RadarRateLimitError, _super);
|
|
394
|
+
function RadarRateLimitError(response) {
|
|
395
|
+
var _this = this;
|
|
264
396
|
var _a, _b;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
397
|
+
_this = _super.call(this, ((_a = response === null || response === void 0 ? void 0 : response.meta) === null || _a === void 0 ? void 0 : _a.message) || 'Rate limit exceeded.') || this;
|
|
398
|
+
_this.name = 'RadarRateLimitError';
|
|
399
|
+
_this.code = 429;
|
|
400
|
+
_this.response = response;
|
|
401
|
+
_this.type = (_b = response === null || response === void 0 ? void 0 : response.meta) === null || _b === void 0 ? void 0 : _b.type;
|
|
402
|
+
_this.status = 'ERROR_RATE_LIMIT';
|
|
403
|
+
return _this;
|
|
404
|
+
}
|
|
405
|
+
return RadarRateLimitError;
|
|
406
|
+
}(RadarError));
|
|
407
|
+
var RadarServerError = /** @class */ (function (_super) {
|
|
408
|
+
__extends(RadarServerError, _super);
|
|
409
|
+
function RadarServerError(response) {
|
|
410
|
+
var _this = this;
|
|
275
411
|
var _a;
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
412
|
+
_this = _super.call(this, ((_a = response === null || response === void 0 ? void 0 : response.meta) === null || _a === void 0 ? void 0 : _a.message) || 'Internal server error.') || this;
|
|
413
|
+
_this.name = 'RadarServerError';
|
|
414
|
+
_this.response = response;
|
|
415
|
+
_this.status = 'ERROR_SERVER';
|
|
416
|
+
return _this;
|
|
417
|
+
}
|
|
418
|
+
return RadarServerError;
|
|
419
|
+
}(RadarError));
|
|
420
|
+
var RadarNetworkError = /** @class */ (function (_super) {
|
|
421
|
+
__extends(RadarNetworkError, _super);
|
|
422
|
+
function RadarNetworkError() {
|
|
423
|
+
var _this = _super.call(this, 'Request timed out.') || this;
|
|
424
|
+
_this.name = 'RadarNetworkError';
|
|
425
|
+
_this.status = 'ERROR_NETWORK';
|
|
426
|
+
return _this;
|
|
427
|
+
}
|
|
428
|
+
return RadarNetworkError;
|
|
429
|
+
}(RadarError));
|
|
430
|
+
var RadarUnknownError = /** @class */ (function (_super) {
|
|
431
|
+
__extends(RadarUnknownError, _super);
|
|
432
|
+
function RadarUnknownError(response) {
|
|
433
|
+
var _this = this;
|
|
291
434
|
var _a;
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
435
|
+
_this = _super.call(this, ((_a = response === null || response === void 0 ? void 0 : response.meta) === null || _a === void 0 ? void 0 : _a.message) || 'Something went wrong.') || this;
|
|
436
|
+
_this.name = 'RadarUnknownError';
|
|
437
|
+
_this.response = response;
|
|
438
|
+
_this.status = 'ERROR_UNKNOWN';
|
|
439
|
+
return _this;
|
|
440
|
+
}
|
|
441
|
+
return RadarUnknownError;
|
|
442
|
+
}(RadarError));
|
|
443
|
+
var RadarAutocompleteContainerNotFound = /** @class */ (function (_super) {
|
|
444
|
+
__extends(RadarAutocompleteContainerNotFound, _super);
|
|
445
|
+
function RadarAutocompleteContainerNotFound(message) {
|
|
446
|
+
var _this = _super.call(this, message) || this;
|
|
447
|
+
_this.name = 'RadarAutocompleteContainerNotFound';
|
|
448
|
+
_this.status = 'CONTAINER_NOT_FOUND';
|
|
449
|
+
return _this;
|
|
450
|
+
}
|
|
451
|
+
return RadarAutocompleteContainerNotFound;
|
|
452
|
+
}(RadarError));
|
|
305
453
|
|
|
306
|
-
|
|
454
|
+
var DEFAULT_POSITION_OPTIONS = {
|
|
307
455
|
maximumAge: 0,
|
|
308
456
|
timeout: 1000 * 30,
|
|
309
457
|
enableHighAccuracy: true,
|
|
310
458
|
};
|
|
311
459
|
// set "enableHighAccuracy" for navigator only when desiredAccuracy is "high"
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
if (
|
|
330
|
-
|
|
460
|
+
var useHighAccuracy = function (desiredAccuracy) { return (Boolean(desiredAccuracy === 'high')); };
|
|
461
|
+
var Navigator = /** @class */ (function () {
|
|
462
|
+
function Navigator() {
|
|
463
|
+
}
|
|
464
|
+
Navigator.getCurrentPosition = function (overrides) {
|
|
465
|
+
if (overrides === void 0) { overrides = {}; }
|
|
466
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
467
|
+
return __generator(this, function (_a) {
|
|
468
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
469
|
+
var options = Config.get();
|
|
470
|
+
if (!navigator || !navigator.geolocation) {
|
|
471
|
+
return reject(new RadarLocationError('navigator.geolocation is not available.'));
|
|
472
|
+
}
|
|
473
|
+
// use cached location if available and options are set
|
|
474
|
+
if (options.cacheLocationMinutes) {
|
|
475
|
+
try {
|
|
476
|
+
var rawCachedLocation = Storage.getItem(Storage.CACHED_LOCATION);
|
|
477
|
+
if (rawCachedLocation) {
|
|
478
|
+
var cachedLocation = JSON.parse(rawCachedLocation);
|
|
479
|
+
var _a = cachedLocation || {}, latitude = _a.latitude, longitude = _a.longitude, accuracy = _a.accuracy, expiresAt = _a.expiresAt;
|
|
480
|
+
if (Date.now() < parseInt(expiresAt)) {
|
|
481
|
+
if (latitude && longitude && accuracy) {
|
|
482
|
+
return resolve({ latitude: latitude, longitude: longitude, accuracy: accuracy });
|
|
483
|
+
}
|
|
484
|
+
}
|
|
331
485
|
}
|
|
332
486
|
}
|
|
487
|
+
catch (e) {
|
|
488
|
+
Logger.warn('could not load cached location.');
|
|
489
|
+
}
|
|
333
490
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
return reject(new RadarPermissionsError('Location permissions denied.'));
|
|
376
|
-
}
|
|
377
|
-
return reject(new RadarLocationError('Could not determine location.'));
|
|
378
|
-
}, positionOptions);
|
|
491
|
+
// set options from config
|
|
492
|
+
var positionOptions = Object.assign({}, DEFAULT_POSITION_OPTIONS);
|
|
493
|
+
if (options.locationMaximumAge !== undefined) {
|
|
494
|
+
positionOptions.maximumAge = options.locationMaximumAge;
|
|
495
|
+
}
|
|
496
|
+
if (options.locationTimeout !== undefined) {
|
|
497
|
+
positionOptions.timeout = options.locationTimeout;
|
|
498
|
+
}
|
|
499
|
+
if (options.desiredAccuracy !== undefined) {
|
|
500
|
+
positionOptions.enableHighAccuracy = useHighAccuracy(options.desiredAccuracy);
|
|
501
|
+
}
|
|
502
|
+
// set options from overrides
|
|
503
|
+
if (overrides.desiredAccuracy !== undefined) {
|
|
504
|
+
positionOptions.enableHighAccuracy = useHighAccuracy(overrides.desiredAccuracy);
|
|
505
|
+
}
|
|
506
|
+
Logger.info("Using geolocation options: ".concat(JSON.stringify(positionOptions)));
|
|
507
|
+
// get current location from browser
|
|
508
|
+
navigator.geolocation.getCurrentPosition(function (position) {
|
|
509
|
+
if (!position || !position.coords) {
|
|
510
|
+
return reject(new RadarLocationError('device location return empty coordinates.'));
|
|
511
|
+
}
|
|
512
|
+
var _a = position.coords, latitude = _a.latitude, longitude = _a.longitude, accuracy = _a.accuracy;
|
|
513
|
+
// cache location if option is set
|
|
514
|
+
if (options.cacheLocationMinutes) {
|
|
515
|
+
var cacheLocationMinutes = Number.parseFloat(options.cacheLocationMinutes);
|
|
516
|
+
var updatedAt = Date.now();
|
|
517
|
+
var expiresAt = updatedAt + (cacheLocationMinutes * 60 * 1000); // convert to ms
|
|
518
|
+
var lastLocation = { latitude: latitude, longitude: longitude, accuracy: accuracy, updatedAt: updatedAt, expiresAt: expiresAt };
|
|
519
|
+
Storage.setItem(Storage.CACHED_LOCATION, JSON.stringify(lastLocation));
|
|
520
|
+
}
|
|
521
|
+
return resolve({ latitude: latitude, longitude: longitude, accuracy: accuracy });
|
|
522
|
+
}, function (err) {
|
|
523
|
+
if (err && err.code === 1) {
|
|
524
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/GeolocationPositionError
|
|
525
|
+
// code 1 means location permissions denied
|
|
526
|
+
// codes 2 and 3 mean location unavailable or timeout
|
|
527
|
+
return reject(new RadarPermissionsError('Location permissions denied.'));
|
|
528
|
+
}
|
|
529
|
+
return reject(new RadarLocationError('Could not determine location.'));
|
|
530
|
+
}, positionOptions);
|
|
531
|
+
})];
|
|
379
532
|
});
|
|
380
533
|
});
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
return __awaiter(this, void 0, void 0, function
|
|
384
|
-
return
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
534
|
+
};
|
|
535
|
+
Navigator.getPermissionStatus = function () {
|
|
536
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
537
|
+
return __generator(this, function (_a) {
|
|
538
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
539
|
+
if (!navigator || !navigator.permissions) {
|
|
540
|
+
return reject(new RadarLocationError('navigator.permissions is not available.'));
|
|
541
|
+
}
|
|
542
|
+
navigator.permissions.query({ name: 'geolocation' }).then(function (permissionsStatus) {
|
|
543
|
+
var locationAuthorization = 'NOT_DETERMINED';
|
|
544
|
+
switch (permissionsStatus.state) {
|
|
545
|
+
case 'granted':
|
|
546
|
+
locationAuthorization = 'GRANTED_FOREGROUND';
|
|
547
|
+
break;
|
|
548
|
+
case 'denied':
|
|
549
|
+
locationAuthorization = 'DENIED';
|
|
550
|
+
break;
|
|
551
|
+
case 'prompt':
|
|
552
|
+
locationAuthorization = 'NOT_DETERMINED';
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
return resolve(locationAuthorization);
|
|
556
|
+
});
|
|
557
|
+
})];
|
|
403
558
|
});
|
|
404
559
|
});
|
|
405
|
-
}
|
|
406
|
-
|
|
560
|
+
};
|
|
561
|
+
return Navigator;
|
|
562
|
+
}());
|
|
407
563
|
|
|
408
|
-
var SDK_VERSION = '4.2.1-beta.
|
|
564
|
+
var SDK_VERSION = '4.2.1-beta.2';
|
|
409
565
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
let url = `${urlHost}/${version}/${path}`;
|
|
425
|
-
if (!versioned) {
|
|
426
|
-
url = `${urlHost}/${path}`;
|
|
427
|
-
}
|
|
428
|
-
// remove undefined values from request data
|
|
429
|
-
let body = {};
|
|
430
|
-
Object.keys(data || {}).forEach((key) => {
|
|
431
|
-
const value = data[key];
|
|
432
|
-
if (value !== undefined) {
|
|
433
|
-
body[key] = value;
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
// convert data to querystring for GET requests
|
|
437
|
-
if (method === 'GET') {
|
|
438
|
-
const params = Object.keys(body).map((key) => (`${key}=${encodeURIComponent(body[key])}`));
|
|
439
|
-
if (params.length > 0) {
|
|
440
|
-
const queryString = params.join('&');
|
|
441
|
-
url = `${url}?${queryString}`;
|
|
442
|
-
}
|
|
443
|
-
body = undefined; // dont send body for GET request
|
|
444
|
-
}
|
|
445
|
-
const xhr = new XMLHttpRequest();
|
|
446
|
-
xhr.open(method, url, true);
|
|
447
|
-
const defaultHeaders = {
|
|
448
|
-
'Authorization': publishableKey,
|
|
449
|
-
'Content-Type': 'application/json',
|
|
450
|
-
'X-Radar-Device-Type': 'Web',
|
|
451
|
-
'X-Radar-SDK-Version': SDK_VERSION,
|
|
452
|
-
};
|
|
453
|
-
// set custom config headers if present
|
|
454
|
-
let configHeaders = {};
|
|
455
|
-
if (typeof options.getRequestHeaders === 'function') {
|
|
456
|
-
configHeaders = options.getRequestHeaders();
|
|
457
|
-
}
|
|
458
|
-
// combines default headers with custom headers and config headers
|
|
459
|
-
const allHeaders = Object.assign(defaultHeaders, headers, configHeaders);
|
|
460
|
-
// set headers
|
|
461
|
-
Object.entries(allHeaders).forEach(([key, val]) => {
|
|
462
|
-
xhr.setRequestHeader(key, val);
|
|
463
|
-
});
|
|
464
|
-
if (allHeaders['Content-Type'] === 'image/png') {
|
|
465
|
-
xhr.responseType = 'blob';
|
|
466
|
-
}
|
|
467
|
-
xhr.onload = () => {
|
|
468
|
-
var _a;
|
|
469
|
-
let response;
|
|
470
|
-
try {
|
|
471
|
-
if (allHeaders['Content-Type'] === 'application/json') {
|
|
472
|
-
response = JSON.parse(xhr.response);
|
|
566
|
+
var Http = /** @class */ (function () {
|
|
567
|
+
function Http() {
|
|
568
|
+
}
|
|
569
|
+
Http.request = function (_a) {
|
|
570
|
+
var method = _a.method, path = _a.path, data = _a.data, host = _a.host, headers = _a.headers;
|
|
571
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
572
|
+
return __generator(this, function (_b) {
|
|
573
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
574
|
+
var options = Config.get();
|
|
575
|
+
// check for publishableKey on request
|
|
576
|
+
var publishableKey = options.publishableKey;
|
|
577
|
+
if (!publishableKey) {
|
|
578
|
+
reject(new RadarPublishableKeyError('publishableKey not set.'));
|
|
579
|
+
return;
|
|
473
580
|
}
|
|
474
|
-
|
|
475
|
-
|
|
581
|
+
// setup request URL
|
|
582
|
+
var urlHost = host || options.host;
|
|
583
|
+
var version = options.version;
|
|
584
|
+
var url = "".concat(urlHost, "/").concat(version, "/").concat(path);
|
|
585
|
+
// remove undefined values from request data
|
|
586
|
+
var body = {};
|
|
587
|
+
Object.keys(data || {}).forEach(function (key) {
|
|
588
|
+
var value = data[key];
|
|
589
|
+
if (value !== undefined) {
|
|
590
|
+
body[key] = value;
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
// convert data to querystring for GET requests
|
|
594
|
+
if (method === 'GET') {
|
|
595
|
+
var params = Object.keys(body).map(function (key) { return ("".concat(key, "=").concat(encodeURIComponent(body[key]))); });
|
|
596
|
+
if (params.length > 0) {
|
|
597
|
+
var queryString = params.join('&');
|
|
598
|
+
url = "".concat(url, "?").concat(queryString);
|
|
599
|
+
}
|
|
600
|
+
body = undefined; // dont send body for GET request
|
|
476
601
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
602
|
+
var xhr = new XMLHttpRequest();
|
|
603
|
+
xhr.open(method, url, true);
|
|
604
|
+
// set standard headers
|
|
605
|
+
xhr.setRequestHeader('Authorization', publishableKey);
|
|
606
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
607
|
+
xhr.setRequestHeader('X-Radar-Device-Type', 'Web');
|
|
608
|
+
xhr.setRequestHeader('X-Radar-SDK-Version', SDK_VERSION);
|
|
609
|
+
// set passed custom headers if present
|
|
610
|
+
if (headers) {
|
|
611
|
+
Object.keys(headers).forEach(function (key) {
|
|
612
|
+
var val = headers[key];
|
|
613
|
+
xhr.setRequestHeader(key, val);
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
// set config custom headers if present
|
|
617
|
+
if (typeof options.getRequestHeaders === 'function') {
|
|
618
|
+
var headers_1 = options.getRequestHeaders();
|
|
619
|
+
Object.keys(headers_1 || {}).forEach(function (key) {
|
|
620
|
+
xhr.setRequestHeader(key, headers_1[key]);
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
xhr.onload = function () {
|
|
624
|
+
var _a;
|
|
625
|
+
var response;
|
|
626
|
+
try {
|
|
627
|
+
response = JSON.parse(xhr.response);
|
|
628
|
+
}
|
|
629
|
+
catch (e) {
|
|
630
|
+
return reject(new RadarServerError(response));
|
|
631
|
+
}
|
|
632
|
+
var error = (_a = response === null || response === void 0 ? void 0 : response.meta) === null || _a === void 0 ? void 0 : _a.error;
|
|
633
|
+
if (error === 'ERROR_PERMISSIONS') {
|
|
634
|
+
return reject(new RadarPermissionsError('Location permissions not granted.'));
|
|
635
|
+
}
|
|
636
|
+
else if (error === 'ERROR_LOCATION') {
|
|
637
|
+
return reject(new RadarLocationError('Could not determine location.'));
|
|
638
|
+
}
|
|
639
|
+
else if (error === 'ERROR_NETWORK') {
|
|
640
|
+
return reject(new RadarNetworkError());
|
|
641
|
+
}
|
|
642
|
+
if (xhr.status == 200) {
|
|
643
|
+
return resolve(response);
|
|
644
|
+
}
|
|
645
|
+
if (options.debug) {
|
|
646
|
+
Logger.debug("API call failed: ".concat(url));
|
|
647
|
+
Logger.debug(JSON.stringify(response));
|
|
648
|
+
}
|
|
649
|
+
if (xhr.status === 400) {
|
|
650
|
+
reject(new RadarBadRequestError(response));
|
|
651
|
+
}
|
|
652
|
+
else if (xhr.status === 401) {
|
|
653
|
+
reject(new RadarUnauthorizedError(response));
|
|
654
|
+
}
|
|
655
|
+
else if (xhr.status === 402) {
|
|
656
|
+
reject(new RadarPaymentRequiredError(response));
|
|
657
|
+
}
|
|
658
|
+
else if (xhr.status === 403) {
|
|
659
|
+
reject(new RadarForbiddenError(response));
|
|
660
|
+
}
|
|
661
|
+
else if (xhr.status === 404) {
|
|
662
|
+
reject(new RadarNotFoundError(response));
|
|
663
|
+
}
|
|
664
|
+
else if (xhr.status === 429) {
|
|
665
|
+
reject(new RadarRateLimitError(response));
|
|
666
|
+
}
|
|
667
|
+
else if (500 <= xhr.status && xhr.status < 600) {
|
|
668
|
+
reject(new RadarServerError(response));
|
|
669
|
+
}
|
|
670
|
+
else {
|
|
671
|
+
reject(new RadarUnknownError(response));
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
xhr.onerror = function () {
|
|
675
|
+
if (host && (host === 'http://localhost:52516' || host === 'https://radar-verify.com:52516')) {
|
|
676
|
+
reject(new RadarVerifyAppError());
|
|
677
|
+
}
|
|
678
|
+
else {
|
|
679
|
+
reject(new RadarServerError());
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
xhr.ontimeout = function () {
|
|
683
|
+
reject(new RadarVerifyAppError());
|
|
684
|
+
};
|
|
685
|
+
xhr.send(JSON.stringify(body));
|
|
686
|
+
})];
|
|
535
687
|
});
|
|
536
688
|
});
|
|
537
|
-
}
|
|
538
|
-
|
|
689
|
+
};
|
|
690
|
+
return Http;
|
|
691
|
+
}());
|
|
539
692
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
693
|
+
var AddressesAPI = /** @class */ (function () {
|
|
694
|
+
function AddressesAPI() {
|
|
695
|
+
}
|
|
696
|
+
AddressesAPI.validateAddress = function (params) {
|
|
697
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
698
|
+
var options, response, address, result, validateAddressRes;
|
|
699
|
+
return __generator(this, function (_a) {
|
|
700
|
+
switch (_a.label) {
|
|
701
|
+
case 0:
|
|
702
|
+
options = Config.get();
|
|
703
|
+
return [4 /*yield*/, Http.request({
|
|
704
|
+
method: 'GET',
|
|
705
|
+
path: 'addresses/validate',
|
|
706
|
+
data: params,
|
|
707
|
+
})];
|
|
708
|
+
case 1:
|
|
709
|
+
response = _a.sent();
|
|
710
|
+
address = response.address, result = response.result;
|
|
711
|
+
validateAddressRes = {
|
|
712
|
+
address: address,
|
|
713
|
+
result: result,
|
|
714
|
+
};
|
|
715
|
+
if (options.debug) {
|
|
716
|
+
validateAddressRes.response = response;
|
|
717
|
+
}
|
|
718
|
+
return [2 /*return*/, validateAddressRes];
|
|
719
|
+
}
|
|
548
720
|
});
|
|
549
|
-
const { address, result } = response;
|
|
550
|
-
const validateAddressRes = {
|
|
551
|
-
address,
|
|
552
|
-
result,
|
|
553
|
-
};
|
|
554
|
-
if (options.debug) {
|
|
555
|
-
validateAddressRes.response = response;
|
|
556
|
-
}
|
|
557
|
-
return validateAddressRes;
|
|
558
721
|
});
|
|
559
|
-
}
|
|
560
|
-
|
|
722
|
+
};
|
|
723
|
+
return AddressesAPI;
|
|
724
|
+
}());
|
|
561
725
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
726
|
+
var generateUUID = function () {
|
|
727
|
+
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (char) {
|
|
728
|
+
var r = Math.random() * 16 | 0;
|
|
729
|
+
var v = (char == 'x') ? r : (r & 0x3 | 0x8);
|
|
566
730
|
return v.toString(16);
|
|
567
731
|
});
|
|
568
732
|
return uuid;
|
|
569
733
|
};
|
|
570
|
-
|
|
571
|
-
|
|
734
|
+
var Device = /** @class */ (function () {
|
|
735
|
+
function Device() {
|
|
736
|
+
}
|
|
737
|
+
Device.getDeviceId = function () {
|
|
572
738
|
// use existing deviceId if present
|
|
573
|
-
|
|
739
|
+
var deviceId = Storage.getItem(Storage.DEVICE_ID);
|
|
574
740
|
if (deviceId) {
|
|
575
741
|
return deviceId;
|
|
576
742
|
}
|
|
577
743
|
// generate new deviceId
|
|
578
|
-
|
|
744
|
+
var uuid = generateUUID();
|
|
579
745
|
Storage.setItem(Storage.DEVICE_ID, uuid);
|
|
580
746
|
return uuid;
|
|
581
|
-
}
|
|
582
|
-
|
|
747
|
+
};
|
|
748
|
+
Device.getInstallId = function () {
|
|
583
749
|
// use existing installId if present
|
|
584
|
-
|
|
750
|
+
var deviceId = Storage.getItem(Storage.INSTALL_ID);
|
|
585
751
|
if (deviceId) {
|
|
586
752
|
return deviceId;
|
|
587
753
|
}
|
|
588
754
|
// generate new installId
|
|
589
|
-
|
|
755
|
+
var uuid = generateUUID();
|
|
590
756
|
Storage.setItem(Storage.INSTALL_ID, uuid);
|
|
591
757
|
return uuid;
|
|
592
|
-
}
|
|
593
|
-
|
|
758
|
+
};
|
|
759
|
+
return Device;
|
|
760
|
+
}());
|
|
594
761
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
762
|
+
var SESSION_TIMEOUT_SECS = 300; // 5 mins
|
|
763
|
+
var isValid = function (sessionId) {
|
|
764
|
+
var now = Math.trunc(Date.now() / 1000);
|
|
765
|
+
var session = Number.parseInt(sessionId);
|
|
766
|
+
var diff = Math.abs(now - session);
|
|
600
767
|
return diff < SESSION_TIMEOUT_SECS;
|
|
601
768
|
};
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
769
|
+
var Session = /** @class */ (function () {
|
|
770
|
+
function Session() {
|
|
771
|
+
}
|
|
772
|
+
Session.getSessionId = function () {
|
|
773
|
+
var sessionId = Storage.getItem(Storage.SESSION_ID);
|
|
605
774
|
// reuse session if still within 5 min threshold
|
|
606
775
|
if (sessionId && isValid(sessionId)) {
|
|
607
776
|
return sessionId;
|
|
608
777
|
}
|
|
609
778
|
// create new session if does not already exist or expired
|
|
610
|
-
|
|
779
|
+
var newSessionId = Math.trunc(Date.now() / 1000).toString(); // unix ts in seconds
|
|
611
780
|
Storage.setItem(Storage.SESSION_ID, newSessionId);
|
|
612
781
|
return newSessionId;
|
|
613
|
-
}
|
|
614
|
-
|
|
782
|
+
};
|
|
783
|
+
return Session;
|
|
784
|
+
}());
|
|
615
785
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
786
|
+
var ConfigAPI = /** @class */ (function () {
|
|
787
|
+
function ConfigAPI() {
|
|
788
|
+
}
|
|
789
|
+
ConfigAPI.getConfig = function (params) {
|
|
790
|
+
if (params === void 0) { params = {}; }
|
|
791
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
792
|
+
var options, deviceId, installId, sessionId, locationAuthorization, data, err_1;
|
|
793
|
+
return __generator(this, function (_a) {
|
|
794
|
+
switch (_a.label) {
|
|
795
|
+
case 0:
|
|
796
|
+
options = Config.get();
|
|
797
|
+
if (options.version != 'v1') {
|
|
798
|
+
Logger.info('Skipping /config call.');
|
|
799
|
+
return [2 /*return*/];
|
|
800
|
+
}
|
|
801
|
+
deviceId = params.deviceId || Device.getDeviceId();
|
|
802
|
+
installId = params.installId || Device.getInstallId();
|
|
803
|
+
sessionId = Session.getSessionId();
|
|
804
|
+
return [4 /*yield*/, Navigator.getPermissionStatus()];
|
|
805
|
+
case 1:
|
|
806
|
+
locationAuthorization = _a.sent();
|
|
807
|
+
data = {
|
|
808
|
+
deviceId: deviceId,
|
|
809
|
+
installId: installId,
|
|
810
|
+
sessionId: sessionId,
|
|
811
|
+
locationAuthorization: locationAuthorization,
|
|
812
|
+
};
|
|
813
|
+
_a.label = 2;
|
|
814
|
+
case 2:
|
|
815
|
+
_a.trys.push([2, 4, , 5]);
|
|
816
|
+
return [4 /*yield*/, Http.request({
|
|
817
|
+
method: 'GET',
|
|
818
|
+
path: 'config',
|
|
819
|
+
data: data,
|
|
820
|
+
})];
|
|
821
|
+
case 3:
|
|
822
|
+
_a.sent();
|
|
823
|
+
return [3 /*break*/, 5];
|
|
824
|
+
case 4:
|
|
825
|
+
err_1 = _a.sent();
|
|
826
|
+
Logger.warn("Error calling /config: ".concat(err_1.message));
|
|
827
|
+
return [3 /*break*/, 5];
|
|
828
|
+
case 5: return [2 /*return*/];
|
|
829
|
+
}
|
|
830
|
+
});
|
|
644
831
|
});
|
|
645
|
-
}
|
|
646
|
-
|
|
832
|
+
};
|
|
833
|
+
return ConfigAPI;
|
|
834
|
+
}());
|
|
647
835
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
836
|
+
var ContextAPI = /** @class */ (function () {
|
|
837
|
+
function ContextAPI() {
|
|
838
|
+
}
|
|
839
|
+
ContextAPI.getContext = function (location) {
|
|
840
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
841
|
+
var options, latitude, longitude, accuracy, response, geofences, place, country, state, dma, postalCode, contextRes;
|
|
842
|
+
return __generator(this, function (_a) {
|
|
843
|
+
switch (_a.label) {
|
|
844
|
+
case 0:
|
|
845
|
+
options = Config.get();
|
|
846
|
+
if (!(!location.latitude || !location.longitude)) return [3 /*break*/, 2];
|
|
847
|
+
return [4 /*yield*/, Navigator.getCurrentPosition()];
|
|
848
|
+
case 1:
|
|
849
|
+
location = _a.sent();
|
|
850
|
+
_a.label = 2;
|
|
851
|
+
case 2:
|
|
852
|
+
latitude = location.latitude, longitude = location.longitude, accuracy = location.accuracy;
|
|
853
|
+
return [4 /*yield*/, Http.request({
|
|
854
|
+
method: 'GET',
|
|
855
|
+
path: 'context',
|
|
856
|
+
data: {
|
|
857
|
+
coordinates: "".concat(latitude, ",").concat(longitude),
|
|
858
|
+
accuracy: accuracy,
|
|
859
|
+
},
|
|
860
|
+
})];
|
|
861
|
+
case 3:
|
|
862
|
+
response = _a.sent();
|
|
863
|
+
geofences = response.geofences, place = response.place, country = response.country, state = response.state, dma = response.dma, postalCode = response.postalCode;
|
|
864
|
+
contextRes = {
|
|
865
|
+
location: location,
|
|
866
|
+
geofences: geofences,
|
|
867
|
+
place: place,
|
|
868
|
+
country: country,
|
|
869
|
+
state: state,
|
|
870
|
+
dma: dma,
|
|
871
|
+
postalCode: postalCode,
|
|
872
|
+
};
|
|
873
|
+
if (options.debug) {
|
|
874
|
+
contextRes.response = response;
|
|
875
|
+
}
|
|
876
|
+
return [2 /*return*/, contextRes];
|
|
877
|
+
}
|
|
664
878
|
});
|
|
665
|
-
const { geofences, place, country, state, dma, postalCode, } = response;
|
|
666
|
-
const contextRes = {
|
|
667
|
-
location,
|
|
668
|
-
geofences,
|
|
669
|
-
place,
|
|
670
|
-
country,
|
|
671
|
-
state,
|
|
672
|
-
dma,
|
|
673
|
-
postalCode,
|
|
674
|
-
};
|
|
675
|
-
if (options.debug) {
|
|
676
|
-
contextRes.response = response;
|
|
677
|
-
}
|
|
678
|
-
return contextRes;
|
|
679
879
|
});
|
|
680
|
-
}
|
|
681
|
-
|
|
880
|
+
};
|
|
881
|
+
return ContextAPI;
|
|
882
|
+
}());
|
|
682
883
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
884
|
+
var ConversionsAPI = /** @class */ (function () {
|
|
885
|
+
function ConversionsAPI() {
|
|
886
|
+
}
|
|
887
|
+
ConversionsAPI.logConversion = function (params) {
|
|
888
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
889
|
+
var options, name, userId, deviceId, installId, metadata, createdAt, data, response, conversionRes;
|
|
890
|
+
return __generator(this, function (_a) {
|
|
891
|
+
switch (_a.label) {
|
|
892
|
+
case 0:
|
|
893
|
+
options = Config.get();
|
|
894
|
+
name = params.name;
|
|
895
|
+
userId = params.userId || Storage.getItem(Storage.USER_ID);
|
|
896
|
+
deviceId = params.deviceId || Device.getDeviceId();
|
|
897
|
+
installId = params.installId || Device.getInstallId();
|
|
898
|
+
metadata = params.metadata || {};
|
|
899
|
+
createdAt = params.createdAt;
|
|
900
|
+
if (params.revenue) {
|
|
901
|
+
metadata.revenue = params.revenue;
|
|
902
|
+
}
|
|
903
|
+
data = {
|
|
904
|
+
name: name,
|
|
905
|
+
userId: userId,
|
|
906
|
+
deviceId: deviceId,
|
|
907
|
+
installId: installId,
|
|
908
|
+
metadata: metadata,
|
|
909
|
+
};
|
|
910
|
+
if (typeof createdAt === 'string') {
|
|
911
|
+
data.createdAt = createdAt;
|
|
912
|
+
}
|
|
913
|
+
else if (createdAt instanceof Date) {
|
|
914
|
+
data.createdAt = createdAt.toISOString();
|
|
915
|
+
}
|
|
916
|
+
else {
|
|
917
|
+
data.createdAt = (new Date()).toISOString();
|
|
918
|
+
}
|
|
919
|
+
return [4 /*yield*/, Http.request({
|
|
920
|
+
method: 'POST',
|
|
921
|
+
path: 'events',
|
|
922
|
+
data: data,
|
|
923
|
+
})];
|
|
924
|
+
case 1:
|
|
925
|
+
response = _a.sent();
|
|
926
|
+
conversionRes = {
|
|
927
|
+
event: response.event,
|
|
928
|
+
};
|
|
929
|
+
if (options.debug) {
|
|
930
|
+
conversionRes.response = response;
|
|
931
|
+
}
|
|
932
|
+
return [2 /*return*/, conversionRes];
|
|
933
|
+
}
|
|
716
934
|
});
|
|
717
|
-
const conversionRes = {
|
|
718
|
-
event: response.event,
|
|
719
|
-
};
|
|
720
|
-
if (options.debug) {
|
|
721
|
-
conversionRes.response = response;
|
|
722
|
-
}
|
|
723
|
-
return conversionRes;
|
|
724
935
|
});
|
|
725
|
-
}
|
|
726
|
-
|
|
936
|
+
};
|
|
937
|
+
return ConversionsAPI;
|
|
938
|
+
}());
|
|
727
939
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
940
|
+
var Geocoding = /** @class */ (function () {
|
|
941
|
+
function Geocoding() {
|
|
942
|
+
}
|
|
943
|
+
Geocoding.forwardGeocode = function (params) {
|
|
944
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
945
|
+
var options, query, layers, country, response, forwardGeocodeRes;
|
|
946
|
+
return __generator(this, function (_a) {
|
|
947
|
+
switch (_a.label) {
|
|
948
|
+
case 0:
|
|
949
|
+
options = Config.get();
|
|
950
|
+
query = params.query, layers = params.layers, country = params.country;
|
|
951
|
+
return [4 /*yield*/, Http.request({
|
|
952
|
+
method: 'GET',
|
|
953
|
+
path: 'geocode/forward',
|
|
954
|
+
data: {
|
|
955
|
+
query: query,
|
|
956
|
+
layers: layers,
|
|
957
|
+
country: country,
|
|
958
|
+
},
|
|
959
|
+
})];
|
|
960
|
+
case 1:
|
|
961
|
+
response = _a.sent();
|
|
962
|
+
forwardGeocodeRes = {
|
|
963
|
+
addresses: response.addresses,
|
|
964
|
+
};
|
|
965
|
+
if (options.debug) {
|
|
966
|
+
forwardGeocodeRes.response = response;
|
|
967
|
+
}
|
|
968
|
+
return [2 /*return*/, forwardGeocodeRes];
|
|
969
|
+
}
|
|
741
970
|
});
|
|
742
|
-
const forwardGeocodeRes = {
|
|
743
|
-
addresses: response.addresses,
|
|
744
|
-
};
|
|
745
|
-
if (options.debug) {
|
|
746
|
-
forwardGeocodeRes.response = response;
|
|
747
|
-
}
|
|
748
|
-
return forwardGeocodeRes;
|
|
749
971
|
});
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
return __awaiter(this, void 0, void 0, function
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
972
|
+
};
|
|
973
|
+
Geocoding.reverseGeocode = function (params) {
|
|
974
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
975
|
+
var options, latitude, longitude, layers, location_1, response, reverseGeocodeRes;
|
|
976
|
+
return __generator(this, function (_a) {
|
|
977
|
+
switch (_a.label) {
|
|
978
|
+
case 0:
|
|
979
|
+
options = Config.get();
|
|
980
|
+
latitude = params.latitude, longitude = params.longitude, layers = params.layers;
|
|
981
|
+
if (!(!latitude || !longitude)) return [3 /*break*/, 2];
|
|
982
|
+
return [4 /*yield*/, Navigator.getCurrentPosition()];
|
|
983
|
+
case 1:
|
|
984
|
+
location_1 = _a.sent();
|
|
985
|
+
latitude = location_1.latitude;
|
|
986
|
+
longitude = location_1.longitude;
|
|
987
|
+
_a.label = 2;
|
|
988
|
+
case 2: return [4 /*yield*/, Http.request({
|
|
989
|
+
method: 'GET',
|
|
990
|
+
path: 'geocode/reverse',
|
|
991
|
+
data: {
|
|
992
|
+
coordinates: "".concat(latitude, ",").concat(longitude),
|
|
993
|
+
layers: layers,
|
|
994
|
+
},
|
|
995
|
+
})];
|
|
996
|
+
case 3:
|
|
997
|
+
response = _a.sent();
|
|
998
|
+
reverseGeocodeRes = {
|
|
999
|
+
addresses: response.addresses,
|
|
1000
|
+
};
|
|
1001
|
+
if (options.debug) {
|
|
1002
|
+
reverseGeocodeRes.response = response;
|
|
1003
|
+
}
|
|
1004
|
+
return [2 /*return*/, reverseGeocodeRes];
|
|
1005
|
+
}
|
|
767
1006
|
});
|
|
768
|
-
const reverseGeocodeRes = {
|
|
769
|
-
addresses: response.addresses,
|
|
770
|
-
};
|
|
771
|
-
if (options.debug) {
|
|
772
|
-
reverseGeocodeRes.response = response;
|
|
773
|
-
}
|
|
774
|
-
return reverseGeocodeRes;
|
|
775
1007
|
});
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
return __awaiter(this, void 0, void 0, function
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
1008
|
+
};
|
|
1009
|
+
Geocoding.ipGeocode = function () {
|
|
1010
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1011
|
+
var options, response, ipGeocodeRes;
|
|
1012
|
+
return __generator(this, function (_a) {
|
|
1013
|
+
switch (_a.label) {
|
|
1014
|
+
case 0:
|
|
1015
|
+
options = Config.get();
|
|
1016
|
+
return [4 /*yield*/, Http.request({
|
|
1017
|
+
method: 'GET',
|
|
1018
|
+
path: 'geocode/ip',
|
|
1019
|
+
})];
|
|
1020
|
+
case 1:
|
|
1021
|
+
response = _a.sent();
|
|
1022
|
+
ipGeocodeRes = {
|
|
1023
|
+
ip: response.ip,
|
|
1024
|
+
address: response.address,
|
|
1025
|
+
proxy: response.proxy,
|
|
1026
|
+
};
|
|
1027
|
+
if (options.debug) {
|
|
1028
|
+
ipGeocodeRes.response = response;
|
|
1029
|
+
}
|
|
1030
|
+
return [2 /*return*/, ipGeocodeRes];
|
|
1031
|
+
}
|
|
783
1032
|
});
|
|
784
|
-
const ipGeocodeRes = {
|
|
785
|
-
ip: response.ip,
|
|
786
|
-
address: response.address,
|
|
787
|
-
proxy: response.proxy,
|
|
788
|
-
};
|
|
789
|
-
if (options.debug) {
|
|
790
|
-
ipGeocodeRes.response = response;
|
|
791
|
-
}
|
|
792
|
-
return ipGeocodeRes;
|
|
793
1033
|
});
|
|
794
|
-
}
|
|
795
|
-
|
|
1034
|
+
};
|
|
1035
|
+
return Geocoding;
|
|
1036
|
+
}());
|
|
796
1037
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
1038
|
+
var RoutingAPI = /** @class */ (function () {
|
|
1039
|
+
function RoutingAPI() {
|
|
1040
|
+
}
|
|
1041
|
+
RoutingAPI.distance = function (params) {
|
|
1042
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1043
|
+
var options, origin, destination, modes, units, geometry, geometryPoints, avoid, _a, latitude, longitude, latitude, longitude, latitude, longitude, response, distanceRes;
|
|
1044
|
+
return __generator(this, function (_b) {
|
|
1045
|
+
switch (_b.label) {
|
|
1046
|
+
case 0:
|
|
1047
|
+
options = Config.get();
|
|
1048
|
+
origin = params.origin, destination = params.destination, modes = params.modes, units = params.units, geometry = params.geometry, geometryPoints = params.geometryPoints, avoid = params.avoid;
|
|
1049
|
+
if (!!origin) return [3 /*break*/, 2];
|
|
1050
|
+
return [4 /*yield*/, Navigator.getCurrentPosition()];
|
|
1051
|
+
case 1:
|
|
1052
|
+
_a = _b.sent(), latitude = _a.latitude, longitude = _a.longitude;
|
|
1053
|
+
origin = "".concat(latitude, ",").concat(longitude);
|
|
1054
|
+
return [3 /*break*/, 3];
|
|
1055
|
+
case 2:
|
|
1056
|
+
if (typeof origin !== 'string') { // origin is "Location" object
|
|
1057
|
+
latitude = origin.latitude, longitude = origin.longitude;
|
|
1058
|
+
origin = "".concat(latitude, ",").concat(longitude);
|
|
1059
|
+
}
|
|
1060
|
+
_b.label = 3;
|
|
1061
|
+
case 3:
|
|
1062
|
+
if (typeof destination !== 'string') {
|
|
1063
|
+
latitude = destination.latitude, longitude = destination.longitude;
|
|
1064
|
+
destination = "".concat(latitude, ",").concat(longitude);
|
|
1065
|
+
}
|
|
1066
|
+
if (Array.isArray(modes)) {
|
|
1067
|
+
modes = modes.join(',');
|
|
1068
|
+
}
|
|
1069
|
+
if (Array.isArray(avoid)) {
|
|
1070
|
+
avoid = avoid.join(',');
|
|
1071
|
+
}
|
|
1072
|
+
return [4 /*yield*/, Http.request({
|
|
1073
|
+
method: 'GET',
|
|
1074
|
+
path: 'route/distance',
|
|
1075
|
+
data: {
|
|
1076
|
+
origin: origin,
|
|
1077
|
+
destination: destination,
|
|
1078
|
+
modes: modes,
|
|
1079
|
+
units: units,
|
|
1080
|
+
geometry: geometry,
|
|
1081
|
+
geometryPoints: geometryPoints,
|
|
1082
|
+
avoid: avoid,
|
|
1083
|
+
},
|
|
1084
|
+
})];
|
|
1085
|
+
case 4:
|
|
1086
|
+
response = _b.sent();
|
|
1087
|
+
distanceRes = {
|
|
1088
|
+
routes: response.routes,
|
|
1089
|
+
};
|
|
1090
|
+
if (options.debug) {
|
|
1091
|
+
distanceRes.response = response;
|
|
1092
|
+
}
|
|
1093
|
+
return [2 /*return*/, distanceRes];
|
|
1094
|
+
}
|
|
833
1095
|
});
|
|
834
|
-
const distanceRes = {
|
|
835
|
-
routes: response.routes,
|
|
836
|
-
};
|
|
837
|
-
if (options.debug) {
|
|
838
|
-
distanceRes.response = response;
|
|
839
|
-
}
|
|
840
|
-
return distanceRes;
|
|
841
1096
|
});
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
return __awaiter(this, void 0, void 0, function
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
1097
|
+
};
|
|
1098
|
+
RoutingAPI.matrix = function (params) {
|
|
1099
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1100
|
+
var options, origins, destinations, mode, units, avoid, _a, latitude, longitude, originStrings, i, response, matrixRes;
|
|
1101
|
+
return __generator(this, function (_b) {
|
|
1102
|
+
switch (_b.label) {
|
|
1103
|
+
case 0:
|
|
1104
|
+
options = Config.get();
|
|
1105
|
+
origins = params.origins, destinations = params.destinations, mode = params.mode, units = params.units, avoid = params.avoid;
|
|
1106
|
+
if (!!origins) return [3 /*break*/, 2];
|
|
1107
|
+
return [4 /*yield*/, Navigator.getCurrentPosition()];
|
|
1108
|
+
case 1:
|
|
1109
|
+
_a = _b.sent(), latitude = _a.latitude, longitude = _a.longitude;
|
|
1110
|
+
originStrings = [];
|
|
1111
|
+
for (i = 0; i < destinations.length; i++) {
|
|
1112
|
+
originStrings.push("".concat(latitude, ",").concat(longitude));
|
|
1113
|
+
}
|
|
1114
|
+
origins = originStrings.join('|');
|
|
1115
|
+
return [3 /*break*/, 3];
|
|
1116
|
+
case 2:
|
|
1117
|
+
if (Array.isArray(origins)) { // origin is a list of "Location" objects
|
|
1118
|
+
origins = origins.map(function (location) { return "".concat(location.latitude, ",").concat(location.longitude); }).join('|');
|
|
1119
|
+
}
|
|
1120
|
+
_b.label = 3;
|
|
1121
|
+
case 3:
|
|
1122
|
+
// convert array to pipe-delimited string
|
|
1123
|
+
if (Array.isArray(destinations)) {
|
|
1124
|
+
destinations = destinations.map(function (location) { return "".concat(location.latitude, ",").concat(location.longitude); }).join('|');
|
|
1125
|
+
}
|
|
1126
|
+
if (Array.isArray(avoid)) {
|
|
1127
|
+
avoid = avoid.join(',');
|
|
1128
|
+
}
|
|
1129
|
+
return [4 /*yield*/, Http.request({
|
|
1130
|
+
method: 'GET',
|
|
1131
|
+
path: 'route/matrix',
|
|
1132
|
+
data: {
|
|
1133
|
+
origins: origins,
|
|
1134
|
+
destinations: destinations,
|
|
1135
|
+
mode: mode,
|
|
1136
|
+
units: units,
|
|
1137
|
+
avoid: avoid,
|
|
1138
|
+
},
|
|
1139
|
+
})];
|
|
1140
|
+
case 4:
|
|
1141
|
+
response = _b.sent();
|
|
1142
|
+
matrixRes = {
|
|
1143
|
+
origins: response.origins,
|
|
1144
|
+
destinations: response.destinations,
|
|
1145
|
+
matrix: response.matrix,
|
|
1146
|
+
};
|
|
1147
|
+
if (options.debug) {
|
|
1148
|
+
matrixRes.response = response;
|
|
1149
|
+
}
|
|
1150
|
+
return [2 /*return*/, matrixRes];
|
|
853
1151
|
}
|
|
854
|
-
origins = originStrings.join('|');
|
|
855
|
-
}
|
|
856
|
-
else if (Array.isArray(origins)) { // origin is a list of "Location" objects
|
|
857
|
-
origins = origins.map((location) => `${location.latitude},${location.longitude}`).join('|');
|
|
858
|
-
}
|
|
859
|
-
// convert array to pipe-delimited string
|
|
860
|
-
if (Array.isArray(destinations)) {
|
|
861
|
-
destinations = destinations.map((location) => `${location.latitude},${location.longitude}`).join('|');
|
|
862
|
-
}
|
|
863
|
-
if (Array.isArray(avoid)) {
|
|
864
|
-
avoid = avoid.join(',');
|
|
865
|
-
}
|
|
866
|
-
const response = yield Http.request({
|
|
867
|
-
method: 'GET',
|
|
868
|
-
path: 'route/matrix',
|
|
869
|
-
data: {
|
|
870
|
-
origins,
|
|
871
|
-
destinations,
|
|
872
|
-
mode,
|
|
873
|
-
units,
|
|
874
|
-
avoid,
|
|
875
|
-
},
|
|
876
1152
|
});
|
|
877
|
-
const matrixRes = {
|
|
878
|
-
origins: response.origins,
|
|
879
|
-
destinations: response.destinations,
|
|
880
|
-
matrix: response.matrix,
|
|
881
|
-
};
|
|
882
|
-
if (options.debug) {
|
|
883
|
-
matrixRes.response = response;
|
|
884
|
-
}
|
|
885
|
-
return matrixRes;
|
|
886
1153
|
});
|
|
887
|
-
}
|
|
888
|
-
|
|
1154
|
+
};
|
|
1155
|
+
return RoutingAPI;
|
|
1156
|
+
}());
|
|
889
1157
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
1158
|
+
var SearchAPI = /** @class */ (function () {
|
|
1159
|
+
function SearchAPI() {
|
|
1160
|
+
}
|
|
1161
|
+
SearchAPI.autocomplete = function (params) {
|
|
1162
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1163
|
+
var options, query, near, limit, layers, countryCode, expandUnits, mailable, response, autocompleteRes;
|
|
1164
|
+
return __generator(this, function (_a) {
|
|
1165
|
+
switch (_a.label) {
|
|
1166
|
+
case 0:
|
|
1167
|
+
options = Config.get();
|
|
1168
|
+
query = params.query, near = params.near, limit = params.limit, layers = params.layers, countryCode = params.countryCode, expandUnits = params.expandUnits, mailable = params.mailable;
|
|
1169
|
+
// near can be provided as a string or Location object
|
|
1170
|
+
// if "near" is not provided, request will fallback to IP based location
|
|
1171
|
+
if (near && typeof near !== 'string') {
|
|
1172
|
+
if (near.latitude && near.longitude) {
|
|
1173
|
+
near = "".concat(near.latitude, ",").concat(near.longitude);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
return [4 /*yield*/, Http.request({
|
|
1177
|
+
method: 'GET',
|
|
1178
|
+
path: 'search/autocomplete',
|
|
1179
|
+
data: {
|
|
1180
|
+
query: query,
|
|
1181
|
+
near: near,
|
|
1182
|
+
limit: limit,
|
|
1183
|
+
layers: layers,
|
|
1184
|
+
countryCode: countryCode,
|
|
1185
|
+
expandUnits: expandUnits,
|
|
1186
|
+
mailable: mailable,
|
|
1187
|
+
},
|
|
1188
|
+
})];
|
|
1189
|
+
case 1:
|
|
1190
|
+
response = _a.sent();
|
|
1191
|
+
autocompleteRes = {
|
|
1192
|
+
addresses: response.addresses,
|
|
1193
|
+
};
|
|
1194
|
+
if (options.debug) {
|
|
1195
|
+
autocompleteRes.response = response;
|
|
1196
|
+
}
|
|
1197
|
+
return [2 /*return*/, autocompleteRes];
|
|
900
1198
|
}
|
|
901
|
-
}
|
|
902
|
-
const response = yield Http.request({
|
|
903
|
-
method: 'GET',
|
|
904
|
-
path: 'search/autocomplete',
|
|
905
|
-
data: {
|
|
906
|
-
query,
|
|
907
|
-
near,
|
|
908
|
-
limit,
|
|
909
|
-
layers,
|
|
910
|
-
countryCode,
|
|
911
|
-
expandUnits,
|
|
912
|
-
mailable,
|
|
913
|
-
},
|
|
914
1199
|
});
|
|
915
|
-
const autocompleteRes = {
|
|
916
|
-
addresses: response.addresses,
|
|
917
|
-
};
|
|
918
|
-
if (options.debug) {
|
|
919
|
-
autocompleteRes.response = response;
|
|
920
|
-
}
|
|
921
|
-
return autocompleteRes;
|
|
922
1200
|
});
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
return __awaiter(this, void 0, void 0, function
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1201
|
+
};
|
|
1202
|
+
SearchAPI.searchGeofences = function (params) {
|
|
1203
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1204
|
+
var options, near, radius, tags, metadata, limit, includeGeometry, _a, latitude, longitude, latitude, longitude, response, geofencesSearchRes;
|
|
1205
|
+
return __generator(this, function (_b) {
|
|
1206
|
+
switch (_b.label) {
|
|
1207
|
+
case 0:
|
|
1208
|
+
options = Config.get();
|
|
1209
|
+
near = params.near, radius = params.radius, tags = params.tags, metadata = params.metadata, limit = params.limit, includeGeometry = params.includeGeometry;
|
|
1210
|
+
if (!!near) return [3 /*break*/, 2];
|
|
1211
|
+
return [4 /*yield*/, Navigator.getCurrentPosition()];
|
|
1212
|
+
case 1:
|
|
1213
|
+
_a = _b.sent(), latitude = _a.latitude, longitude = _a.longitude;
|
|
1214
|
+
near = "".concat(latitude, ",").concat(longitude);
|
|
1215
|
+
return [3 /*break*/, 3];
|
|
1216
|
+
case 2:
|
|
1217
|
+
if (typeof near !== 'string') { // near is "Location" object
|
|
1218
|
+
latitude = near.latitude, longitude = near.longitude;
|
|
1219
|
+
near = "".concat(latitude, ",").concat(longitude);
|
|
1220
|
+
}
|
|
1221
|
+
_b.label = 3;
|
|
1222
|
+
case 3:
|
|
1223
|
+
// convert arrays to comma-strings
|
|
1224
|
+
if (Array.isArray(tags)) {
|
|
1225
|
+
tags = tags.join(',');
|
|
1226
|
+
}
|
|
1227
|
+
return [4 /*yield*/, Http.request({
|
|
1228
|
+
method: 'GET',
|
|
1229
|
+
path: 'search/geofences',
|
|
1230
|
+
data: {
|
|
1231
|
+
near: near,
|
|
1232
|
+
radius: radius,
|
|
1233
|
+
tags: tags,
|
|
1234
|
+
metadata: metadata,
|
|
1235
|
+
limit: limit,
|
|
1236
|
+
includeGeometry: includeGeometry,
|
|
1237
|
+
},
|
|
1238
|
+
})];
|
|
1239
|
+
case 4:
|
|
1240
|
+
response = _b.sent();
|
|
1241
|
+
geofencesSearchRes = {
|
|
1242
|
+
geofences: response.geofences,
|
|
1243
|
+
};
|
|
1244
|
+
if (options.debug) {
|
|
1245
|
+
geofencesSearchRes.response = response;
|
|
1246
|
+
}
|
|
1247
|
+
return [2 /*return*/, geofencesSearchRes];
|
|
1248
|
+
}
|
|
952
1249
|
});
|
|
953
|
-
const geofencesSearchRes = {
|
|
954
|
-
geofences: response.geofences,
|
|
955
|
-
};
|
|
956
|
-
if (options.debug) {
|
|
957
|
-
geofencesSearchRes.response = response;
|
|
958
|
-
}
|
|
959
|
-
return geofencesSearchRes;
|
|
960
1250
|
});
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
return __awaiter(this, void 0, void 0, function
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1251
|
+
};
|
|
1252
|
+
SearchAPI.searchPlaces = function (params) {
|
|
1253
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1254
|
+
var options, near, radius, chains, categories, groups, limit, _a, latitude, longitude, latitude, longitude, response, placeSearchRes;
|
|
1255
|
+
return __generator(this, function (_b) {
|
|
1256
|
+
switch (_b.label) {
|
|
1257
|
+
case 0:
|
|
1258
|
+
options = Config.get();
|
|
1259
|
+
near = params.near, radius = params.radius, chains = params.chains, categories = params.categories, groups = params.groups, limit = params.limit;
|
|
1260
|
+
if (!!near) return [3 /*break*/, 2];
|
|
1261
|
+
return [4 /*yield*/, Navigator.getCurrentPosition()];
|
|
1262
|
+
case 1:
|
|
1263
|
+
_a = _b.sent(), latitude = _a.latitude, longitude = _a.longitude;
|
|
1264
|
+
near = "".concat(latitude, ",").concat(longitude);
|
|
1265
|
+
return [3 /*break*/, 3];
|
|
1266
|
+
case 2:
|
|
1267
|
+
if (typeof near !== 'string') { // near is "Location" object
|
|
1268
|
+
latitude = near.latitude, longitude = near.longitude;
|
|
1269
|
+
near = "".concat(latitude, ",").concat(longitude);
|
|
1270
|
+
}
|
|
1271
|
+
_b.label = 3;
|
|
1272
|
+
case 3:
|
|
1273
|
+
// convert arrays to comma-strings
|
|
1274
|
+
if (Array.isArray(chains)) {
|
|
1275
|
+
chains = chains.join(',');
|
|
1276
|
+
}
|
|
1277
|
+
if (Array.isArray(categories)) {
|
|
1278
|
+
categories = categories.join(',');
|
|
1279
|
+
}
|
|
1280
|
+
if (Array.isArray(groups)) {
|
|
1281
|
+
groups = groups.join(',');
|
|
1282
|
+
}
|
|
1283
|
+
return [4 /*yield*/, Http.request({
|
|
1284
|
+
method: 'GET',
|
|
1285
|
+
path: 'search/places',
|
|
1286
|
+
data: {
|
|
1287
|
+
near: near,
|
|
1288
|
+
radius: radius,
|
|
1289
|
+
chains: chains,
|
|
1290
|
+
categories: categories,
|
|
1291
|
+
groups: groups,
|
|
1292
|
+
limit: limit,
|
|
1293
|
+
},
|
|
1294
|
+
})];
|
|
1295
|
+
case 4:
|
|
1296
|
+
response = _b.sent();
|
|
1297
|
+
placeSearchRes = {
|
|
1298
|
+
places: response.places,
|
|
1299
|
+
};
|
|
1300
|
+
if (options.debug) {
|
|
1301
|
+
placeSearchRes.response = response;
|
|
1302
|
+
}
|
|
1303
|
+
return [2 /*return*/, placeSearchRes];
|
|
1304
|
+
}
|
|
996
1305
|
});
|
|
997
|
-
const placeSearchRes = {
|
|
998
|
-
places: response.places,
|
|
999
|
-
};
|
|
1000
|
-
if (options.debug) {
|
|
1001
|
-
placeSearchRes.response = response;
|
|
1002
|
-
}
|
|
1003
|
-
return placeSearchRes;
|
|
1004
1306
|
});
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1307
|
+
};
|
|
1308
|
+
return SearchAPI;
|
|
1309
|
+
}());
|
|
1007
1310
|
|
|
1008
1311
|
// https://stackoverflow.com/a/44198641
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1312
|
+
var isValidDate = function (date) { return date && Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date); };
|
|
1313
|
+
var TripsAPI = /** @class */ (function () {
|
|
1314
|
+
function TripsAPI() {
|
|
1315
|
+
}
|
|
1316
|
+
TripsAPI.setTripOptions = function (tripOptions) {
|
|
1012
1317
|
if (!tripOptions) {
|
|
1013
1318
|
TripsAPI.clearTripOptions();
|
|
1014
1319
|
return;
|
|
1015
1320
|
}
|
|
1016
|
-
|
|
1017
|
-
Logger.debug(
|
|
1321
|
+
var tripOptionsString = JSON.stringify(tripOptions);
|
|
1322
|
+
Logger.debug("Saving trip options: ".concat(tripOptionsString));
|
|
1018
1323
|
Storage.setItem(Storage.TRIP_OPTIONS, tripOptionsString);
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1324
|
+
};
|
|
1325
|
+
TripsAPI.getTripOptions = function () {
|
|
1326
|
+
var tripOptions = Storage.getItem(Storage.TRIP_OPTIONS);
|
|
1022
1327
|
if (tripOptions) {
|
|
1023
1328
|
tripOptions = JSON.parse(tripOptions);
|
|
1024
1329
|
}
|
|
1025
1330
|
return tripOptions;
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1331
|
+
};
|
|
1332
|
+
TripsAPI.clearTripOptions = function () {
|
|
1028
1333
|
Storage.removeItem(Storage.TRIP_OPTIONS);
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
return __awaiter(this, void 0, void 0, function
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1334
|
+
};
|
|
1335
|
+
TripsAPI.startTrip = function (tripOptions) {
|
|
1336
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1337
|
+
var options, userId, externalId, destinationGeofenceTag, destinationGeofenceExternalId, mode, metadata, approachingThreshold, scheduledArrivalAt, data, response, tripRes;
|
|
1338
|
+
return __generator(this, function (_a) {
|
|
1339
|
+
switch (_a.label) {
|
|
1340
|
+
case 0:
|
|
1341
|
+
options = Config.get();
|
|
1342
|
+
tripOptions = tripOptions || TripsAPI.getTripOptions();
|
|
1343
|
+
if (!tripOptions) {
|
|
1344
|
+
Logger.warn('tripOptions not set when calling "startTrip"');
|
|
1345
|
+
}
|
|
1346
|
+
userId = tripOptions.userId || Storage.getItem(Storage.USER_ID);
|
|
1347
|
+
if (userId && userId !== Storage.getItem(Storage.USER_ID)) {
|
|
1348
|
+
// set as userId for tracking if provided
|
|
1349
|
+
Storage.setItem(Storage.USER_ID, userId);
|
|
1350
|
+
}
|
|
1351
|
+
externalId = tripOptions.externalId, destinationGeofenceTag = tripOptions.destinationGeofenceTag, destinationGeofenceExternalId = tripOptions.destinationGeofenceExternalId, mode = tripOptions.mode, metadata = tripOptions.metadata, approachingThreshold = tripOptions.approachingThreshold, scheduledArrivalAt = tripOptions.scheduledArrivalAt;
|
|
1352
|
+
data = {
|
|
1353
|
+
userId: userId,
|
|
1354
|
+
externalId: externalId,
|
|
1355
|
+
destinationGeofenceTag: destinationGeofenceTag,
|
|
1356
|
+
destinationGeofenceExternalId: destinationGeofenceExternalId,
|
|
1357
|
+
mode: mode,
|
|
1358
|
+
metadata: metadata,
|
|
1359
|
+
approachingThreshold: approachingThreshold,
|
|
1360
|
+
};
|
|
1361
|
+
if (isValidDate(scheduledArrivalAt)) {
|
|
1362
|
+
data.scheduledArrivalAt = scheduledArrivalAt === null || scheduledArrivalAt === void 0 ? void 0 : scheduledArrivalAt.toJSON();
|
|
1363
|
+
}
|
|
1364
|
+
else {
|
|
1365
|
+
if (scheduledArrivalAt) {
|
|
1366
|
+
Logger.warn('Invalid date format for scheduledArrivalAt');
|
|
1367
|
+
}
|
|
1368
|
+
data.scheduledArrivalAt = undefined;
|
|
1369
|
+
}
|
|
1370
|
+
return [4 /*yield*/, Http.request({
|
|
1371
|
+
method: 'POST',
|
|
1372
|
+
path: 'trips',
|
|
1373
|
+
data: data,
|
|
1374
|
+
})];
|
|
1375
|
+
case 1:
|
|
1376
|
+
response = _a.sent();
|
|
1377
|
+
// save trip options
|
|
1378
|
+
TripsAPI.setTripOptions(tripOptions);
|
|
1379
|
+
tripRes = {
|
|
1380
|
+
trip: response.trip,
|
|
1381
|
+
events: response.events,
|
|
1382
|
+
};
|
|
1383
|
+
if (options.debug) {
|
|
1384
|
+
tripRes.response = response;
|
|
1385
|
+
}
|
|
1386
|
+
return [2 /*return*/, tripRes];
|
|
1058
1387
|
}
|
|
1059
|
-
data.scheduledArrivalAt = undefined;
|
|
1060
|
-
}
|
|
1061
|
-
const response = yield Http.request({
|
|
1062
|
-
method: 'POST',
|
|
1063
|
-
path: 'trips',
|
|
1064
|
-
data,
|
|
1065
1388
|
});
|
|
1066
|
-
// save trip options
|
|
1067
|
-
TripsAPI.setTripOptions(tripOptions);
|
|
1068
|
-
const tripRes = {
|
|
1069
|
-
trip: response.trip,
|
|
1070
|
-
events: response.events,
|
|
1071
|
-
};
|
|
1072
|
-
if (options.debug) {
|
|
1073
|
-
tripRes.response = response;
|
|
1074
|
-
}
|
|
1075
|
-
return tripRes;
|
|
1076
1389
|
});
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
return __awaiter(this, void 0, void 0, function
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1390
|
+
};
|
|
1391
|
+
TripsAPI.updateTrip = function (tripOptions, status) {
|
|
1392
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1393
|
+
var options, externalId, destinationGeofenceTag, destinationGeofenceExternalId, mode, metadata, approachingThreshold, scheduledArrivalAt, data, response, tripRes;
|
|
1394
|
+
return __generator(this, function (_a) {
|
|
1395
|
+
switch (_a.label) {
|
|
1396
|
+
case 0:
|
|
1397
|
+
options = Config.get();
|
|
1398
|
+
tripOptions = tripOptions || TripsAPI.getTripOptions();
|
|
1399
|
+
if (!tripOptions) {
|
|
1400
|
+
Logger.warn('tripOptions not set when calling "startTrip"');
|
|
1401
|
+
}
|
|
1402
|
+
externalId = tripOptions.externalId, destinationGeofenceTag = tripOptions.destinationGeofenceTag, destinationGeofenceExternalId = tripOptions.destinationGeofenceExternalId, mode = tripOptions.mode, metadata = tripOptions.metadata, approachingThreshold = tripOptions.approachingThreshold, scheduledArrivalAt = tripOptions.scheduledArrivalAt;
|
|
1403
|
+
data = {
|
|
1404
|
+
status: status,
|
|
1405
|
+
externalId: externalId,
|
|
1406
|
+
destinationGeofenceTag: destinationGeofenceTag,
|
|
1407
|
+
destinationGeofenceExternalId: destinationGeofenceExternalId,
|
|
1408
|
+
mode: mode,
|
|
1409
|
+
metadata: metadata,
|
|
1410
|
+
approachingThreshold: approachingThreshold,
|
|
1411
|
+
};
|
|
1412
|
+
if (isValidDate(scheduledArrivalAt)) {
|
|
1413
|
+
data.scheduledArrivalAt = scheduledArrivalAt === null || scheduledArrivalAt === void 0 ? void 0 : scheduledArrivalAt.toJSON();
|
|
1414
|
+
}
|
|
1415
|
+
else {
|
|
1416
|
+
if (scheduledArrivalAt) {
|
|
1417
|
+
Logger.warn('Invalid date format for scheduledArrivalAt');
|
|
1418
|
+
}
|
|
1419
|
+
data.scheduledArrivalAt = undefined;
|
|
1420
|
+
}
|
|
1421
|
+
return [4 /*yield*/, Http.request({
|
|
1422
|
+
method: 'PATCH',
|
|
1423
|
+
path: "trips/".concat(externalId, "/update"),
|
|
1424
|
+
data: data,
|
|
1425
|
+
})];
|
|
1426
|
+
case 1:
|
|
1427
|
+
response = _a.sent();
|
|
1428
|
+
tripRes = {
|
|
1429
|
+
trip: response.trip,
|
|
1430
|
+
events: response.events,
|
|
1431
|
+
};
|
|
1432
|
+
if (options.debug) {
|
|
1433
|
+
tripRes.response = response;
|
|
1434
|
+
}
|
|
1435
|
+
return [2 /*return*/, tripRes];
|
|
1101
1436
|
}
|
|
1102
|
-
data.scheduledArrivalAt = undefined;
|
|
1103
|
-
}
|
|
1104
|
-
const response = yield Http.request({
|
|
1105
|
-
method: 'PATCH',
|
|
1106
|
-
path: `trips/${externalId}/update`,
|
|
1107
|
-
data,
|
|
1108
1437
|
});
|
|
1109
|
-
const tripRes = {
|
|
1110
|
-
trip: response.trip,
|
|
1111
|
-
events: response.events,
|
|
1112
|
-
};
|
|
1113
|
-
if (options.debug) {
|
|
1114
|
-
tripRes.response = response;
|
|
1115
|
-
}
|
|
1116
|
-
return tripRes;
|
|
1117
1438
|
});
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
return __awaiter(this, void 0, void 0, function
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1439
|
+
};
|
|
1440
|
+
TripsAPI.completeTrip = function () {
|
|
1441
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1442
|
+
var tripOptions, tripResponse;
|
|
1443
|
+
return __generator(this, function (_a) {
|
|
1444
|
+
switch (_a.label) {
|
|
1445
|
+
case 0:
|
|
1446
|
+
tripOptions = TripsAPI.getTripOptions();
|
|
1447
|
+
return [4 /*yield*/, TripsAPI.updateTrip(tripOptions, 'completed')];
|
|
1448
|
+
case 1:
|
|
1449
|
+
tripResponse = _a.sent();
|
|
1450
|
+
// clear local trip options
|
|
1451
|
+
TripsAPI.clearTripOptions();
|
|
1452
|
+
return [2 /*return*/, tripResponse];
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1126
1455
|
});
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
return __awaiter(this, void 0, void 0, function
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1456
|
+
};
|
|
1457
|
+
TripsAPI.cancelTrip = function () {
|
|
1458
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1459
|
+
var tripOptions, tripResponse;
|
|
1460
|
+
return __generator(this, function (_a) {
|
|
1461
|
+
switch (_a.label) {
|
|
1462
|
+
case 0:
|
|
1463
|
+
tripOptions = TripsAPI.getTripOptions();
|
|
1464
|
+
return [4 /*yield*/, TripsAPI.updateTrip(tripOptions, 'canceled')];
|
|
1465
|
+
case 1:
|
|
1466
|
+
tripResponse = _a.sent();
|
|
1467
|
+
// clear local trip options
|
|
1468
|
+
TripsAPI.clearTripOptions();
|
|
1469
|
+
return [2 /*return*/, tripResponse];
|
|
1470
|
+
}
|
|
1471
|
+
});
|
|
1135
1472
|
});
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1473
|
+
};
|
|
1474
|
+
return TripsAPI;
|
|
1475
|
+
}());
|
|
1138
1476
|
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1477
|
+
var base64Encode = function (str) {
|
|
1478
|
+
return btoa(str).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
1479
|
+
};
|
|
1480
|
+
var signJWT = function (payload, key) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1481
|
+
var encoder, encodedHeader, encodedPayload, keyData, messageData, cryptoKey, signatureArrayBuffer, signature;
|
|
1482
|
+
return __generator(this, function (_a) {
|
|
1483
|
+
switch (_a.label) {
|
|
1484
|
+
case 0:
|
|
1485
|
+
encoder = new TextEncoder();
|
|
1486
|
+
encodedHeader = base64Encode(JSON.stringify({
|
|
1487
|
+
alg: 'HS256',
|
|
1488
|
+
typ: 'JWT',
|
|
1489
|
+
}));
|
|
1490
|
+
encodedPayload = base64Encode(JSON.stringify(payload));
|
|
1491
|
+
keyData = encoder.encode(key);
|
|
1492
|
+
messageData = encoder.encode("".concat(encodedHeader, ".").concat(encodedPayload));
|
|
1493
|
+
return [4 /*yield*/, crypto.subtle.importKey('raw', keyData, { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign'])];
|
|
1494
|
+
case 1:
|
|
1495
|
+
cryptoKey = _a.sent();
|
|
1496
|
+
return [4 /*yield*/, crypto.subtle.sign('HMAC', cryptoKey, messageData)];
|
|
1497
|
+
case 2:
|
|
1498
|
+
signatureArrayBuffer = _a.sent();
|
|
1499
|
+
signature = base64Encode(String.fromCharCode.apply(String, Array.from(new Uint8Array(signatureArrayBuffer))));
|
|
1500
|
+
return [2 /*return*/, "".concat(encodedHeader, ".").concat(encodedPayload, ".").concat(signature)];
|
|
1501
|
+
}
|
|
1502
|
+
});
|
|
1503
|
+
}); };
|
|
1154
1504
|
|
|
1155
|
-
|
|
1156
|
-
return new Promise((resolve)
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1505
|
+
var ping = function (host) {
|
|
1506
|
+
return new Promise(function (resolve) {
|
|
1507
|
+
var socket = new WebSocket(host);
|
|
1508
|
+
var pings = 0;
|
|
1509
|
+
var latencies = [];
|
|
1510
|
+
var pingInterval;
|
|
1511
|
+
var timeoutInterval;
|
|
1512
|
+
var ping = function () {
|
|
1163
1513
|
pings++;
|
|
1164
|
-
|
|
1514
|
+
var start = Date.now();
|
|
1165
1515
|
socket.send('ping');
|
|
1166
|
-
socket.onmessage = (event)
|
|
1516
|
+
socket.onmessage = function (event) {
|
|
1167
1517
|
if (event.data === 'pong') {
|
|
1168
|
-
|
|
1518
|
+
var latency = Date.now() - start;
|
|
1169
1519
|
latencies.push(latency);
|
|
1170
1520
|
if (pings >= 3) {
|
|
1171
1521
|
clearInterval(pingInterval);
|
|
1172
1522
|
clearInterval(timeoutInterval);
|
|
1173
|
-
|
|
1523
|
+
var median = latencies.sort(function (a, b) { return a - b; })[1];
|
|
1174
1524
|
socket.close();
|
|
1175
1525
|
resolve(median);
|
|
1176
1526
|
}
|
|
1177
1527
|
}
|
|
1178
1528
|
};
|
|
1179
1529
|
};
|
|
1180
|
-
|
|
1530
|
+
var timeout = function () {
|
|
1181
1531
|
Logger.warn('Socket timeout');
|
|
1182
1532
|
clearInterval(pingInterval);
|
|
1183
1533
|
clearInterval(timeoutInterval);
|
|
1184
1534
|
socket.close();
|
|
1185
1535
|
resolve(-1);
|
|
1186
1536
|
};
|
|
1187
|
-
socket.onerror = (err)
|
|
1537
|
+
socket.onerror = function (err) {
|
|
1188
1538
|
Logger.warn('Error opening socket');
|
|
1189
1539
|
socket.close();
|
|
1190
1540
|
resolve(-1);
|
|
1191
1541
|
};
|
|
1192
|
-
socket.onopen = ()
|
|
1542
|
+
socket.onopen = function () {
|
|
1193
1543
|
ping();
|
|
1194
1544
|
pingInterval = setInterval(ping, 1000);
|
|
1195
1545
|
timeoutInterval = setInterval(timeout, 10000);
|
|
@@ -1197,264 +1547,258 @@ const ping = (host) => {
|
|
|
1197
1547
|
});
|
|
1198
1548
|
};
|
|
1199
1549
|
|
|
1200
|
-
|
|
1201
|
-
|
|
1550
|
+
var TrackAPI = /** @class */ (function () {
|
|
1551
|
+
function TrackAPI() {
|
|
1552
|
+
}
|
|
1553
|
+
TrackAPI.trackOnce = function (params) {
|
|
1202
1554
|
var _a, _b, _c;
|
|
1203
|
-
return __awaiter(this, void 0, void 0, function
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
response.user
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1555
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1556
|
+
var options, latitude, longitude, accuracy, desiredAccuracy, fraud, deviceLocation, locationAuthorization, err_1, userId, deviceId, installId, sessionId, deviceType, description, timeZone, metadata, tripOptions, body, response, host, pingHost, lang, langs, dk, sclVal, cslVal, _d, sclRes, csl, scl, payload, reqToken, user_1, events_1, token, expiresAt, location_1, passed, expiresIn, trackRes_1, user, events, location, trackRes;
|
|
1557
|
+
return __generator(this, function (_e) {
|
|
1558
|
+
switch (_e.label) {
|
|
1559
|
+
case 0:
|
|
1560
|
+
options = Config.get();
|
|
1561
|
+
latitude = params.latitude, longitude = params.longitude, accuracy = params.accuracy, desiredAccuracy = params.desiredAccuracy, fraud = params.fraud;
|
|
1562
|
+
if (!(!latitude || !longitude)) return [3 /*break*/, 2];
|
|
1563
|
+
return [4 /*yield*/, Navigator.getCurrentPosition({ desiredAccuracy: desiredAccuracy })];
|
|
1564
|
+
case 1:
|
|
1565
|
+
deviceLocation = _e.sent();
|
|
1566
|
+
latitude = deviceLocation.latitude;
|
|
1567
|
+
longitude = deviceLocation.longitude;
|
|
1568
|
+
accuracy = deviceLocation.accuracy;
|
|
1569
|
+
_e.label = 2;
|
|
1570
|
+
case 2:
|
|
1571
|
+
_e.trys.push([2, 4, , 5]);
|
|
1572
|
+
return [4 /*yield*/, Navigator.getPermissionStatus()];
|
|
1573
|
+
case 3:
|
|
1574
|
+
locationAuthorization = _e.sent();
|
|
1575
|
+
return [3 /*break*/, 5];
|
|
1576
|
+
case 4:
|
|
1577
|
+
err_1 = _e.sent();
|
|
1578
|
+
Logger.warn("Location authorization error: ".concat(err_1.message));
|
|
1579
|
+
return [3 /*break*/, 5];
|
|
1580
|
+
case 5:
|
|
1581
|
+
userId = params.userId || Storage.getItem(Storage.USER_ID);
|
|
1582
|
+
deviceId = params.deviceId || Device.getDeviceId();
|
|
1583
|
+
installId = params.installId || Device.getInstallId();
|
|
1584
|
+
sessionId = Session.getSessionId();
|
|
1585
|
+
deviceType = params.deviceType || 'Web';
|
|
1586
|
+
description = params.description || Storage.getItem(Storage.DESCRIPTION);
|
|
1587
|
+
try {
|
|
1588
|
+
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1589
|
+
}
|
|
1590
|
+
catch (err) {
|
|
1591
|
+
Logger.warn("Error getting time zone: ".concat(err.message));
|
|
1592
|
+
}
|
|
1593
|
+
// save userId for trip tracking
|
|
1594
|
+
if (!userId) {
|
|
1595
|
+
Logger.warn('userId not provided for trackOnce.');
|
|
1596
|
+
}
|
|
1597
|
+
else {
|
|
1598
|
+
Storage.setItem(Storage.USER_ID, userId);
|
|
1599
|
+
}
|
|
1600
|
+
metadata = params.metadata || Storage.getJSON(Storage.METADATA);
|
|
1601
|
+
tripOptions = params.tripOptions || TripsAPI.getTripOptions();
|
|
1602
|
+
if (tripOptions) {
|
|
1603
|
+
tripOptions.version = '2';
|
|
1604
|
+
}
|
|
1605
|
+
body = __assign(__assign({}, params), { locationAuthorization: locationAuthorization, accuracy: accuracy, description: description, deviceId: deviceId, deviceType: deviceType, foreground: true, installId: installId, sessionId: sessionId, latitude: latitude, longitude: longitude, metadata: metadata, sdkVersion: SDK_VERSION, stopped: true, userId: userId, tripOptions: tripOptions, timeZone: timeZone });
|
|
1606
|
+
if (!fraud) return [3 /*break*/, 13];
|
|
1607
|
+
host = 'https://api-verified.radar.io';
|
|
1608
|
+
pingHost = 'ping.radar-verify.com';
|
|
1609
|
+
lang = navigator.language;
|
|
1610
|
+
langs = navigator.languages;
|
|
1611
|
+
return [4 /*yield*/, Http.request({
|
|
1612
|
+
host: host,
|
|
1613
|
+
method: 'GET',
|
|
1614
|
+
path: 'config',
|
|
1615
|
+
data: {
|
|
1616
|
+
deviceId: deviceId,
|
|
1617
|
+
installId: installId,
|
|
1618
|
+
sessionId: sessionId,
|
|
1619
|
+
locationAuthorization: locationAuthorization,
|
|
1620
|
+
},
|
|
1621
|
+
headers: {
|
|
1622
|
+
'X-Radar-Desktop-Device-Type': 'Web',
|
|
1623
|
+
},
|
|
1624
|
+
})];
|
|
1625
|
+
case 6:
|
|
1626
|
+
dk = (_e.sent()).dk;
|
|
1627
|
+
sclVal = -1;
|
|
1628
|
+
cslVal = -1;
|
|
1629
|
+
_e.label = 7;
|
|
1630
|
+
case 7:
|
|
1631
|
+
_e.trys.push([7, 9, , 10]);
|
|
1632
|
+
return [4 /*yield*/, Promise.all([
|
|
1633
|
+
Http.request({
|
|
1634
|
+
host: "https://".concat(pingHost),
|
|
1635
|
+
method: 'GET',
|
|
1636
|
+
path: 'ping',
|
|
1637
|
+
}),
|
|
1638
|
+
ping("wss://".concat(pingHost)),
|
|
1639
|
+
])];
|
|
1640
|
+
case 8:
|
|
1641
|
+
_d = _e.sent(), sclRes = _d[0], csl = _d[1];
|
|
1642
|
+
scl = sclRes.scl;
|
|
1643
|
+
sclVal = scl;
|
|
1644
|
+
cslVal = csl;
|
|
1645
|
+
return [3 /*break*/, 10];
|
|
1646
|
+
case 9:
|
|
1647
|
+
_e.sent();
|
|
1648
|
+
return [3 /*break*/, 10];
|
|
1649
|
+
case 10:
|
|
1650
|
+
payload = {
|
|
1651
|
+
payload: JSON.stringify(__assign(__assign({}, body), { scl: sclVal, csl: cslVal, lang: lang, langs: langs })),
|
|
1652
|
+
};
|
|
1653
|
+
return [4 /*yield*/, signJWT(payload, dk)];
|
|
1654
|
+
case 11:
|
|
1655
|
+
reqToken = _e.sent();
|
|
1656
|
+
return [4 /*yield*/, Http.request({
|
|
1657
|
+
host: host,
|
|
1658
|
+
method: 'POST',
|
|
1659
|
+
path: 'track',
|
|
1660
|
+
data: {
|
|
1661
|
+
token: reqToken,
|
|
1662
|
+
},
|
|
1663
|
+
headers: {
|
|
1664
|
+
'X-Radar-Body-Is-Token': 'true',
|
|
1665
|
+
},
|
|
1666
|
+
})];
|
|
1667
|
+
case 12:
|
|
1668
|
+
response = _e.sent();
|
|
1669
|
+
if (options.debug && response && response.user) {
|
|
1670
|
+
if (!response.user.metadata) {
|
|
1671
|
+
response.user.metadata = {};
|
|
1672
|
+
}
|
|
1673
|
+
response.user.metadata['radar:debug'] = {
|
|
1674
|
+
sclVal: sclVal,
|
|
1675
|
+
cslVal: cslVal,
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
user_1 = response.user, events_1 = response.events, token = response.token, expiresAt = response.expiresAt;
|
|
1679
|
+
location_1 = { latitude: latitude, longitude: longitude, accuracy: accuracy };
|
|
1680
|
+
passed = void 0;
|
|
1681
|
+
expiresIn = void 0;
|
|
1682
|
+
if (expiresAt) {
|
|
1683
|
+
expiresAt = new Date(expiresAt);
|
|
1684
|
+
passed = ((_a = user_1 === null || user_1 === void 0 ? void 0 : user_1.fraud) === null || _a === void 0 ? void 0 : _a.passed) && ((_b = user_1 === null || user_1 === void 0 ? void 0 : user_1.country) === null || _b === void 0 ? void 0 : _b.passed) && ((_c = user_1 === null || user_1 === void 0 ? void 0 : user_1.state) === null || _c === void 0 ? void 0 : _c.passed);
|
|
1685
|
+
expiresIn = (expiresAt.getTime() - Date.now()) / 1000;
|
|
1686
|
+
}
|
|
1687
|
+
trackRes_1 = {
|
|
1688
|
+
user: user_1,
|
|
1689
|
+
events: events_1,
|
|
1690
|
+
location: location_1,
|
|
1691
|
+
token: token,
|
|
1692
|
+
expiresAt: expiresAt,
|
|
1693
|
+
expiresIn: expiresIn,
|
|
1694
|
+
passed: passed,
|
|
1695
|
+
};
|
|
1696
|
+
if (options.debug) {
|
|
1697
|
+
trackRes_1.response = response;
|
|
1698
|
+
}
|
|
1699
|
+
return [2 /*return*/, trackRes_1];
|
|
1700
|
+
case 13: return [4 /*yield*/, Http.request({
|
|
1701
|
+
method: 'POST',
|
|
1702
|
+
path: 'track',
|
|
1703
|
+
data: body,
|
|
1704
|
+
})];
|
|
1705
|
+
case 14:
|
|
1706
|
+
response = _e.sent();
|
|
1707
|
+
user = response.user, events = response.events;
|
|
1708
|
+
location = { latitude: latitude, longitude: longitude, accuracy: accuracy };
|
|
1709
|
+
trackRes = {
|
|
1710
|
+
user: user,
|
|
1711
|
+
events: events,
|
|
1712
|
+
location: location,
|
|
1713
|
+
};
|
|
1714
|
+
if (options.debug) {
|
|
1715
|
+
trackRes.response = response;
|
|
1716
|
+
}
|
|
1717
|
+
return [2 /*return*/, trackRes];
|
|
1345
1718
|
}
|
|
1346
|
-
}
|
|
1347
|
-
response = yield Http.request({
|
|
1348
|
-
method: 'POST',
|
|
1349
|
-
path: 'track',
|
|
1350
|
-
data: body,
|
|
1351
1719
|
});
|
|
1352
|
-
const { user, events } = response;
|
|
1353
|
-
const location = { latitude, longitude, accuracy };
|
|
1354
|
-
const trackRes = {
|
|
1355
|
-
user,
|
|
1356
|
-
events,
|
|
1357
|
-
location,
|
|
1358
|
-
};
|
|
1359
|
-
if (options.debug) {
|
|
1360
|
-
trackRes.response = response;
|
|
1361
|
-
}
|
|
1362
|
-
return trackRes;
|
|
1363
1720
|
});
|
|
1364
|
-
}
|
|
1365
|
-
|
|
1721
|
+
};
|
|
1722
|
+
return TrackAPI;
|
|
1723
|
+
}());
|
|
1366
1724
|
|
|
1367
|
-
|
|
1368
|
-
|
|
1725
|
+
var VerifyAPI = /** @class */ (function () {
|
|
1726
|
+
function VerifyAPI() {
|
|
1727
|
+
}
|
|
1728
|
+
VerifyAPI.trackVerified = function (params, encrypted) {
|
|
1369
1729
|
var _a, _b, _c;
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1730
|
+
if (encrypted === void 0) { encrypted = false; }
|
|
1731
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1732
|
+
var options, userId, deviceId, installId, sessionId, description, metadata, body, userAgent, apple, response, user, events, token, expiresAt, location, passed, expiresIn, trackRes;
|
|
1733
|
+
return __generator(this, function (_d) {
|
|
1734
|
+
switch (_d.label) {
|
|
1735
|
+
case 0:
|
|
1736
|
+
options = Config.get();
|
|
1737
|
+
userId = params.userId || Storage.getItem(Storage.USER_ID);
|
|
1738
|
+
deviceId = params.deviceId || Device.getDeviceId();
|
|
1739
|
+
installId = params.installId || Device.getInstallId();
|
|
1740
|
+
sessionId = Session.getSessionId();
|
|
1741
|
+
description = params.description || Storage.getItem(Storage.DESCRIPTION);
|
|
1742
|
+
// save userId
|
|
1743
|
+
if (!userId) {
|
|
1744
|
+
Logger.warn('userId not provided for trackVerified.');
|
|
1745
|
+
}
|
|
1746
|
+
else {
|
|
1747
|
+
Storage.setItem(Storage.USER_ID, userId);
|
|
1748
|
+
}
|
|
1749
|
+
metadata = params.metadata || Storage.getJSON(Storage.METADATA);
|
|
1750
|
+
body = __assign(__assign({}, params), { description: description, deviceId: deviceId, foreground: true, installId: installId, sessionId: sessionId, metadata: metadata, sdkVersion: SDK_VERSION, stopped: true, userId: userId, encrypted: encrypted });
|
|
1751
|
+
userAgent = navigator.userAgent;
|
|
1752
|
+
apple = userAgent && (userAgent.toLowerCase().includes('mac') || userAgent.toLowerCase().includes('iphone') || userAgent.toLowerCase().includes('ipod') || userAgent.toLowerCase().includes('ipad'));
|
|
1753
|
+
return [4 /*yield*/, Http.request({
|
|
1754
|
+
method: 'GET',
|
|
1755
|
+
path: 'verify',
|
|
1756
|
+
data: body,
|
|
1757
|
+
host: apple ? 'https://radar-verify.com:52516' : 'http://localhost:52516',
|
|
1758
|
+
})];
|
|
1759
|
+
case 1:
|
|
1760
|
+
response = _d.sent();
|
|
1761
|
+
user = response.user, events = response.events, token = response.token, expiresAt = response.expiresAt;
|
|
1762
|
+
if (user && user.location && user.location.coordinates && user.locationAccuracy) {
|
|
1763
|
+
location = {
|
|
1764
|
+
latitude: user.location.coordinates[1],
|
|
1765
|
+
longitude: user.location.coordinates[0],
|
|
1766
|
+
accuracy: user.locationAccuracy,
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1769
|
+
if (expiresAt) {
|
|
1770
|
+
expiresAt = new Date(expiresAt);
|
|
1771
|
+
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);
|
|
1772
|
+
expiresIn = (expiresAt.getTime() - Date.now()) / 1000;
|
|
1773
|
+
}
|
|
1774
|
+
trackRes = {
|
|
1775
|
+
user: user,
|
|
1776
|
+
events: events,
|
|
1777
|
+
location: location,
|
|
1778
|
+
token: token,
|
|
1779
|
+
expiresAt: expiresAt,
|
|
1780
|
+
expiresIn: expiresIn,
|
|
1781
|
+
passed: passed,
|
|
1782
|
+
};
|
|
1783
|
+
if (options.debug) {
|
|
1784
|
+
trackRes.response = response;
|
|
1785
|
+
}
|
|
1786
|
+
return [2 /*return*/, trackRes];
|
|
1787
|
+
}
|
|
1399
1788
|
});
|
|
1400
|
-
let { user, events, token, expiresAt } = response;
|
|
1401
|
-
let location;
|
|
1402
|
-
if (user && user.location && user.location.coordinates && user.locationAccuracy) {
|
|
1403
|
-
location = {
|
|
1404
|
-
latitude: user.location.coordinates[1],
|
|
1405
|
-
longitude: user.location.coordinates[0],
|
|
1406
|
-
accuracy: user.locationAccuracy,
|
|
1407
|
-
};
|
|
1408
|
-
}
|
|
1409
|
-
let passed;
|
|
1410
|
-
let expiresIn;
|
|
1411
|
-
if (expiresAt) {
|
|
1412
|
-
expiresAt = new Date(expiresAt);
|
|
1413
|
-
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);
|
|
1414
|
-
expiresIn = (expiresAt.getTime() - Date.now()) / 1000;
|
|
1415
|
-
}
|
|
1416
|
-
const trackRes = {
|
|
1417
|
-
user,
|
|
1418
|
-
events,
|
|
1419
|
-
location,
|
|
1420
|
-
token,
|
|
1421
|
-
expiresAt,
|
|
1422
|
-
expiresIn,
|
|
1423
|
-
passed,
|
|
1424
|
-
};
|
|
1425
|
-
if (options.debug) {
|
|
1426
|
-
trackRes.response = response;
|
|
1427
|
-
}
|
|
1428
|
-
return trackRes;
|
|
1429
1789
|
});
|
|
1430
|
-
}
|
|
1431
|
-
|
|
1790
|
+
};
|
|
1791
|
+
return VerifyAPI;
|
|
1792
|
+
}());
|
|
1432
1793
|
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
onAdd() {
|
|
1436
|
-
const img = document.createElement('img');
|
|
1437
|
-
img.src = RADAR_LOGO_URL;
|
|
1438
|
-
this.link = document.createElement('a');
|
|
1439
|
-
this.link.id = 'radar-map-logo';
|
|
1440
|
-
this.link.href = 'https://radar.com?ref=powered_by_radar';
|
|
1441
|
-
this.link.target = '_blank';
|
|
1442
|
-
this.link.appendChild(img);
|
|
1443
|
-
return this.link;
|
|
1444
|
-
}
|
|
1445
|
-
onRemove() {
|
|
1446
|
-
var _a;
|
|
1447
|
-
(_a = this.link) === null || _a === void 0 ? void 0 : _a.remove();
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
|
-
const DEFAULT_STYLE = 'radar-default-v1';
|
|
1452
|
-
const RADAR_STYLES = [
|
|
1794
|
+
var DEFAULT_STYLE = 'radar-default-v1';
|
|
1795
|
+
var RADAR_STYLES = [
|
|
1453
1796
|
'radar-default-v1',
|
|
1454
1797
|
'radar-light-v1',
|
|
1455
1798
|
'radar-dark-v1',
|
|
1456
1799
|
];
|
|
1457
|
-
|
|
1800
|
+
var RADAR_LOGO_URL = 'https://api.radar.io/maps/static/images/logo.svg';
|
|
1801
|
+
var defaultMaplibreOptions = {
|
|
1458
1802
|
minZoom: 1,
|
|
1459
1803
|
maxZoom: 20,
|
|
1460
1804
|
attributionControl: false,
|
|
@@ -1462,65 +1806,79 @@ const defaultMaplibreOptions = {
|
|
|
1462
1806
|
touchPitch: false,
|
|
1463
1807
|
maplibreLogo: false,
|
|
1464
1808
|
};
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1809
|
+
var defaultMarkerOptions = {
|
|
1810
|
+
color: '#000257',
|
|
1811
|
+
};
|
|
1812
|
+
var createStyleURL = function (options, style) {
|
|
1813
|
+
if (style === void 0) { style = DEFAULT_STYLE; }
|
|
1814
|
+
return ("".concat(options.host, "/maps/styles/").concat(style, "?publishableKey=").concat(options.publishableKey));
|
|
1470
1815
|
};
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
if (!style || (typeof style === 'string' &&
|
|
1475
|
-
return createStyleURL(options, style);
|
|
1816
|
+
// use formatted style URL if using one of Radar's out-of-the-box styles
|
|
1817
|
+
var getStyle = function (options, mapOptions) {
|
|
1818
|
+
var style = mapOptions.style;
|
|
1819
|
+
if (!style || (typeof style === 'string' && RADAR_STYLES.includes(style))) {
|
|
1820
|
+
return createStyleURL(options, mapOptions.style);
|
|
1476
1821
|
}
|
|
1477
1822
|
return mapOptions.style;
|
|
1478
1823
|
};
|
|
1479
|
-
class
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1824
|
+
var MapUI = /** @class */ (function () {
|
|
1825
|
+
function MapUI() {
|
|
1826
|
+
}
|
|
1827
|
+
MapUI.getMapLibre = function () {
|
|
1828
|
+
return maplibregl;
|
|
1829
|
+
};
|
|
1830
|
+
MapUI.createMap = function (mapOptions) {
|
|
1831
|
+
var options = Config.get();
|
|
1832
|
+
if (!options.publishableKey) {
|
|
1483
1833
|
Logger.warn('publishableKey not set. Call Radar.initialize() with key before creating a new map.');
|
|
1484
1834
|
}
|
|
1485
1835
|
// configure maplibre options
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
Logger.debug(
|
|
1836
|
+
var style = getStyle(options, mapOptions);
|
|
1837
|
+
var maplibreOptions = Object.assign({}, defaultMaplibreOptions, mapOptions, { style: style });
|
|
1838
|
+
Logger.debug("initialize map with options: ".concat(JSON.stringify(maplibreOptions)));
|
|
1839
|
+
// set container
|
|
1840
|
+
maplibreOptions.container = mapOptions.container;
|
|
1489
1841
|
// custom request handler for Radar styles
|
|
1490
|
-
maplibreOptions.transformRequest = (url, resourceType)
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
radarStyleURL = createStyleURL(config, url);
|
|
1495
|
-
}
|
|
1496
|
-
if (mapOptions.transformRequest) {
|
|
1497
|
-
return mapOptions.transformRequest(radarStyleURL, resourceType);
|
|
1842
|
+
maplibreOptions.transformRequest = function (url, resourceType) {
|
|
1843
|
+
if (resourceType === 'Style' && RADAR_STYLES.includes(url)) {
|
|
1844
|
+
var radarStyleURL = createStyleURL(options, url);
|
|
1845
|
+
return { url: radarStyleURL };
|
|
1498
1846
|
}
|
|
1499
|
-
|
|
1500
|
-
|
|
1847
|
+
else {
|
|
1848
|
+
return { url: url };
|
|
1501
1849
|
}
|
|
1502
|
-
return { url: radarStyleURL, headers };
|
|
1503
1850
|
};
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1851
|
+
// create map
|
|
1852
|
+
var map = new maplibregl.Map(maplibreOptions);
|
|
1853
|
+
var container = map.getContainer();
|
|
1507
1854
|
if (!container.style.width && !container.style.height) {
|
|
1508
1855
|
Logger.warn('map container does not have a set "width" or "height"');
|
|
1509
1856
|
}
|
|
1510
1857
|
// add radar logo
|
|
1511
|
-
|
|
1512
|
-
|
|
1858
|
+
var img = document.createElement('img');
|
|
1859
|
+
img.src = RADAR_LOGO_URL;
|
|
1860
|
+
var link = document.createElement('a');
|
|
1861
|
+
link.id = 'radar-map-logo';
|
|
1862
|
+
link.href = 'https://radar.com?ref=powered_by_radar';
|
|
1863
|
+
link.target = '_blank';
|
|
1864
|
+
link.style.position = 'absolute';
|
|
1865
|
+
link.style.bottom = '0';
|
|
1866
|
+
link.style.left = '5px';
|
|
1867
|
+
link.style.width = '80px';
|
|
1868
|
+
link.style.height = '38px';
|
|
1869
|
+
link.appendChild(img);
|
|
1870
|
+
map.getContainer().appendChild(link);
|
|
1513
1871
|
// add attribution
|
|
1514
|
-
|
|
1515
|
-
|
|
1872
|
+
var attribution = new maplibregl.AttributionControl({ compact: false });
|
|
1873
|
+
map.addControl(attribution, 'bottom-right');
|
|
1516
1874
|
// add zoom controls
|
|
1517
|
-
|
|
1518
|
-
|
|
1875
|
+
var nav = new maplibregl.NavigationControl({ showCompass: false });
|
|
1876
|
+
map.addControl(nav, 'bottom-right');
|
|
1519
1877
|
// handle map resize actions
|
|
1520
|
-
|
|
1521
|
-
|
|
1878
|
+
var onResize = function () {
|
|
1879
|
+
var attrib = document.querySelector('.maplibregl-ctrl-attrib');
|
|
1522
1880
|
if (attrib) {
|
|
1523
|
-
|
|
1881
|
+
var width = map.getContainer().clientWidth;
|
|
1524
1882
|
if (width < 380) {
|
|
1525
1883
|
attrib.classList.add('hidden');
|
|
1526
1884
|
}
|
|
@@ -1529,40 +1887,13 @@ class RadarMap extends maplibregl.Map {
|
|
|
1529
1887
|
}
|
|
1530
1888
|
}
|
|
1531
1889
|
};
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
}
|
|
1539
|
-
|
|
1540
|
-
const defaultMarkerOptions = {
|
|
1541
|
-
color: '#000257',
|
|
1542
|
-
};
|
|
1543
|
-
const fileExtensionToContentType = {
|
|
1544
|
-
svg: 'image/svg+xml',
|
|
1545
|
-
png: 'image/png',
|
|
1546
|
-
};
|
|
1547
|
-
const getFileExtension = (file) => {
|
|
1548
|
-
return file.split('.').pop() || '';
|
|
1549
|
-
};
|
|
1550
|
-
const createImageElement = (options) => {
|
|
1551
|
-
const element = document.createElement('img');
|
|
1552
|
-
element.src = options.url;
|
|
1553
|
-
if (options.width) {
|
|
1554
|
-
element.width = options.width;
|
|
1555
|
-
}
|
|
1556
|
-
if (options.height) {
|
|
1557
|
-
element.height = options.height;
|
|
1558
|
-
}
|
|
1559
|
-
element.style.maxWidth = '64px';
|
|
1560
|
-
element.style.maxHeight = '64px';
|
|
1561
|
-
return element;
|
|
1562
|
-
};
|
|
1563
|
-
class RadarMarker extends maplibregl.Marker {
|
|
1564
|
-
constructor(markerOptions) {
|
|
1565
|
-
const maplibreOptions = Object.assign({}, defaultMarkerOptions);
|
|
1890
|
+
map.on('resize', onResize);
|
|
1891
|
+
map.on('load', onResize);
|
|
1892
|
+
return map;
|
|
1893
|
+
};
|
|
1894
|
+
MapUI.createMarker = function (markerOptions) {
|
|
1895
|
+
if (markerOptions === void 0) { markerOptions = {}; }
|
|
1896
|
+
var maplibreOptions = Object.assign({}, defaultMarkerOptions);
|
|
1566
1897
|
if (markerOptions.color) {
|
|
1567
1898
|
maplibreOptions.color = markerOptions.color;
|
|
1568
1899
|
}
|
|
@@ -1572,101 +1903,22 @@ class RadarMarker extends maplibregl.Marker {
|
|
|
1572
1903
|
if (markerOptions.scale) {
|
|
1573
1904
|
maplibreOptions.scale = markerOptions.scale;
|
|
1574
1905
|
}
|
|
1575
|
-
|
|
1576
|
-
maplibreOptions.element = createImageElement(markerOptions.image);
|
|
1577
|
-
}
|
|
1578
|
-
super(maplibreOptions);
|
|
1579
|
-
if (markerOptions.image) {
|
|
1580
|
-
this._image = markerOptions.image;
|
|
1581
|
-
}
|
|
1582
|
-
if (markerOptions.customMarkerId) {
|
|
1583
|
-
const ext = getFileExtension(markerOptions.customMarkerId);
|
|
1584
|
-
if (ext !== 'svg' && ext !== 'png') {
|
|
1585
|
-
Logger.error(`Invalid custom marker extension ${ext} - falling back to default marker`);
|
|
1586
|
-
}
|
|
1587
|
-
else {
|
|
1588
|
-
this._customMarkerId = markerOptions.customMarkerId;
|
|
1589
|
-
const originalElement = this._element.cloneNode(true);
|
|
1590
|
-
this._element.childNodes.forEach((child) => {
|
|
1591
|
-
child.remove();
|
|
1592
|
-
});
|
|
1593
|
-
const contentType = fileExtensionToContentType[ext];
|
|
1594
|
-
Http.request({
|
|
1595
|
-
method: 'GET',
|
|
1596
|
-
versioned: false,
|
|
1597
|
-
path: `maps/PlACEHOLDER/markers/${markerOptions.customMarkerId}`,
|
|
1598
|
-
headers: {
|
|
1599
|
-
'Content-Type': contentType,
|
|
1600
|
-
},
|
|
1601
|
-
}).then((res) => {
|
|
1602
|
-
if (res.data instanceof Blob) {
|
|
1603
|
-
// png returns a Blob
|
|
1604
|
-
const customMarkerUrl = URL.createObjectURL(res.data);
|
|
1605
|
-
this._element.replaceChildren(createImageElement({ url: customMarkerUrl }));
|
|
1606
|
-
}
|
|
1607
|
-
else {
|
|
1608
|
-
// svg returns an xml string
|
|
1609
|
-
this._element.innerHTML = res.data;
|
|
1610
|
-
}
|
|
1611
|
-
}).catch((err) => {
|
|
1612
|
-
Logger.error(`Could not get custom marker: ${err.message} - falling back to default marker`);
|
|
1613
|
-
this._element.replaceChildren(...originalElement.childNodes);
|
|
1614
|
-
});
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1906
|
+
var marker = new maplibregl.Marker(maplibreOptions);
|
|
1617
1907
|
// set popup text or HTML
|
|
1618
1908
|
if (markerOptions.text) {
|
|
1619
|
-
|
|
1620
|
-
|
|
1909
|
+
var popup = new maplibregl.Popup({ offset: 35 }).setText(markerOptions.text);
|
|
1910
|
+
marker.setPopup(popup);
|
|
1621
1911
|
}
|
|
1622
1912
|
else if (markerOptions.html) {
|
|
1623
|
-
|
|
1624
|
-
|
|
1913
|
+
var popup = new maplibregl.Popup({ offset: 35 }).setHTML(markerOptions.html);
|
|
1914
|
+
marker.setPopup(popup);
|
|
1625
1915
|
}
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
}
|
|
1631
|
-
remove() {
|
|
1632
|
-
if (this._map) {
|
|
1633
|
-
this._map._markers = this._map._markers.filter((marker) => marker !== this);
|
|
1634
|
-
}
|
|
1635
|
-
return super.remove();
|
|
1636
|
-
}
|
|
1637
|
-
getOptions() {
|
|
1638
|
-
const markerOptions = {
|
|
1639
|
-
// TODO: element: marker.getElement(),
|
|
1640
|
-
image: this._image,
|
|
1641
|
-
color: this._color,
|
|
1642
|
-
scale: this._scale,
|
|
1643
|
-
offset: this.getOffset(),
|
|
1644
|
-
anchor: this._anchor,
|
|
1645
|
-
draggable: this.isDraggable(),
|
|
1646
|
-
clickTolerance: this._clickTolerance,
|
|
1647
|
-
rotation: this.getRotation(),
|
|
1648
|
-
rotationAlignment: this.getRotationAlignment(),
|
|
1649
|
-
pitchAlignment: this.getPitchAlignment()
|
|
1650
|
-
};
|
|
1651
|
-
return markerOptions;
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1916
|
+
return marker;
|
|
1917
|
+
};
|
|
1918
|
+
return MapUI;
|
|
1919
|
+
}());
|
|
1654
1920
|
|
|
1655
|
-
|
|
1656
|
-
static getMapLibre() {
|
|
1657
|
-
return maplibregl;
|
|
1658
|
-
}
|
|
1659
|
-
static createMap(mapOptions) {
|
|
1660
|
-
const radarMap = new RadarMap(mapOptions);
|
|
1661
|
-
return radarMap;
|
|
1662
|
-
}
|
|
1663
|
-
static createMarker(markerOptions = {}) {
|
|
1664
|
-
const radarMarker = new RadarMarker(markerOptions);
|
|
1665
|
-
return radarMarker;
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
const CLASSNAMES = {
|
|
1921
|
+
var CLASSNAMES = {
|
|
1670
1922
|
WRAPPER: 'radar-autocomplete-wrapper',
|
|
1671
1923
|
INPUT: 'radar-autocomplete-input',
|
|
1672
1924
|
SEARCH_ICON: 'radar-autocomplete-search-icon',
|
|
@@ -1677,10 +1929,10 @@ const CLASSNAMES = {
|
|
|
1677
1929
|
POWERED_BY_RADAR: 'radar-powered',
|
|
1678
1930
|
NO_RESULTS: 'radar-no-results',
|
|
1679
1931
|
};
|
|
1680
|
-
|
|
1932
|
+
var ARIA = {
|
|
1681
1933
|
EXPANDED: 'aria-expanded',
|
|
1682
1934
|
};
|
|
1683
|
-
|
|
1935
|
+
var defaultAutocompleteOptions = {
|
|
1684
1936
|
container: 'autocomplete',
|
|
1685
1937
|
debounceMS: 200,
|
|
1686
1938
|
minCharacters: 3,
|
|
@@ -1692,14 +1944,14 @@ const defaultAutocompleteOptions = {
|
|
|
1692
1944
|
hideResultsOnBlur: true,
|
|
1693
1945
|
};
|
|
1694
1946
|
// determine whether to use px or CSS string
|
|
1695
|
-
|
|
1947
|
+
var formatCSSValue = function (value) {
|
|
1696
1948
|
if (typeof value === 'number') {
|
|
1697
|
-
return
|
|
1949
|
+
return "".concat(value, "px");
|
|
1698
1950
|
}
|
|
1699
1951
|
return value;
|
|
1700
1952
|
};
|
|
1701
|
-
|
|
1702
|
-
|
|
1953
|
+
var DEFAULT_WIDTH = 400;
|
|
1954
|
+
var setWidth = function (input, options) {
|
|
1703
1955
|
// if responsive and width is provided, treat it as maxWidth
|
|
1704
1956
|
if (options.responsive) {
|
|
1705
1957
|
input.style.width = '100%';
|
|
@@ -1712,25 +1964,21 @@ const setWidth = (input, options) => {
|
|
|
1712
1964
|
input.style.width = formatCSSValue(options.width || DEFAULT_WIDTH);
|
|
1713
1965
|
input.style.removeProperty('max-width');
|
|
1714
1966
|
};
|
|
1715
|
-
|
|
1967
|
+
var setHeight = function (resultsList, options) {
|
|
1716
1968
|
if (options.maxHeight) {
|
|
1717
1969
|
resultsList.style.maxHeight = formatCSSValue(options.maxHeight);
|
|
1718
1970
|
resultsList.style.overflowY = 'auto'; /* allow overflow when maxHeight is applied */
|
|
1719
1971
|
}
|
|
1720
1972
|
};
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
<path d
|
|
1725
|
-
|
|
1726
|
-
return `data:image/svg+xml;charset=utf-8,${svg}`;
|
|
1973
|
+
var getMarkerIcon = function (color) {
|
|
1974
|
+
if (color === void 0) { color = "#ACBDC8"; }
|
|
1975
|
+
var fill = color.replace('#', '%23');
|
|
1976
|
+
var svg = "<svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M12.5704 6.57036C12.5704 4.11632 10.6342 2.11257 8.21016 2C8.14262 2 8.06757 2 8.00003 2C7.93249 2 7.85744 2 7.7899 2C5.35838 2.11257 3.42967 4.11632 3.42967 6.57036C3.42967 6.60037 3.42967 6.6379 3.42967 6.66792C3.42967 6.69794 3.42967 6.73546 3.42967 6.76548C3.42967 9.46717 7.09196 13.3621 7.4672 13.7598C7.61729 13.9174 7.84994 14 8.00003 14C8.15012 14 8.38277 13.9174 8.53286 13.7598C8.9156 13.3621 12.5704 9.46717 12.5704 6.76548C12.5704 6.72795 12.5704 6.69794 12.5704 6.66792C12.5704 6.6379 12.5704 6.60037 12.5704 6.57036ZM7.99252 8.28893C7.04693 8.28893 6.27395 7.52345 6.27395 6.57036C6.27395 5.61726 7.03943 4.85178 7.99252 4.85178C8.94562 4.85178 9.7111 5.61726 9.7111 6.57036C9.7111 7.52345 8.94562 8.28893 7.99252 8.28893Z\" fill=\"".concat(fill, "\"/>\n </svg>").trim();
|
|
1977
|
+
return "data:image/svg+xml;charset=utf-8,".concat(svg);
|
|
1727
1978
|
};
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
return new AutocompleteUI(autocompleteOptions);
|
|
1732
|
-
}
|
|
1733
|
-
constructor(options = {}) {
|
|
1979
|
+
var AutocompleteUI = /** @class */ (function () {
|
|
1980
|
+
function AutocompleteUI(options) {
|
|
1981
|
+
if (options === void 0) { options = {}; }
|
|
1734
1982
|
this.config = Object.assign({}, defaultAutocompleteOptions, options);
|
|
1735
1983
|
// setup state
|
|
1736
1984
|
this.isOpen = false;
|
|
@@ -1747,11 +1995,11 @@ class AutocompleteUI {
|
|
|
1747
1995
|
this.near = options.near;
|
|
1748
1996
|
}
|
|
1749
1997
|
else {
|
|
1750
|
-
this.near =
|
|
1998
|
+
this.near = "".concat(options.near.latitude, ",").concat(options.near.longitude);
|
|
1751
1999
|
}
|
|
1752
2000
|
}
|
|
1753
2001
|
// get container element
|
|
1754
|
-
|
|
2002
|
+
var containerEL;
|
|
1755
2003
|
if (typeof this.config.container === 'string') { // lookup container element by ID
|
|
1756
2004
|
containerEL = document.getElementById(this.config.container);
|
|
1757
2005
|
}
|
|
@@ -1759,7 +2007,7 @@ class AutocompleteUI {
|
|
|
1759
2007
|
containerEL = this.config.container; // HTMLElement
|
|
1760
2008
|
}
|
|
1761
2009
|
if (!containerEL) {
|
|
1762
|
-
throw new RadarAutocompleteContainerNotFound(
|
|
2010
|
+
throw new RadarAutocompleteContainerNotFound("Could not find container element: ".concat(this.config.container));
|
|
1763
2011
|
}
|
|
1764
2012
|
this.container = containerEL;
|
|
1765
2013
|
// create wrapper for input and result list
|
|
@@ -1788,7 +2036,7 @@ class AutocompleteUI {
|
|
|
1788
2036
|
this.inputField.type = 'text';
|
|
1789
2037
|
this.inputField.disabled = this.config.disabled;
|
|
1790
2038
|
// search icon
|
|
1791
|
-
|
|
2039
|
+
var searchIcon = document.createElement('div');
|
|
1792
2040
|
searchIcon.classList.add(CLASSNAMES.SEARCH_ICON);
|
|
1793
2041
|
// append to DOM
|
|
1794
2042
|
this.wrapper.appendChild(this.inputField);
|
|
@@ -1802,104 +2050,123 @@ class AutocompleteUI {
|
|
|
1802
2050
|
if (this.config.hideResultsOnBlur) {
|
|
1803
2051
|
this.inputField.addEventListener('blur', this.close.bind(this), true);
|
|
1804
2052
|
}
|
|
1805
|
-
Logger.debug(
|
|
2053
|
+
Logger.debug("AutocompleteUI iniailized with options: ".concat(JSON.stringify(this.config)));
|
|
1806
2054
|
}
|
|
1807
|
-
|
|
2055
|
+
// create a new AutocompleteUI instance
|
|
2056
|
+
AutocompleteUI.createAutocomplete = function (autocompleteOptions) {
|
|
2057
|
+
return new AutocompleteUI(autocompleteOptions);
|
|
2058
|
+
};
|
|
2059
|
+
AutocompleteUI.prototype.handleInput = function () {
|
|
2060
|
+
var _this = this;
|
|
1808
2061
|
// Fetch autocomplete results and display them
|
|
1809
|
-
|
|
2062
|
+
var query = this.inputField.value;
|
|
1810
2063
|
if (query.length < this.config.minCharacters) {
|
|
1811
2064
|
return;
|
|
1812
2065
|
}
|
|
1813
2066
|
this.debouncedFetchResults(query)
|
|
1814
|
-
.then((results)
|
|
1815
|
-
|
|
2067
|
+
.then(function (results) {
|
|
2068
|
+
var onResults = _this.config.onResults;
|
|
1816
2069
|
if (onResults) {
|
|
1817
2070
|
onResults(results);
|
|
1818
2071
|
}
|
|
1819
|
-
|
|
2072
|
+
_this.displayResults(results);
|
|
1820
2073
|
})
|
|
1821
|
-
.catch((error)
|
|
1822
|
-
Logger.warn(
|
|
1823
|
-
|
|
2074
|
+
.catch(function (error) {
|
|
2075
|
+
Logger.warn("Autocomplete ui error: ".concat(error.message));
|
|
2076
|
+
var onError = _this.config.onError;
|
|
1824
2077
|
if (onError) {
|
|
1825
2078
|
onError(error);
|
|
1826
2079
|
}
|
|
1827
2080
|
});
|
|
1828
|
-
}
|
|
1829
|
-
debounce(fn, delay) {
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
2081
|
+
};
|
|
2082
|
+
AutocompleteUI.prototype.debounce = function (fn, delay) {
|
|
2083
|
+
var _this = this;
|
|
2084
|
+
var timeoutId;
|
|
2085
|
+
var resolveFn;
|
|
2086
|
+
var rejectFn;
|
|
2087
|
+
return function () {
|
|
2088
|
+
var args = [];
|
|
2089
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2090
|
+
args[_i] = arguments[_i];
|
|
2091
|
+
}
|
|
1834
2092
|
clearTimeout(timeoutId);
|
|
1835
|
-
timeoutId = setTimeout(()
|
|
1836
|
-
|
|
2093
|
+
timeoutId = setTimeout(function () {
|
|
2094
|
+
var result = fn.apply(_this, args);
|
|
1837
2095
|
if (result instanceof Promise) {
|
|
1838
2096
|
result
|
|
1839
|
-
.then((value)
|
|
2097
|
+
.then(function (value) {
|
|
1840
2098
|
if (resolveFn) {
|
|
1841
2099
|
resolveFn(value);
|
|
1842
2100
|
}
|
|
1843
2101
|
})
|
|
1844
|
-
.catch((error)
|
|
2102
|
+
.catch(function (error) {
|
|
1845
2103
|
if (rejectFn) {
|
|
1846
2104
|
rejectFn(error);
|
|
1847
2105
|
}
|
|
1848
2106
|
});
|
|
1849
2107
|
}
|
|
1850
2108
|
}, delay);
|
|
1851
|
-
return new Promise((resolve, reject)
|
|
2109
|
+
return new Promise(function (resolve, reject) {
|
|
1852
2110
|
resolveFn = resolve;
|
|
1853
2111
|
rejectFn = reject;
|
|
1854
2112
|
});
|
|
1855
2113
|
};
|
|
1856
|
-
}
|
|
1857
|
-
fetchResults(query) {
|
|
1858
|
-
return __awaiter(this, void 0, void 0, function
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
2114
|
+
};
|
|
2115
|
+
AutocompleteUI.prototype.fetchResults = function (query) {
|
|
2116
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2117
|
+
var _a, limit, layers, countryCode, expandUnits, mailable, onRequest, params, addresses;
|
|
2118
|
+
return __generator(this, function (_b) {
|
|
2119
|
+
switch (_b.label) {
|
|
2120
|
+
case 0:
|
|
2121
|
+
_a = this.config, limit = _a.limit, layers = _a.layers, countryCode = _a.countryCode, expandUnits = _a.expandUnits, mailable = _a.mailable, onRequest = _a.onRequest;
|
|
2122
|
+
params = {
|
|
2123
|
+
query: query,
|
|
2124
|
+
limit: limit,
|
|
2125
|
+
layers: layers,
|
|
2126
|
+
countryCode: countryCode,
|
|
2127
|
+
expandUnits: expandUnits,
|
|
2128
|
+
mailable: mailable,
|
|
2129
|
+
};
|
|
2130
|
+
if (this.near) {
|
|
2131
|
+
params.near = this.near;
|
|
2132
|
+
}
|
|
2133
|
+
if (onRequest) {
|
|
2134
|
+
onRequest(params);
|
|
2135
|
+
}
|
|
2136
|
+
return [4 /*yield*/, SearchAPI.autocomplete(params)];
|
|
2137
|
+
case 1:
|
|
2138
|
+
addresses = (_b.sent()).addresses;
|
|
2139
|
+
return [2 /*return*/, addresses];
|
|
2140
|
+
}
|
|
2141
|
+
});
|
|
1876
2142
|
});
|
|
1877
|
-
}
|
|
1878
|
-
displayResults(results) {
|
|
2143
|
+
};
|
|
2144
|
+
AutocompleteUI.prototype.displayResults = function (results) {
|
|
2145
|
+
var _this = this;
|
|
1879
2146
|
// Clear the previous results
|
|
1880
2147
|
this.clearResultsList();
|
|
1881
2148
|
this.results = results;
|
|
1882
|
-
|
|
2149
|
+
var marker;
|
|
1883
2150
|
if (this.config.showMarkers) {
|
|
1884
2151
|
marker = document.createElement('img');
|
|
1885
2152
|
marker.classList.add(CLASSNAMES.RESULTS_MARKER);
|
|
1886
2153
|
marker.setAttribute('src', getMarkerIcon(this.config.markerColor));
|
|
1887
2154
|
}
|
|
1888
2155
|
// Create and append list items for each result
|
|
1889
|
-
results.forEach((result, index)
|
|
1890
|
-
|
|
2156
|
+
results.forEach(function (result, index) {
|
|
2157
|
+
var li = document.createElement('li');
|
|
1891
2158
|
li.classList.add(CLASSNAMES.RESULTS_ITEM);
|
|
1892
2159
|
// construct result with bolded label
|
|
1893
|
-
|
|
2160
|
+
var listContent;
|
|
1894
2161
|
if (result.formattedAddress.includes(result.addressLabel) && result.layer !== 'postalCode') {
|
|
1895
2162
|
// if addressLabel is contained in the formatted address, bold the address label
|
|
1896
|
-
|
|
2163
|
+
var regex = new RegExp("(".concat(result.addressLabel, "),?"));
|
|
1897
2164
|
listContent = result.formattedAddress.replace(regex, '<b>$1</b>');
|
|
1898
2165
|
}
|
|
1899
2166
|
else {
|
|
1900
2167
|
// otherwise append the address or place label to formatted address
|
|
1901
|
-
|
|
1902
|
-
listContent =
|
|
2168
|
+
var label = result.placeLabel || result.addressLabel;
|
|
2169
|
+
listContent = "<b>".concat(label, "</b> ").concat(result.formattedAddress);
|
|
1903
2170
|
}
|
|
1904
2171
|
li.innerHTML = listContent;
|
|
1905
2172
|
// prepend marker if enabled
|
|
@@ -1907,59 +2174,60 @@ class AutocompleteUI {
|
|
|
1907
2174
|
li.prepend(marker.cloneNode());
|
|
1908
2175
|
}
|
|
1909
2176
|
// add click handler to each result, use mousedown to fire before blur event
|
|
1910
|
-
li.addEventListener('mousedown', ()
|
|
1911
|
-
|
|
2177
|
+
li.addEventListener('mousedown', function () {
|
|
2178
|
+
_this.select(index);
|
|
1912
2179
|
});
|
|
1913
|
-
|
|
2180
|
+
_this.resultsList.appendChild(li);
|
|
1914
2181
|
});
|
|
1915
2182
|
this.open();
|
|
1916
2183
|
if (results.length > 0) {
|
|
1917
|
-
|
|
2184
|
+
var link = document.createElement('a');
|
|
1918
2185
|
link.href = 'https://radar.com?ref=powered_by_radar';
|
|
1919
2186
|
link.target = '_blank';
|
|
1920
2187
|
this.poweredByLink = link;
|
|
1921
|
-
|
|
2188
|
+
var poweredByText = document.createElement('span');
|
|
1922
2189
|
poweredByText.textContent = 'Powered by';
|
|
1923
2190
|
link.appendChild(poweredByText);
|
|
1924
|
-
|
|
2191
|
+
var radarLogo = document.createElement('span');
|
|
1925
2192
|
radarLogo.id = 'radar-powered-logo';
|
|
1926
2193
|
link.appendChild(radarLogo);
|
|
1927
|
-
|
|
2194
|
+
var poweredByContainer = document.createElement('div');
|
|
1928
2195
|
poweredByContainer.classList.add(CLASSNAMES.POWERED_BY_RADAR);
|
|
1929
2196
|
poweredByContainer.appendChild(link);
|
|
1930
2197
|
this.resultsList.appendChild(poweredByContainer);
|
|
1931
2198
|
}
|
|
1932
2199
|
else {
|
|
1933
|
-
|
|
2200
|
+
var noResultsText = document.createElement('div');
|
|
1934
2201
|
noResultsText.classList.add(CLASSNAMES.NO_RESULTS);
|
|
1935
2202
|
noResultsText.textContent = 'No results';
|
|
1936
2203
|
this.resultsList.appendChild(noResultsText);
|
|
1937
2204
|
}
|
|
1938
|
-
}
|
|
1939
|
-
open() {
|
|
2205
|
+
};
|
|
2206
|
+
AutocompleteUI.prototype.open = function () {
|
|
1940
2207
|
if (this.isOpen) {
|
|
1941
2208
|
return;
|
|
1942
2209
|
}
|
|
1943
2210
|
this.wrapper.setAttribute(ARIA.EXPANDED, 'true');
|
|
1944
2211
|
this.resultsList.removeAttribute('hidden');
|
|
1945
2212
|
this.isOpen = true;
|
|
1946
|
-
}
|
|
1947
|
-
close(e) {
|
|
2213
|
+
};
|
|
2214
|
+
AutocompleteUI.prototype.close = function (e) {
|
|
2215
|
+
var _this = this;
|
|
1948
2216
|
if (!this.isOpen) {
|
|
1949
2217
|
return;
|
|
1950
2218
|
}
|
|
1951
2219
|
// run this code async to allow link click to propagate before blur
|
|
1952
2220
|
// (add 100ms delay if closed from link click)
|
|
1953
|
-
|
|
1954
|
-
setTimeout(()
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
2221
|
+
var linkClick = e && (e.relatedTarget === this.poweredByLink);
|
|
2222
|
+
setTimeout(function () {
|
|
2223
|
+
_this.wrapper.removeAttribute(ARIA.EXPANDED);
|
|
2224
|
+
_this.resultsList.setAttribute('hidden', '');
|
|
2225
|
+
_this.highlightedIndex = -1;
|
|
2226
|
+
_this.isOpen = false;
|
|
2227
|
+
_this.clearResultsList();
|
|
1960
2228
|
}, linkClick ? 100 : 0);
|
|
1961
|
-
}
|
|
1962
|
-
goTo(index) {
|
|
2229
|
+
};
|
|
2230
|
+
AutocompleteUI.prototype.goTo = function (index) {
|
|
1963
2231
|
if (!this.isOpen || !this.results.length) {
|
|
1964
2232
|
return;
|
|
1965
2233
|
}
|
|
@@ -1970,7 +2238,7 @@ class AutocompleteUI {
|
|
|
1970
2238
|
else if (index >= this.results.length) {
|
|
1971
2239
|
index = 0;
|
|
1972
2240
|
}
|
|
1973
|
-
|
|
2241
|
+
var resultItems = this.resultsList.getElementsByTagName('li');
|
|
1974
2242
|
if (this.highlightedIndex > -1) {
|
|
1975
2243
|
// clear class names on previously highlighted item
|
|
1976
2244
|
resultItems[this.highlightedIndex].classList.remove(CLASSNAMES.SELECTED_ITEM);
|
|
@@ -1978,10 +2246,10 @@ class AutocompleteUI {
|
|
|
1978
2246
|
// add class name to newly highlighted item
|
|
1979
2247
|
resultItems[index].classList.add(CLASSNAMES.SELECTED_ITEM);
|
|
1980
2248
|
this.highlightedIndex = index;
|
|
1981
|
-
}
|
|
1982
|
-
handleKeyboardNavigation(event) {
|
|
2249
|
+
};
|
|
2250
|
+
AutocompleteUI.prototype.handleKeyboardNavigation = function (event) {
|
|
1983
2251
|
// fallback to deprecated "keyCode" if event.code not set
|
|
1984
|
-
|
|
2252
|
+
var code = event.code !== undefined ? event.code : event.keyCode;
|
|
1985
2253
|
// allow event to propagate if result list is not open
|
|
1986
2254
|
if (!this.isOpen) {
|
|
1987
2255
|
return;
|
|
@@ -2011,41 +2279,41 @@ class AutocompleteUI {
|
|
|
2011
2279
|
this.close();
|
|
2012
2280
|
break;
|
|
2013
2281
|
}
|
|
2014
|
-
}
|
|
2015
|
-
select(index) {
|
|
2016
|
-
|
|
2282
|
+
};
|
|
2283
|
+
AutocompleteUI.prototype.select = function (index) {
|
|
2284
|
+
var result = this.results[index];
|
|
2017
2285
|
if (!result) {
|
|
2018
|
-
Logger.warn(
|
|
2286
|
+
Logger.warn("No autocomplete result found at index: ".concat(index));
|
|
2019
2287
|
return;
|
|
2020
2288
|
}
|
|
2021
|
-
|
|
2289
|
+
var inputValue;
|
|
2022
2290
|
if (result.formattedAddress.includes(result.addressLabel)) {
|
|
2023
2291
|
inputValue = result.formattedAddress;
|
|
2024
2292
|
}
|
|
2025
2293
|
else {
|
|
2026
|
-
|
|
2027
|
-
inputValue =
|
|
2294
|
+
var label = result.placeLabel || result.addressLabel;
|
|
2295
|
+
inputValue = "".concat(label, ", ").concat(result.formattedAddress);
|
|
2028
2296
|
}
|
|
2029
2297
|
this.inputField.value = inputValue;
|
|
2030
|
-
|
|
2298
|
+
var onSelection = this.config.onSelection;
|
|
2031
2299
|
if (onSelection) {
|
|
2032
2300
|
onSelection(result);
|
|
2033
2301
|
}
|
|
2034
2302
|
// clear results list
|
|
2035
2303
|
this.close();
|
|
2036
|
-
}
|
|
2037
|
-
clearResultsList() {
|
|
2304
|
+
};
|
|
2305
|
+
AutocompleteUI.prototype.clearResultsList = function () {
|
|
2038
2306
|
this.resultsList.innerHTML = '';
|
|
2039
2307
|
this.results = [];
|
|
2040
|
-
}
|
|
2308
|
+
};
|
|
2041
2309
|
// remove elements from DOM
|
|
2042
|
-
remove() {
|
|
2310
|
+
AutocompleteUI.prototype.remove = function () {
|
|
2043
2311
|
Logger.debug('AutocompleteUI removed.');
|
|
2044
2312
|
this.inputField.remove();
|
|
2045
2313
|
this.resultsList.remove();
|
|
2046
2314
|
this.wrapper.remove();
|
|
2047
|
-
}
|
|
2048
|
-
setNear(near) {
|
|
2315
|
+
};
|
|
2316
|
+
AutocompleteUI.prototype.setNear = function (near) {
|
|
2049
2317
|
if (near === undefined || near === null) {
|
|
2050
2318
|
this.near = undefined;
|
|
2051
2319
|
}
|
|
@@ -2053,78 +2321,78 @@ class AutocompleteUI {
|
|
|
2053
2321
|
this.near = near;
|
|
2054
2322
|
}
|
|
2055
2323
|
else {
|
|
2056
|
-
this.near =
|
|
2324
|
+
this.near = "".concat(near.latitude, ",").concat(near.longitude);
|
|
2057
2325
|
}
|
|
2058
2326
|
return this;
|
|
2059
|
-
}
|
|
2060
|
-
setPlaceholder(placeholder) {
|
|
2327
|
+
};
|
|
2328
|
+
AutocompleteUI.prototype.setPlaceholder = function (placeholder) {
|
|
2061
2329
|
this.config.placeholder = placeholder;
|
|
2062
2330
|
this.inputField.placeholder = placeholder;
|
|
2063
2331
|
return this;
|
|
2064
|
-
}
|
|
2065
|
-
setDisabled(disabled) {
|
|
2332
|
+
};
|
|
2333
|
+
AutocompleteUI.prototype.setDisabled = function (disabled) {
|
|
2066
2334
|
this.config.disabled = disabled;
|
|
2067
2335
|
this.inputField.disabled = disabled;
|
|
2068
2336
|
return this;
|
|
2069
|
-
}
|
|
2070
|
-
setResponsive(responsive) {
|
|
2337
|
+
};
|
|
2338
|
+
AutocompleteUI.prototype.setResponsive = function (responsive) {
|
|
2071
2339
|
this.config.responsive = responsive;
|
|
2072
2340
|
setWidth(this.wrapper, this.config);
|
|
2073
2341
|
return this;
|
|
2074
|
-
}
|
|
2075
|
-
setWidth(width) {
|
|
2342
|
+
};
|
|
2343
|
+
AutocompleteUI.prototype.setWidth = function (width) {
|
|
2076
2344
|
this.config.width = width;
|
|
2077
2345
|
setWidth(this.wrapper, this.config);
|
|
2078
2346
|
return this;
|
|
2079
|
-
}
|
|
2080
|
-
setMaxHeight(height) {
|
|
2347
|
+
};
|
|
2348
|
+
AutocompleteUI.prototype.setMaxHeight = function (height) {
|
|
2081
2349
|
this.config.maxHeight = height;
|
|
2082
2350
|
setHeight(this.resultsList, this.config);
|
|
2083
2351
|
return this;
|
|
2084
|
-
}
|
|
2085
|
-
setMinCharacters(minCharacters) {
|
|
2352
|
+
};
|
|
2353
|
+
AutocompleteUI.prototype.setMinCharacters = function (minCharacters) {
|
|
2086
2354
|
this.config.minCharacters = minCharacters;
|
|
2087
2355
|
this.config.threshold = minCharacters;
|
|
2088
2356
|
return this;
|
|
2089
|
-
}
|
|
2090
|
-
setLimit(limit) {
|
|
2357
|
+
};
|
|
2358
|
+
AutocompleteUI.prototype.setLimit = function (limit) {
|
|
2091
2359
|
this.config.limit = limit;
|
|
2092
2360
|
return this;
|
|
2093
|
-
}
|
|
2094
|
-
setShowMarkers(showMarkers) {
|
|
2361
|
+
};
|
|
2362
|
+
AutocompleteUI.prototype.setShowMarkers = function (showMarkers) {
|
|
2095
2363
|
this.config.showMarkers = showMarkers;
|
|
2096
2364
|
if (showMarkers) {
|
|
2097
|
-
|
|
2365
|
+
var marker = document.createElement('img');
|
|
2098
2366
|
marker.classList.add(CLASSNAMES.RESULTS_MARKER);
|
|
2099
2367
|
marker.setAttribute('src', getMarkerIcon(this.config.markerColor));
|
|
2100
|
-
|
|
2101
|
-
for (
|
|
2102
|
-
|
|
2368
|
+
var resultItems = this.resultsList.getElementsByTagName('li');
|
|
2369
|
+
for (var i = 0; i < resultItems.length; i++) {
|
|
2370
|
+
var currentMarker = resultItems[i].getElementsByClassName(CLASSNAMES.RESULTS_MARKER)[0];
|
|
2103
2371
|
if (!currentMarker) {
|
|
2104
2372
|
resultItems[i].prepend(marker.cloneNode());
|
|
2105
2373
|
}
|
|
2106
2374
|
}
|
|
2107
2375
|
}
|
|
2108
2376
|
else {
|
|
2109
|
-
|
|
2110
|
-
for (
|
|
2111
|
-
|
|
2377
|
+
var resultItems = this.resultsList.getElementsByTagName('li');
|
|
2378
|
+
for (var i = 0; i < resultItems.length; i++) {
|
|
2379
|
+
var marker = resultItems[i].getElementsByClassName(CLASSNAMES.RESULTS_MARKER)[0];
|
|
2112
2380
|
if (marker) {
|
|
2113
2381
|
marker.remove();
|
|
2114
2382
|
}
|
|
2115
2383
|
}
|
|
2116
2384
|
}
|
|
2117
2385
|
return this;
|
|
2118
|
-
}
|
|
2119
|
-
setMarkerColor(color) {
|
|
2386
|
+
};
|
|
2387
|
+
AutocompleteUI.prototype.setMarkerColor = function (color) {
|
|
2120
2388
|
this.config.markerColor = color;
|
|
2121
|
-
|
|
2122
|
-
for (
|
|
2389
|
+
var marker = this.resultsList.getElementsByClassName(CLASSNAMES.RESULTS_MARKER);
|
|
2390
|
+
for (var i = 0; i < marker.length; i++) {
|
|
2123
2391
|
marker[i].setAttribute('src', getMarkerIcon(color));
|
|
2124
2392
|
}
|
|
2125
2393
|
return this;
|
|
2126
|
-
}
|
|
2127
|
-
setHideResultsOnBlur(hideResultsOnBlur) {
|
|
2394
|
+
};
|
|
2395
|
+
AutocompleteUI.prototype.setHideResultsOnBlur = function (hideResultsOnBlur) {
|
|
2128
2396
|
this.config.hideResultsOnBlur = hideResultsOnBlur;
|
|
2129
2397
|
if (hideResultsOnBlur) {
|
|
2130
2398
|
this.inputField.addEventListener('blur', this.close.bind(this), true);
|
|
@@ -2133,25 +2401,37 @@ class AutocompleteUI {
|
|
|
2133
2401
|
this.inputField.removeEventListener('blur', this.close.bind(this), true);
|
|
2134
2402
|
}
|
|
2135
2403
|
return this;
|
|
2136
|
-
}
|
|
2137
|
-
|
|
2404
|
+
};
|
|
2405
|
+
return AutocompleteUI;
|
|
2406
|
+
}());
|
|
2138
2407
|
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2408
|
+
var isSecretKey = function (key) { return (key.includes('_sk_')); };
|
|
2409
|
+
var isLiveKey = function (key) { return (key.includes('_live_')); };
|
|
2410
|
+
var Radar = /** @class */ (function () {
|
|
2411
|
+
function Radar() {
|
|
2412
|
+
}
|
|
2413
|
+
Object.defineProperty(Radar, "VERSION", {
|
|
2414
|
+
get: function () {
|
|
2415
|
+
return SDK_VERSION;
|
|
2416
|
+
},
|
|
2417
|
+
enumerable: false,
|
|
2418
|
+
configurable: true
|
|
2419
|
+
});
|
|
2420
|
+
Object.defineProperty(Radar, "ui", {
|
|
2421
|
+
// "ui" namespace
|
|
2422
|
+
get: function () {
|
|
2423
|
+
return {
|
|
2424
|
+
maplibregl: MapUI.getMapLibre(),
|
|
2425
|
+
map: MapUI.createMap,
|
|
2426
|
+
marker: MapUI.createMarker,
|
|
2427
|
+
autocomplete: AutocompleteUI.createAutocomplete,
|
|
2428
|
+
};
|
|
2429
|
+
},
|
|
2430
|
+
enumerable: false,
|
|
2431
|
+
configurable: true
|
|
2432
|
+
});
|
|
2433
|
+
Radar.initialize = function (publishableKey, options) {
|
|
2434
|
+
if (options === void 0) { options = {}; }
|
|
2155
2435
|
if (!publishableKey) {
|
|
2156
2436
|
throw new RadarPublishableKeyError('Publishable key required in initialization.');
|
|
2157
2437
|
}
|
|
@@ -2159,125 +2439,128 @@ class Radar {
|
|
|
2159
2439
|
throw new RadarPublishableKeyError('Secret keys are not allowed. Please use your Radar publishable key.');
|
|
2160
2440
|
}
|
|
2161
2441
|
// store settings in global config
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
publishableKey,
|
|
2167
|
-
live,
|
|
2168
|
-
logLevel,
|
|
2169
|
-
debug,
|
|
2442
|
+
var live = isLiveKey(publishableKey);
|
|
2443
|
+
var logLevel = live ? 'error' : 'info';
|
|
2444
|
+
var debug = !live;
|
|
2445
|
+
var radarOptions = Object.assign(Config.defaultOptions, {
|
|
2446
|
+
publishableKey: publishableKey,
|
|
2447
|
+
live: live,
|
|
2448
|
+
logLevel: logLevel,
|
|
2449
|
+
debug: debug,
|
|
2170
2450
|
}, options);
|
|
2171
2451
|
Config.setup(radarOptions);
|
|
2172
|
-
Logger.info(
|
|
2452
|
+
Logger.info("initialized with ".concat(live ? 'live' : 'test', " publishableKey."));
|
|
2173
2453
|
if (options.debug) {
|
|
2174
|
-
Logger.info(
|
|
2454
|
+
Logger.info("using options: ".concat(JSON.stringify(options)));
|
|
2175
2455
|
}
|
|
2176
2456
|
// NOTE(jasonl): this allows us to run jest tests
|
|
2177
2457
|
// without having to mock the ConfigAPI.getConfig call
|
|
2178
2458
|
if (!(window === null || window === void 0 ? void 0 : window.RADAR_TEST_ENV)) {
|
|
2179
2459
|
ConfigAPI.getConfig();
|
|
2180
2460
|
}
|
|
2181
|
-
}
|
|
2182
|
-
|
|
2461
|
+
};
|
|
2462
|
+
Radar.clear = function () {
|
|
2183
2463
|
Config.clear();
|
|
2184
|
-
}
|
|
2464
|
+
};
|
|
2185
2465
|
///////////////////////
|
|
2186
2466
|
// geofencing platform
|
|
2187
2467
|
///////////////////////
|
|
2188
|
-
|
|
2468
|
+
Radar.setUserId = function (userId) {
|
|
2189
2469
|
if (!userId) {
|
|
2190
2470
|
Storage.removeItem(Storage.USER_ID);
|
|
2191
2471
|
return;
|
|
2192
2472
|
}
|
|
2193
2473
|
Storage.setItem(Storage.USER_ID, String(userId).trim());
|
|
2194
|
-
}
|
|
2195
|
-
|
|
2474
|
+
};
|
|
2475
|
+
Radar.setDescription = function (description) {
|
|
2196
2476
|
if (!description) {
|
|
2197
2477
|
Storage.removeItem(Storage.DESCRIPTION);
|
|
2198
2478
|
return;
|
|
2199
2479
|
}
|
|
2200
2480
|
Storage.setItem(Storage.DESCRIPTION, String(description).trim());
|
|
2201
|
-
}
|
|
2202
|
-
|
|
2481
|
+
};
|
|
2482
|
+
Radar.setMetadata = function (metadata) {
|
|
2203
2483
|
if (!metadata) {
|
|
2204
2484
|
Storage.removeItem(Storage.METADATA);
|
|
2205
2485
|
return;
|
|
2206
2486
|
}
|
|
2207
2487
|
Storage.setItem(Storage.METADATA, JSON.stringify(metadata));
|
|
2208
|
-
}
|
|
2209
|
-
|
|
2488
|
+
};
|
|
2489
|
+
Radar.getLocation = function () {
|
|
2210
2490
|
return Navigator.getCurrentPosition();
|
|
2211
|
-
}
|
|
2212
|
-
|
|
2491
|
+
};
|
|
2492
|
+
Radar.trackOnce = function (params) {
|
|
2493
|
+
if (params === void 0) { params = {}; }
|
|
2213
2494
|
try {
|
|
2214
2495
|
return TrackAPI.trackOnce(params);
|
|
2215
2496
|
}
|
|
2216
2497
|
finally {
|
|
2217
2498
|
ConfigAPI.getConfig(params); // call with updated permissions
|
|
2218
2499
|
}
|
|
2219
|
-
}
|
|
2220
|
-
|
|
2500
|
+
};
|
|
2501
|
+
Radar.trackVerified = function (params) {
|
|
2502
|
+
if (params === void 0) { params = {}; }
|
|
2221
2503
|
return VerifyAPI.trackVerified(params);
|
|
2222
|
-
}
|
|
2223
|
-
|
|
2504
|
+
};
|
|
2505
|
+
Radar.getContext = function (params) {
|
|
2224
2506
|
return ContextAPI.getContext(params);
|
|
2225
|
-
}
|
|
2226
|
-
|
|
2507
|
+
};
|
|
2508
|
+
Radar.setTripOptions = function (tripOptions) {
|
|
2227
2509
|
TripsAPI.setTripOptions(tripOptions);
|
|
2228
|
-
}
|
|
2229
|
-
|
|
2510
|
+
};
|
|
2511
|
+
Radar.clearTripOptions = function () {
|
|
2230
2512
|
TripsAPI.clearTripOptions();
|
|
2231
|
-
}
|
|
2232
|
-
|
|
2513
|
+
};
|
|
2514
|
+
Radar.getTripOptions = function () {
|
|
2233
2515
|
return TripsAPI.getTripOptions();
|
|
2234
|
-
}
|
|
2235
|
-
|
|
2516
|
+
};
|
|
2517
|
+
Radar.startTrip = function (tripOptions) {
|
|
2236
2518
|
return TripsAPI.startTrip(tripOptions);
|
|
2237
|
-
}
|
|
2238
|
-
|
|
2519
|
+
};
|
|
2520
|
+
Radar.updateTrip = function (tripOptions) {
|
|
2239
2521
|
return TripsAPI.updateTrip(tripOptions);
|
|
2240
|
-
}
|
|
2241
|
-
|
|
2522
|
+
};
|
|
2523
|
+
Radar.completeTrip = function () {
|
|
2242
2524
|
return TripsAPI.completeTrip();
|
|
2243
|
-
}
|
|
2244
|
-
|
|
2525
|
+
};
|
|
2526
|
+
Radar.cancelTrip = function () {
|
|
2245
2527
|
return TripsAPI.cancelTrip();
|
|
2246
|
-
}
|
|
2247
|
-
|
|
2528
|
+
};
|
|
2529
|
+
Radar.logConversion = function (params) {
|
|
2248
2530
|
return ConversionsAPI.logConversion(params);
|
|
2249
|
-
}
|
|
2531
|
+
};
|
|
2250
2532
|
/////////////////
|
|
2251
2533
|
// maps platform
|
|
2252
2534
|
/////////////////
|
|
2253
|
-
|
|
2535
|
+
Radar.forwardGeocode = function (params) {
|
|
2254
2536
|
return Geocoding.forwardGeocode(params);
|
|
2255
|
-
}
|
|
2256
|
-
|
|
2537
|
+
};
|
|
2538
|
+
Radar.reverseGeocode = function (params) {
|
|
2257
2539
|
return Geocoding.reverseGeocode(params);
|
|
2258
|
-
}
|
|
2259
|
-
|
|
2540
|
+
};
|
|
2541
|
+
Radar.ipGeocode = function () {
|
|
2260
2542
|
return Geocoding.ipGeocode();
|
|
2261
|
-
}
|
|
2262
|
-
|
|
2543
|
+
};
|
|
2544
|
+
Radar.autocomplete = function (params) {
|
|
2263
2545
|
return SearchAPI.autocomplete(params);
|
|
2264
|
-
}
|
|
2265
|
-
|
|
2546
|
+
};
|
|
2547
|
+
Radar.searchGeofences = function (params) {
|
|
2266
2548
|
return SearchAPI.searchGeofences(params);
|
|
2267
|
-
}
|
|
2268
|
-
|
|
2549
|
+
};
|
|
2550
|
+
Radar.searchPlaces = function (params) {
|
|
2269
2551
|
return SearchAPI.searchPlaces(params);
|
|
2270
|
-
}
|
|
2271
|
-
|
|
2552
|
+
};
|
|
2553
|
+
Radar.validateAddress = function (params) {
|
|
2272
2554
|
return AddressesAPI.validateAddress(params);
|
|
2273
|
-
}
|
|
2274
|
-
|
|
2555
|
+
};
|
|
2556
|
+
Radar.distance = function (params) {
|
|
2275
2557
|
return RoutingAPI.distance(params);
|
|
2276
|
-
}
|
|
2277
|
-
|
|
2558
|
+
};
|
|
2559
|
+
Radar.matrix = function (params) {
|
|
2278
2560
|
return RoutingAPI.matrix(params);
|
|
2279
|
-
}
|
|
2280
|
-
|
|
2561
|
+
};
|
|
2562
|
+
return Radar;
|
|
2563
|
+
}());
|
|
2281
2564
|
|
|
2282
2565
|
export { Radar as default };
|
|
2283
2566
|
//# sourceMappingURL=radar.js.map
|