glitch-javascript-sdk 0.5.7 → 0.5.8
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/cjs/index.js +36 -21
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +36 -21
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/util/Storage.ts +37 -19
package/package.json
CHANGED
package/src/util/Storage.ts
CHANGED
|
@@ -25,7 +25,11 @@ class Storage {
|
|
|
25
25
|
const serializedValue = JSON.stringify(value);
|
|
26
26
|
window.sessionStorage.setItem(Storage.getStorageKey(key), serializedValue);
|
|
27
27
|
} catch (e) {
|
|
28
|
-
|
|
28
|
+
try {
|
|
29
|
+
this.setCookie(key, value, 31);
|
|
30
|
+
} catch(e){
|
|
31
|
+
|
|
32
|
+
}
|
|
29
33
|
Storage.data[key] = value;
|
|
30
34
|
}
|
|
31
35
|
}
|
|
@@ -44,7 +48,14 @@ class Storage {
|
|
|
44
48
|
return JSON.parse(serializedValue);
|
|
45
49
|
}
|
|
46
50
|
} catch (e) {
|
|
47
|
-
let value =
|
|
51
|
+
let value = null;
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
value = Storage.getCookie(key);
|
|
55
|
+
} catch(e) {
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
48
59
|
if (!value) {
|
|
49
60
|
value = Storage.data[key];
|
|
50
61
|
}
|
|
@@ -62,9 +73,12 @@ class Storage {
|
|
|
62
73
|
}
|
|
63
74
|
|
|
64
75
|
public static eraseCookie(name: string) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
76
|
+
|
|
77
|
+
if(document){
|
|
78
|
+
document.cookie =
|
|
79
|
+
name +
|
|
80
|
+
'=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
81
|
+
}
|
|
68
82
|
}
|
|
69
83
|
|
|
70
84
|
private static setCookie(name: string, value: string, days: number) {
|
|
@@ -75,23 +89,27 @@ class Storage {
|
|
|
75
89
|
expires = '; expires=' + date.toUTCString();
|
|
76
90
|
}
|
|
77
91
|
|
|
78
|
-
document
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
92
|
+
if(document){
|
|
93
|
+
document.cookie =
|
|
94
|
+
name +
|
|
95
|
+
'=' +
|
|
96
|
+
(value || '') +
|
|
97
|
+
expires +
|
|
98
|
+
'; path=/; domain=' +
|
|
99
|
+
Storage.rootDomain +
|
|
100
|
+
'; HttpOnly=false; SameSite=none; Secure';
|
|
101
|
+
}
|
|
86
102
|
}
|
|
87
103
|
|
|
88
104
|
private static getCookie(name: string): string | null {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
let
|
|
93
|
-
|
|
94
|
-
|
|
105
|
+
if(document){
|
|
106
|
+
const nameEQ = name + '=';
|
|
107
|
+
const ca = document.cookie.split(';');
|
|
108
|
+
for (let i = 0; i < ca.length; i++) {
|
|
109
|
+
let c = ca[i];
|
|
110
|
+
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
|
111
|
+
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
|
112
|
+
}
|
|
95
113
|
}
|
|
96
114
|
return null;
|
|
97
115
|
}
|