radar-sdk-js 3.0.1 → 3.1.0-beta.10
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 -0
- package/dist/index.js +409 -49
- package/dist/radar.js +409 -49
- package/dist/radar.min.js +1 -1
- package/package.json +1 -1
- package/src/api/matrix.js +35 -0
- package/src/api/track.js +24 -10
- package/src/api/trips.js +30 -0
- package/src/cookie.js +18 -2
- package/src/http.js +10 -0
- package/src/index.js +91 -2
- package/src/tripStatus.js +9 -0
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,13 @@ See the Radar overview documentation [here](https://radar.io/documentation).
|
|
|
12
12
|
|
|
13
13
|
Then, see the Radar web SDK documentation [here](https://radar.io/documentation/sdk/web).
|
|
14
14
|
|
|
15
|
+
## Running locally
|
|
16
|
+
|
|
17
|
+
1. Clone the repo
|
|
18
|
+
2. `npm install`
|
|
19
|
+
3. To run the SDK in a browser, run `npm run build && node demo/server.js`, which should open a tab in your browser of choice. Modify the `/src/index.html` file as needed
|
|
20
|
+
4. To run tests, run `npm run test`
|
|
21
|
+
|
|
15
22
|
## Support
|
|
16
23
|
|
|
17
24
|
Have questions? We're here to help! Email us at [support@radar.io](mailto:support@radar.io).
|
package/dist/index.js
CHANGED
|
@@ -520,6 +520,28 @@ var _export = function (options, source) {
|
|
|
520
520
|
}
|
|
521
521
|
};
|
|
522
522
|
|
|
523
|
+
// `ToObject` abstract operation
|
|
524
|
+
// https://tc39.github.io/ecma262/#sec-toobject
|
|
525
|
+
var toObject = function (argument) {
|
|
526
|
+
return Object(requireObjectCoercible(argument));
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
// `Object.keys` method
|
|
530
|
+
// https://tc39.github.io/ecma262/#sec-object.keys
|
|
531
|
+
var objectKeys = Object.keys || function keys(O) {
|
|
532
|
+
return objectKeysInternal(O, enumBugKeys);
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
var FAILS_ON_PRIMITIVES = fails(function () { objectKeys(1); });
|
|
536
|
+
|
|
537
|
+
// `Object.keys` method
|
|
538
|
+
// https://tc39.github.io/ecma262/#sec-object.keys
|
|
539
|
+
_export({ target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES }, {
|
|
540
|
+
keys: function keys(it) {
|
|
541
|
+
return objectKeys(toObject(it));
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
|
|
523
545
|
// a string of all valid unicode whitespaces
|
|
524
546
|
// eslint-disable-next-line max-len
|
|
525
547
|
var whitespaces = '\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF';
|
|
@@ -645,18 +667,61 @@ function _createClass(Constructor, protoProps, staticProps) {
|
|
|
645
667
|
return Constructor;
|
|
646
668
|
}
|
|
647
669
|
|
|
670
|
+
function _defineProperty(obj, key, value) {
|
|
671
|
+
if (key in obj) {
|
|
672
|
+
Object.defineProperty(obj, key, {
|
|
673
|
+
value: value,
|
|
674
|
+
enumerable: true,
|
|
675
|
+
configurable: true,
|
|
676
|
+
writable: true
|
|
677
|
+
});
|
|
678
|
+
} else {
|
|
679
|
+
obj[key] = value;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
return obj;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
function ownKeys$1(object, enumerableOnly) {
|
|
686
|
+
var keys = Object.keys(object);
|
|
687
|
+
|
|
688
|
+
if (Object.getOwnPropertySymbols) {
|
|
689
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
690
|
+
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
691
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
692
|
+
});
|
|
693
|
+
keys.push.apply(keys, symbols);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
return keys;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
function _objectSpread2(target) {
|
|
700
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
701
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
702
|
+
|
|
703
|
+
if (i % 2) {
|
|
704
|
+
ownKeys$1(Object(source), true).forEach(function (key) {
|
|
705
|
+
_defineProperty(target, key, source[key]);
|
|
706
|
+
});
|
|
707
|
+
} else if (Object.getOwnPropertyDescriptors) {
|
|
708
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
709
|
+
} else {
|
|
710
|
+
ownKeys$1(Object(source)).forEach(function (key) {
|
|
711
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
return target;
|
|
717
|
+
}
|
|
718
|
+
|
|
648
719
|
// `IsArray` abstract operation
|
|
649
720
|
// https://tc39.github.io/ecma262/#sec-isarray
|
|
650
721
|
var isArray = Array.isArray || function isArray(arg) {
|
|
651
722
|
return classofRaw(arg) == 'Array';
|
|
652
723
|
};
|
|
653
724
|
|
|
654
|
-
// `ToObject` abstract operation
|
|
655
|
-
// https://tc39.github.io/ecma262/#sec-toobject
|
|
656
|
-
var toObject = function (argument) {
|
|
657
|
-
return Object(requireObjectCoercible(argument));
|
|
658
|
-
};
|
|
659
|
-
|
|
660
725
|
var createProperty = function (object, key, value) {
|
|
661
726
|
var propertyKey = toPrimitive(key);
|
|
662
727
|
if (propertyKey in object) objectDefineProperty.f(object, propertyKey, createPropertyDescriptor(0, value));
|
|
@@ -876,12 +941,6 @@ var arrayIteration = {
|
|
|
876
941
|
findIndex: createMethod$2(6)
|
|
877
942
|
};
|
|
878
943
|
|
|
879
|
-
// `Object.keys` method
|
|
880
|
-
// https://tc39.github.io/ecma262/#sec-object.keys
|
|
881
|
-
var objectKeys = Object.keys || function keys(O) {
|
|
882
|
-
return objectKeysInternal(O, enumBugKeys);
|
|
883
|
-
};
|
|
884
|
-
|
|
885
944
|
// `Object.defineProperties` method
|
|
886
945
|
// https://tc39.github.io/ecma262/#sec-object.defineproperties
|
|
887
946
|
var objectDefineProperties = descriptors ? Object.defineProperties : function defineProperties(O, Properties) {
|
|
@@ -1537,7 +1596,8 @@ var Cookie = /*#__PURE__*/function () {
|
|
|
1537
1596
|
var date = new Date();
|
|
1538
1597
|
date.setFullYear(date.getFullYear() + 10);
|
|
1539
1598
|
var expires = "expires=".concat(date.toGMTString());
|
|
1540
|
-
|
|
1599
|
+
var sameSite = 'samesite=strict';
|
|
1600
|
+
document.cookie = "".concat(key, "=").concat(value, ";path=/;").concat(sameSite, ";").concat(expires);
|
|
1541
1601
|
} // delete cookie with {key}
|
|
1542
1602
|
|
|
1543
1603
|
}, {
|
|
@@ -1560,6 +1620,11 @@ var Cookie = /*#__PURE__*/function () {
|
|
|
1560
1620
|
get: function get() {
|
|
1561
1621
|
return 'radar-deviceId';
|
|
1562
1622
|
}
|
|
1623
|
+
}, {
|
|
1624
|
+
key: "DEVICE_TYPE",
|
|
1625
|
+
get: function get() {
|
|
1626
|
+
return 'radar-deviceType';
|
|
1627
|
+
}
|
|
1563
1628
|
}, {
|
|
1564
1629
|
key: "METADATA",
|
|
1565
1630
|
get: function get() {
|
|
@@ -1580,6 +1645,26 @@ var Cookie = /*#__PURE__*/function () {
|
|
|
1580
1645
|
get: function get() {
|
|
1581
1646
|
return 'radar-userId';
|
|
1582
1647
|
}
|
|
1648
|
+
}, {
|
|
1649
|
+
key: "INSTALL_ID",
|
|
1650
|
+
get: function get() {
|
|
1651
|
+
return 'radar-installId';
|
|
1652
|
+
}
|
|
1653
|
+
}, {
|
|
1654
|
+
key: "TRIP_OPTIONS",
|
|
1655
|
+
get: function get() {
|
|
1656
|
+
return 'radar-trip-options';
|
|
1657
|
+
}
|
|
1658
|
+
}, {
|
|
1659
|
+
key: "CUSTOM_HEADERS",
|
|
1660
|
+
get: function get() {
|
|
1661
|
+
return 'radar-custom-headers';
|
|
1662
|
+
}
|
|
1663
|
+
}, {
|
|
1664
|
+
key: "BASE_API_PATH",
|
|
1665
|
+
get: function get() {
|
|
1666
|
+
return 'radar-base-api-path';
|
|
1667
|
+
}
|
|
1583
1668
|
}]);
|
|
1584
1669
|
|
|
1585
1670
|
return Cookie;
|
|
@@ -3189,16 +3274,6 @@ _export({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT || !USES_TO
|
|
|
3189
3274
|
}
|
|
3190
3275
|
});
|
|
3191
3276
|
|
|
3192
|
-
var FAILS_ON_PRIMITIVES = fails(function () { objectKeys(1); });
|
|
3193
|
-
|
|
3194
|
-
// `Object.keys` method
|
|
3195
|
-
// https://tc39.github.io/ecma262/#sec-object.keys
|
|
3196
|
-
_export({ target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES }, {
|
|
3197
|
-
keys: function keys(it) {
|
|
3198
|
-
return objectKeys(toObject(it));
|
|
3199
|
-
}
|
|
3200
|
-
});
|
|
3201
|
-
|
|
3202
3277
|
// iterable DOM collections
|
|
3203
3278
|
// flag - `iterable` interface - 'entries', 'keys', 'values', 'forEach' methods
|
|
3204
3279
|
var domIterables = {
|
|
@@ -3263,7 +3338,7 @@ var API_HOST = /*#__PURE__*/function () {
|
|
|
3263
3338
|
return API_HOST;
|
|
3264
3339
|
}();
|
|
3265
3340
|
|
|
3266
|
-
var SDK_VERSION = '3.0.
|
|
3341
|
+
var SDK_VERSION = '3.1.0-beta.10';
|
|
3267
3342
|
|
|
3268
3343
|
var Http = /*#__PURE__*/function () {
|
|
3269
3344
|
function Http() {
|
|
@@ -3305,12 +3380,22 @@ var Http = /*#__PURE__*/function () {
|
|
|
3305
3380
|
if (!publishableKey) {
|
|
3306
3381
|
reject(STATUS.ERROR_PUBLISHABLE_KEY);
|
|
3307
3382
|
return;
|
|
3308
|
-
}
|
|
3383
|
+
} // set headers
|
|
3384
|
+
|
|
3309
3385
|
|
|
3310
3386
|
xhr.setRequestHeader('Authorization', publishableKey);
|
|
3311
3387
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
3312
3388
|
xhr.setRequestHeader('X-Radar-Device-Type', 'Web');
|
|
3313
|
-
xhr.setRequestHeader('X-Radar-SDK-Version', SDK_VERSION);
|
|
3389
|
+
xhr.setRequestHeader('X-Radar-SDK-Version', SDK_VERSION); // set custom headers if present
|
|
3390
|
+
|
|
3391
|
+
var customHeaders = Cookie.getCookie(Cookie.CUSTOM_HEADERS);
|
|
3392
|
+
|
|
3393
|
+
if (customHeaders) {
|
|
3394
|
+
var headers = JSON.parse(customHeaders);
|
|
3395
|
+
Object.keys(headers).forEach(function (header) {
|
|
3396
|
+
xhr.setRequestHeader(header, headers[header]);
|
|
3397
|
+
});
|
|
3398
|
+
}
|
|
3314
3399
|
|
|
3315
3400
|
xhr.onload = function () {
|
|
3316
3401
|
var response;
|
|
@@ -3654,6 +3739,86 @@ var Routing = /*#__PURE__*/function () {
|
|
|
3654
3739
|
return Routing;
|
|
3655
3740
|
}();
|
|
3656
3741
|
|
|
3742
|
+
var Matrix = /*#__PURE__*/function () {
|
|
3743
|
+
function Matrix() {
|
|
3744
|
+
_classCallCheck(this, Matrix);
|
|
3745
|
+
}
|
|
3746
|
+
|
|
3747
|
+
_createClass(Matrix, null, [{
|
|
3748
|
+
key: "getMatrixDistances",
|
|
3749
|
+
value: function () {
|
|
3750
|
+
var _getMatrixDistances = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
3751
|
+
var routingOptions,
|
|
3752
|
+
_yield$Navigator$getC,
|
|
3753
|
+
latitude,
|
|
3754
|
+
longitude,
|
|
3755
|
+
origins,
|
|
3756
|
+
destinations,
|
|
3757
|
+
mode,
|
|
3758
|
+
units,
|
|
3759
|
+
params,
|
|
3760
|
+
_args = arguments;
|
|
3761
|
+
|
|
3762
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
3763
|
+
while (1) {
|
|
3764
|
+
switch (_context.prev = _context.next) {
|
|
3765
|
+
case 0:
|
|
3766
|
+
routingOptions = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
3767
|
+
|
|
3768
|
+
if (routingOptions.origins) {
|
|
3769
|
+
_context.next = 8;
|
|
3770
|
+
break;
|
|
3771
|
+
}
|
|
3772
|
+
|
|
3773
|
+
_context.next = 4;
|
|
3774
|
+
return Navigator.getCurrentPosition();
|
|
3775
|
+
|
|
3776
|
+
case 4:
|
|
3777
|
+
_yield$Navigator$getC = _context.sent;
|
|
3778
|
+
latitude = _yield$Navigator$getC.latitude;
|
|
3779
|
+
longitude = _yield$Navigator$getC.longitude;
|
|
3780
|
+
routingOptions.origins = [{
|
|
3781
|
+
latitude: latitude,
|
|
3782
|
+
longitude: longitude
|
|
3783
|
+
}];
|
|
3784
|
+
|
|
3785
|
+
case 8:
|
|
3786
|
+
origins = routingOptions.origins, destinations = routingOptions.destinations, mode = routingOptions.mode, units = routingOptions.units;
|
|
3787
|
+
origins = origins || [];
|
|
3788
|
+
origins = origins.map(function (origin) {
|
|
3789
|
+
return "".concat(origin.latitude, ", ").concat(origin.longitude);
|
|
3790
|
+
}).join('|');
|
|
3791
|
+
destinations = destinations || [];
|
|
3792
|
+
destinations.map(function (destination) {
|
|
3793
|
+
return "".concat(destination.latitude, ", ").concat(destination.longitude);
|
|
3794
|
+
}).join('|');
|
|
3795
|
+
params = {
|
|
3796
|
+
origins: origins,
|
|
3797
|
+
destinations: destinations,
|
|
3798
|
+
mode: mode,
|
|
3799
|
+
units: units
|
|
3800
|
+
};
|
|
3801
|
+
return _context.abrupt("return", Http.request('GET', 'v1/route/matrix', params));
|
|
3802
|
+
|
|
3803
|
+
case 15:
|
|
3804
|
+
case "end":
|
|
3805
|
+
return _context.stop();
|
|
3806
|
+
}
|
|
3807
|
+
}
|
|
3808
|
+
}, _callee);
|
|
3809
|
+
}));
|
|
3810
|
+
|
|
3811
|
+
function getMatrixDistances() {
|
|
3812
|
+
return _getMatrixDistances.apply(this, arguments);
|
|
3813
|
+
}
|
|
3814
|
+
|
|
3815
|
+
return getMatrixDistances;
|
|
3816
|
+
}()
|
|
3817
|
+
}]);
|
|
3818
|
+
|
|
3819
|
+
return Matrix;
|
|
3820
|
+
}();
|
|
3821
|
+
|
|
3657
3822
|
var Search = /*#__PURE__*/function () {
|
|
3658
3823
|
function Search() {
|
|
3659
3824
|
_classCallCheck(this, Search);
|
|
@@ -4058,40 +4223,49 @@ var Track = /*#__PURE__*/function () {
|
|
|
4058
4223
|
key: "trackOnce",
|
|
4059
4224
|
value: function () {
|
|
4060
4225
|
var _trackOnce = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
4061
|
-
var
|
|
4062
|
-
_location,
|
|
4226
|
+
var params,
|
|
4063
4227
|
latitude,
|
|
4064
4228
|
longitude,
|
|
4065
4229
|
accuracy,
|
|
4230
|
+
deviceLocation,
|
|
4066
4231
|
deviceId,
|
|
4067
4232
|
userId,
|
|
4233
|
+
installId,
|
|
4234
|
+
deviceType,
|
|
4068
4235
|
description,
|
|
4069
4236
|
metadata,
|
|
4237
|
+
tripOptions,
|
|
4070
4238
|
body,
|
|
4239
|
+
basePath,
|
|
4240
|
+
trackEndpoint,
|
|
4071
4241
|
response,
|
|
4072
4242
|
_args = arguments;
|
|
4073
|
-
|
|
4074
4243
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
4075
4244
|
while (1) {
|
|
4076
4245
|
switch (_context.prev = _context.next) {
|
|
4077
4246
|
case 0:
|
|
4078
|
-
|
|
4247
|
+
params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
4248
|
+
latitude = params.latitude, longitude = params.longitude, accuracy = params.accuracy;
|
|
4079
4249
|
|
|
4080
|
-
if (!(!
|
|
4081
|
-
_context.next =
|
|
4250
|
+
if (!(!latitude || !longitude)) {
|
|
4251
|
+
_context.next = 9;
|
|
4082
4252
|
break;
|
|
4083
4253
|
}
|
|
4084
4254
|
|
|
4085
|
-
_context.next =
|
|
4255
|
+
_context.next = 5;
|
|
4086
4256
|
return Navigator.getCurrentPosition();
|
|
4087
4257
|
|
|
4088
|
-
case 4:
|
|
4089
|
-
location = _context.sent;
|
|
4090
|
-
|
|
4091
4258
|
case 5:
|
|
4092
|
-
|
|
4259
|
+
deviceLocation = _context.sent;
|
|
4260
|
+
latitude = deviceLocation.latitude;
|
|
4261
|
+
longitude = deviceLocation.longitude;
|
|
4262
|
+
accuracy = deviceLocation.accuracy;
|
|
4263
|
+
|
|
4264
|
+
case 9:
|
|
4093
4265
|
deviceId = Device.getId();
|
|
4094
4266
|
userId = Cookie.getCookie(Cookie.USER_ID);
|
|
4267
|
+
installId = Cookie.getCookie(Cookie.INSTALL_ID) || deviceId;
|
|
4268
|
+
deviceType = Cookie.getCookie(Cookie.DEVICE_TYPE) || 'Web';
|
|
4095
4269
|
description = Cookie.getCookie(Cookie.DESCRIPTION);
|
|
4096
4270
|
metadata = Cookie.getCookie(Cookie.METADATA);
|
|
4097
4271
|
|
|
@@ -4099,29 +4273,42 @@ var Track = /*#__PURE__*/function () {
|
|
|
4099
4273
|
metadata = JSON.parse(metadata);
|
|
4100
4274
|
}
|
|
4101
4275
|
|
|
4102
|
-
|
|
4276
|
+
tripOptions = Cookie.getCookie(Cookie.TRIP_OPTIONS);
|
|
4277
|
+
|
|
4278
|
+
if (tripOptions) {
|
|
4279
|
+
tripOptions = JSON.parse(tripOptions);
|
|
4280
|
+
}
|
|
4281
|
+
|
|
4282
|
+
body = _objectSpread2({}, params, {
|
|
4103
4283
|
accuracy: accuracy,
|
|
4104
4284
|
description: description,
|
|
4105
4285
|
deviceId: deviceId,
|
|
4106
|
-
deviceType:
|
|
4286
|
+
deviceType: deviceType,
|
|
4107
4287
|
foreground: true,
|
|
4108
|
-
installId:
|
|
4288
|
+
installId: installId,
|
|
4109
4289
|
latitude: latitude,
|
|
4110
4290
|
longitude: longitude,
|
|
4111
4291
|
metadata: metadata,
|
|
4112
4292
|
sdkVersion: SDK_VERSION,
|
|
4113
4293
|
stopped: true,
|
|
4114
|
-
userId: userId
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4294
|
+
userId: userId,
|
|
4295
|
+
tripOptions: tripOptions
|
|
4296
|
+
});
|
|
4297
|
+
basePath = Cookie.getCookie(Cookie.BASE_API_PATH) || 'v1';
|
|
4298
|
+
trackEndpoint = "".concat(basePath, "/track");
|
|
4299
|
+
_context.next = 23;
|
|
4300
|
+
return Http.request('POST', trackEndpoint, body);
|
|
4301
|
+
|
|
4302
|
+
case 23:
|
|
4120
4303
|
response = _context.sent;
|
|
4121
|
-
response.location =
|
|
4304
|
+
response.location = {
|
|
4305
|
+
latitude: latitude,
|
|
4306
|
+
longitude: longitude,
|
|
4307
|
+
accuracy: accuracy
|
|
4308
|
+
};
|
|
4122
4309
|
return _context.abrupt("return", response);
|
|
4123
4310
|
|
|
4124
|
-
case
|
|
4311
|
+
case 26:
|
|
4125
4312
|
case "end":
|
|
4126
4313
|
return _context.stop();
|
|
4127
4314
|
}
|
|
@@ -4140,6 +4327,72 @@ var Track = /*#__PURE__*/function () {
|
|
|
4140
4327
|
return Track;
|
|
4141
4328
|
}();
|
|
4142
4329
|
|
|
4330
|
+
var Trips = /*#__PURE__*/function () {
|
|
4331
|
+
function Trips() {
|
|
4332
|
+
_classCallCheck(this, Trips);
|
|
4333
|
+
}
|
|
4334
|
+
|
|
4335
|
+
_createClass(Trips, null, [{
|
|
4336
|
+
key: "updateTrip",
|
|
4337
|
+
value: function () {
|
|
4338
|
+
var _updateTrip = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
4339
|
+
var tripOptions,
|
|
4340
|
+
status,
|
|
4341
|
+
externalId,
|
|
4342
|
+
destinationGeofenceTag,
|
|
4343
|
+
destinationGeofenceExternalId,
|
|
4344
|
+
mode,
|
|
4345
|
+
metadata,
|
|
4346
|
+
params,
|
|
4347
|
+
basePath,
|
|
4348
|
+
_args = arguments;
|
|
4349
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
4350
|
+
while (1) {
|
|
4351
|
+
switch (_context.prev = _context.next) {
|
|
4352
|
+
case 0:
|
|
4353
|
+
tripOptions = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
4354
|
+
status = _args.length > 1 ? _args[1] : undefined;
|
|
4355
|
+
externalId = tripOptions.externalId, destinationGeofenceTag = tripOptions.destinationGeofenceTag, destinationGeofenceExternalId = tripOptions.destinationGeofenceExternalId, mode = tripOptions.mode, metadata = tripOptions.metadata;
|
|
4356
|
+
params = {
|
|
4357
|
+
externalId: externalId,
|
|
4358
|
+
status: status,
|
|
4359
|
+
destinationGeofenceTag: destinationGeofenceTag,
|
|
4360
|
+
destinationGeofenceExternalId: destinationGeofenceExternalId,
|
|
4361
|
+
mode: mode,
|
|
4362
|
+
metadata: metadata
|
|
4363
|
+
};
|
|
4364
|
+
basePath = Cookie.getCookie(Cookie.BASE_API_PATH) || 'v1';
|
|
4365
|
+
return _context.abrupt("return", Http.request('PATCH', "".concat(basePath, "/trips/").concat(externalId), params));
|
|
4366
|
+
|
|
4367
|
+
case 6:
|
|
4368
|
+
case "end":
|
|
4369
|
+
return _context.stop();
|
|
4370
|
+
}
|
|
4371
|
+
}
|
|
4372
|
+
}, _callee);
|
|
4373
|
+
}));
|
|
4374
|
+
|
|
4375
|
+
function updateTrip() {
|
|
4376
|
+
return _updateTrip.apply(this, arguments);
|
|
4377
|
+
}
|
|
4378
|
+
|
|
4379
|
+
return updateTrip;
|
|
4380
|
+
}()
|
|
4381
|
+
}]);
|
|
4382
|
+
|
|
4383
|
+
return Trips;
|
|
4384
|
+
}();
|
|
4385
|
+
|
|
4386
|
+
var TRIP_STATUS = {
|
|
4387
|
+
STARTED: "started",
|
|
4388
|
+
APPROACHING: "approaching",
|
|
4389
|
+
ARRIVED: "arrived",
|
|
4390
|
+
COMPLETED: "completed",
|
|
4391
|
+
EXPIRED: "expired",
|
|
4392
|
+
CANCELED: "canceled",
|
|
4393
|
+
UNKNOWN: undefined
|
|
4394
|
+
};
|
|
4395
|
+
|
|
4143
4396
|
var defaultCallback = function defaultCallback() {};
|
|
4144
4397
|
|
|
4145
4398
|
var handleError = function handleError(callback) {
|
|
@@ -4177,8 +4430,9 @@ var Radar = /*#__PURE__*/function () {
|
|
|
4177
4430
|
}
|
|
4178
4431
|
}, {
|
|
4179
4432
|
key: "setHost",
|
|
4180
|
-
value: function setHost(host) {
|
|
4433
|
+
value: function setHost(host, baseApiPath) {
|
|
4181
4434
|
Cookie.setCookie(Cookie.HOST, host, true);
|
|
4435
|
+
Cookie.setCookie(Cookie.BASE_API_PATH, baseApiPath);
|
|
4182
4436
|
}
|
|
4183
4437
|
}, {
|
|
4184
4438
|
key: "setUserId",
|
|
@@ -4190,6 +4444,21 @@ var Radar = /*#__PURE__*/function () {
|
|
|
4190
4444
|
|
|
4191
4445
|
Cookie.setCookie(Cookie.USER_ID, String(userId).trim());
|
|
4192
4446
|
}
|
|
4447
|
+
}, {
|
|
4448
|
+
key: "setDeviceId",
|
|
4449
|
+
value: function setDeviceId(deviceId, installId) {
|
|
4450
|
+
if (deviceId) {
|
|
4451
|
+
Cookie.setCookie(Cookie.DEVICE_ID, String(deviceId).trim());
|
|
4452
|
+
} else {
|
|
4453
|
+
Cookie.deleteCookie(Cookie.DEVICE_ID);
|
|
4454
|
+
}
|
|
4455
|
+
|
|
4456
|
+
if (installId) {
|
|
4457
|
+
Cookie.setCookie(Cookie.INSTALL_ID, String(installId).trim());
|
|
4458
|
+
} else {
|
|
4459
|
+
Cookie.deleteCookie(Cookie.INSTALL_ID);
|
|
4460
|
+
}
|
|
4461
|
+
}
|
|
4193
4462
|
}, {
|
|
4194
4463
|
key: "setDescription",
|
|
4195
4464
|
value: function setDescription(description) {
|
|
@@ -4210,6 +4479,18 @@ var Radar = /*#__PURE__*/function () {
|
|
|
4210
4479
|
|
|
4211
4480
|
Cookie.setCookie(Cookie.METADATA, JSON.stringify(metadata));
|
|
4212
4481
|
}
|
|
4482
|
+
}, {
|
|
4483
|
+
key: "setRequestHeaders",
|
|
4484
|
+
value: function setRequestHeaders() {
|
|
4485
|
+
var headers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4486
|
+
|
|
4487
|
+
if (!Object.keys(headers).length) {
|
|
4488
|
+
Cookie.deleteCookie(Cookie.CUSTOM_HEADERS);
|
|
4489
|
+
return;
|
|
4490
|
+
}
|
|
4491
|
+
|
|
4492
|
+
Cookie.setCookie(Cookie.CUSTOM_HEADERS, JSON.stringify(headers));
|
|
4493
|
+
}
|
|
4213
4494
|
}, {
|
|
4214
4495
|
key: "getLocation",
|
|
4215
4496
|
value: function getLocation() {
|
|
@@ -4265,6 +4546,74 @@ var Radar = /*#__PURE__*/function () {
|
|
|
4265
4546
|
}, response);
|
|
4266
4547
|
}).catch(handleError(callback));
|
|
4267
4548
|
}
|
|
4549
|
+
}, {
|
|
4550
|
+
key: "startTrip",
|
|
4551
|
+
value: function startTrip(tripOptions) {
|
|
4552
|
+
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultCallback;
|
|
4553
|
+
Trips.updateTrip(tripOptions, TRIP_STATUS.STARTED).then(function (response) {
|
|
4554
|
+
Cookie.setCookie(Cookie.TRIP_OPTIONS, JSON.stringify(tripOptions));
|
|
4555
|
+
callback(null, {
|
|
4556
|
+
trip: response.trip,
|
|
4557
|
+
events: response.events,
|
|
4558
|
+
status: STATUS.SUCCESS
|
|
4559
|
+
}, response);
|
|
4560
|
+
}).catch(handleError(callback));
|
|
4561
|
+
}
|
|
4562
|
+
}, {
|
|
4563
|
+
key: "updateTrip",
|
|
4564
|
+
value: function updateTrip(tripOptions, status) {
|
|
4565
|
+
var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultCallback;
|
|
4566
|
+
Trips.updateTrip(tripOptions, status).then(function (response) {
|
|
4567
|
+
// set cookie
|
|
4568
|
+
Cookie.setCookie(Cookie.TRIP_OPTIONS, JSON.stringify(tripOptions));
|
|
4569
|
+
callback(null, {
|
|
4570
|
+
trip: response.trip,
|
|
4571
|
+
events: response.events,
|
|
4572
|
+
status: STATUS.SUCCESS
|
|
4573
|
+
}, response);
|
|
4574
|
+
}).catch(handleError(callback));
|
|
4575
|
+
}
|
|
4576
|
+
}, {
|
|
4577
|
+
key: "completeTrip",
|
|
4578
|
+
value: function completeTrip() {
|
|
4579
|
+
var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultCallback;
|
|
4580
|
+
var tripOptions = Radar.getTripOptions();
|
|
4581
|
+
Trips.updateTrip(tripOptions, TRIP_STATUS.COMPLETED).then(function (response) {
|
|
4582
|
+
// clear tripOptions
|
|
4583
|
+
Cookie.deleteCookie(Cookie.TRIP_OPTIONS);
|
|
4584
|
+
callback(null, {
|
|
4585
|
+
trip: response.trip,
|
|
4586
|
+
events: response.events,
|
|
4587
|
+
status: STATUS.SUCCESS
|
|
4588
|
+
}, response);
|
|
4589
|
+
}).catch(handleError(callback));
|
|
4590
|
+
}
|
|
4591
|
+
}, {
|
|
4592
|
+
key: "cancelTrip",
|
|
4593
|
+
value: function cancelTrip() {
|
|
4594
|
+
var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultCallback;
|
|
4595
|
+
var tripOptions = Radar.getTripOptions();
|
|
4596
|
+
Trips.updateTrip(tripOptions, TRIP_STATUS.CANCELED).then(function (response) {
|
|
4597
|
+
// clear tripOptions
|
|
4598
|
+
Cookie.deleteCookie(Cookie.TRIP_OPTIONS);
|
|
4599
|
+
callback(null, {
|
|
4600
|
+
trip: response.trip,
|
|
4601
|
+
events: response.events,
|
|
4602
|
+
status: STATUS.SUCCESS
|
|
4603
|
+
}, response);
|
|
4604
|
+
}).catch(handleError(callback));
|
|
4605
|
+
}
|
|
4606
|
+
}, {
|
|
4607
|
+
key: "getTripOptions",
|
|
4608
|
+
value: function getTripOptions() {
|
|
4609
|
+
var tripOptions = Cookie.getCookie(Cookie.TRIP_OPTIONS);
|
|
4610
|
+
|
|
4611
|
+
if (tripOptions) {
|
|
4612
|
+
tripOptions = JSON.parse(tripOptions);
|
|
4613
|
+
}
|
|
4614
|
+
|
|
4615
|
+
return tripOptions;
|
|
4616
|
+
}
|
|
4268
4617
|
}, {
|
|
4269
4618
|
key: "searchPlaces",
|
|
4270
4619
|
value: function searchPlaces(searchOptions) {
|
|
@@ -4362,6 +4711,17 @@ var Radar = /*#__PURE__*/function () {
|
|
|
4362
4711
|
}, response);
|
|
4363
4712
|
}).catch(handleError(callback));
|
|
4364
4713
|
}
|
|
4714
|
+
}, {
|
|
4715
|
+
key: "getMatrix",
|
|
4716
|
+
value: function getMatrix(routingOptions) {
|
|
4717
|
+
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultCallback;
|
|
4718
|
+
Matrix.getMatrixDistances(routingOptions).then(function (response) {
|
|
4719
|
+
callback(null, {
|
|
4720
|
+
routes: response.routes,
|
|
4721
|
+
status: STATUS.SUCCESS
|
|
4722
|
+
}, response);
|
|
4723
|
+
}).catch(handleError(callback));
|
|
4724
|
+
}
|
|
4365
4725
|
}, {
|
|
4366
4726
|
key: "VERSION",
|
|
4367
4727
|
get: function get() {
|