radar-sdk-js 3.2.1-beta.1 → 3.3.0-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/dist/index.js +2409 -1988
- package/dist/radar.js +2409 -1988
- package/dist/radar.min.js +1 -1
- package/package.json +3 -3
- package/src/api/track.js +8 -8
- package/src/api/trips.js +2 -2
- package/src/api_host.js +2 -2
- package/src/device.js +3 -3
- package/src/http.js +4 -4
- package/src/index.js +42 -32
- package/src/storage.js +80 -0
- package/src/version.js +1 -1
- package/src/cookie.js +0 -77
package/src/storage.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
class Storage {
|
|
2
|
+
|
|
3
|
+
// KEYS
|
|
4
|
+
static get DESCRIPTION() {
|
|
5
|
+
return 'radar-description';
|
|
6
|
+
}
|
|
7
|
+
static get DEVICE_ID() {
|
|
8
|
+
return 'radar-deviceId';
|
|
9
|
+
}
|
|
10
|
+
static get DEVICE_TYPE() {
|
|
11
|
+
return 'radar-deviceType';
|
|
12
|
+
}
|
|
13
|
+
static get METADATA() {
|
|
14
|
+
return 'radar-metadata';
|
|
15
|
+
}
|
|
16
|
+
static get HOST() {
|
|
17
|
+
return 'radar-host';
|
|
18
|
+
}
|
|
19
|
+
static get PUBLISHABLE_KEY() {
|
|
20
|
+
return 'radar-publishableKey';
|
|
21
|
+
}
|
|
22
|
+
static get USER_ID() {
|
|
23
|
+
return 'radar-userId';
|
|
24
|
+
}
|
|
25
|
+
static get INSTALL_ID() {
|
|
26
|
+
return 'radar-installId';
|
|
27
|
+
}
|
|
28
|
+
static get TRIP_OPTIONS() {
|
|
29
|
+
return 'radar-trip-options';
|
|
30
|
+
}
|
|
31
|
+
static get CUSTOM_HEADERS() {
|
|
32
|
+
return 'radar-custom-headers';
|
|
33
|
+
}
|
|
34
|
+
static get BASE_API_PATH() {
|
|
35
|
+
return 'radar-base-api-path';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static getStorage() {
|
|
39
|
+
return (window && window.sessionStorage) || undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static setItem(key, value) {
|
|
43
|
+
const storage = this.getStorage();
|
|
44
|
+
if (!storage) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
sessionStorage.setItem(key, value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static getItem(key) {
|
|
51
|
+
const storage = this.getStorage();
|
|
52
|
+
if (!storage) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const value = storage.getItem(key);
|
|
57
|
+
if (value !== undefined && value !== null) {
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static removeItem(key) {
|
|
64
|
+
const storage = this.getStorage();
|
|
65
|
+
if (!storage) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
storage.removeItem(key);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static clear() {
|
|
72
|
+
const storage = this.getStorage();
|
|
73
|
+
if (!storage) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
storage.clear();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default Storage;
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '3.
|
|
1
|
+
export default '3.3.0-beta.2';
|
package/src/cookie.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
class Cookie {
|
|
2
|
-
|
|
3
|
-
// KEYS
|
|
4
|
-
static get DESCRIPTION() {
|
|
5
|
-
return 'radar-description';
|
|
6
|
-
}
|
|
7
|
-
static get DEVICE_ID() {
|
|
8
|
-
return 'radar-deviceId';
|
|
9
|
-
}
|
|
10
|
-
static get DEVICE_TYPE() {
|
|
11
|
-
return 'radar-deviceType';
|
|
12
|
-
}
|
|
13
|
-
static get METADATA() {
|
|
14
|
-
return 'radar-metadata';
|
|
15
|
-
}
|
|
16
|
-
static get HOST() {
|
|
17
|
-
return 'radar-host';
|
|
18
|
-
}
|
|
19
|
-
static get PUBLISHABLE_KEY() {
|
|
20
|
-
return 'radar-publishableKey';
|
|
21
|
-
}
|
|
22
|
-
static get USER_ID () {
|
|
23
|
-
return 'radar-userId';
|
|
24
|
-
}
|
|
25
|
-
static get INSTALL_ID () {
|
|
26
|
-
return 'radar-installId';
|
|
27
|
-
}
|
|
28
|
-
static get TRIP_OPTIONS () {
|
|
29
|
-
return 'radar-trip-options';
|
|
30
|
-
}
|
|
31
|
-
static get CUSTOM_HEADERS () {
|
|
32
|
-
return 'radar-custom-headers';
|
|
33
|
-
}
|
|
34
|
-
static get BASE_API_PATH () {
|
|
35
|
-
return 'radar-base-api-path';
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// parse cookie string to return value at {key}
|
|
39
|
-
static getCookie(key) {
|
|
40
|
-
if (!document || document.cookie === undefined) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const prefix = `${key}=`;
|
|
45
|
-
const cookies = document.cookie.split(';');
|
|
46
|
-
const value = cookies.find(
|
|
47
|
-
(cookie) => cookie.indexOf(prefix) != -1
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
return value ? value.trim().substring(prefix.length) : null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// set cookie using {key, value}
|
|
54
|
-
static setCookie(key, value) {
|
|
55
|
-
if (!document || !document.cookie === undefined || typeof value !== 'string') {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const date = new Date();
|
|
60
|
-
date.setFullYear(date.getFullYear() + 10);
|
|
61
|
-
|
|
62
|
-
const expires = `expires=${date.toGMTString()}`;
|
|
63
|
-
const sameSite = 'samesite=strict';
|
|
64
|
-
document.cookie = `${key}=${value};path=/;${sameSite};${expires}`;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// delete cookie with {key}
|
|
68
|
-
static deleteCookie(key) {
|
|
69
|
-
if (!document || !document.cookie) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
document.cookie = `${key}=;expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/`;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export default Cookie;
|