glitch-javascript-sdk 2.6.8 → 2.6.9
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 +35 -41
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +35 -41
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/util/Storage.d.ts +0 -6
- package/dist/index.d.ts +0 -6
- package/package.json +1 -1
- package/src/util/Storage.ts +35 -46
package/dist/cjs/index.js
CHANGED
|
@@ -18766,12 +18766,6 @@ var Requests = /** @class */ (function () {
|
|
|
18766
18766
|
var Storage = /** @class */ (function () {
|
|
18767
18767
|
function Storage() {
|
|
18768
18768
|
}
|
|
18769
|
-
/**
|
|
18770
|
-
* Sets a root level domain so the data can persist across
|
|
18771
|
-
* subdomains
|
|
18772
|
-
*
|
|
18773
|
-
* @param rootDomain
|
|
18774
|
-
*/
|
|
18775
18769
|
Storage.setRootDomain = function (rootDomain) {
|
|
18776
18770
|
Storage.rootDomain = rootDomain;
|
|
18777
18771
|
};
|
|
@@ -18779,55 +18773,58 @@ var Storage = /** @class */ (function () {
|
|
|
18779
18773
|
return Storage.rootDomain ? "".concat(Storage.rootDomain, ":").concat(key) : key;
|
|
18780
18774
|
};
|
|
18781
18775
|
Storage.set = function (key, value) {
|
|
18782
|
-
|
|
18783
|
-
|
|
18784
|
-
|
|
18785
|
-
|
|
18786
|
-
catch (e) {
|
|
18776
|
+
// 1. Always update in-memory fallback for the current process
|
|
18777
|
+
Storage.data[key] = value;
|
|
18778
|
+
// 2. Only attempt browser storage if window exists
|
|
18779
|
+
if (typeof window !== 'undefined') {
|
|
18787
18780
|
try {
|
|
18788
18781
|
var serializedValue = JSON.stringify(value);
|
|
18789
|
-
window.
|
|
18782
|
+
window.localStorage.setItem(Storage.getStorageKey(key), serializedValue);
|
|
18790
18783
|
}
|
|
18791
18784
|
catch (e) {
|
|
18792
18785
|
try {
|
|
18793
|
-
|
|
18786
|
+
var serializedValue = JSON.stringify(value);
|
|
18787
|
+
window.sessionStorage.setItem(Storage.getStorageKey(key), serializedValue);
|
|
18794
18788
|
}
|
|
18795
18789
|
catch (e) {
|
|
18790
|
+
try {
|
|
18791
|
+
this.setCookie(key, value, 31);
|
|
18792
|
+
}
|
|
18793
|
+
catch (e) { }
|
|
18796
18794
|
}
|
|
18797
|
-
Storage.data[key] = value;
|
|
18798
18795
|
}
|
|
18799
18796
|
}
|
|
18800
18797
|
};
|
|
18801
18798
|
Storage.get = function (key) {
|
|
18802
|
-
|
|
18803
|
-
|
|
18804
|
-
if (serializedValue !== null) {
|
|
18805
|
-
return JSON.parse(serializedValue);
|
|
18806
|
-
}
|
|
18807
|
-
}
|
|
18808
|
-
catch (e) {
|
|
18799
|
+
// 1. Try Browser Storage if available
|
|
18800
|
+
if (typeof window !== 'undefined') {
|
|
18809
18801
|
try {
|
|
18810
|
-
var serializedValue = window.
|
|
18811
|
-
if (serializedValue !== null)
|
|
18802
|
+
var serializedValue = window.localStorage.getItem(Storage.getStorageKey(key));
|
|
18803
|
+
if (serializedValue !== null)
|
|
18812
18804
|
return JSON.parse(serializedValue);
|
|
18813
|
-
}
|
|
18814
18805
|
}
|
|
18815
18806
|
catch (e) {
|
|
18816
|
-
var value = null;
|
|
18817
18807
|
try {
|
|
18818
|
-
|
|
18819
|
-
|
|
18820
|
-
|
|
18808
|
+
var serializedValue = window.sessionStorage.getItem(Storage.getStorageKey(key));
|
|
18809
|
+
if (serializedValue !== null)
|
|
18810
|
+
return JSON.parse(serializedValue);
|
|
18821
18811
|
}
|
|
18822
|
-
|
|
18823
|
-
value = Storage.data[key];
|
|
18824
|
-
}
|
|
18825
|
-
return value;
|
|
18812
|
+
catch (e) { }
|
|
18826
18813
|
}
|
|
18827
18814
|
}
|
|
18815
|
+
// 2. Try Cookie (getCookie is now SSR safe)
|
|
18816
|
+
var value = null;
|
|
18817
|
+
try {
|
|
18818
|
+
value = Storage.getCookie(key);
|
|
18819
|
+
}
|
|
18820
|
+
catch (e) { }
|
|
18821
|
+
// 3. Fallback to in-memory data
|
|
18822
|
+
if (!value) {
|
|
18823
|
+
value = Storage.data[key];
|
|
18824
|
+
}
|
|
18825
|
+
return value;
|
|
18828
18826
|
};
|
|
18829
18827
|
Storage.setAuthToken = function (token) {
|
|
18830
|
-
// Always set the cookie if we have a root domain to ensure cross-subdomain sync
|
|
18831
18828
|
if (Storage.rootDomain) {
|
|
18832
18829
|
if (token) {
|
|
18833
18830
|
this.setCookie('glitch_auth_token', token, 31);
|
|
@@ -18836,20 +18833,18 @@ var Storage = /** @class */ (function () {
|
|
|
18836
18833
|
this.eraseCookie('glitch_auth_token');
|
|
18837
18834
|
}
|
|
18838
18835
|
}
|
|
18839
|
-
// Still set localStorage for the current domain
|
|
18840
18836
|
Storage.set('glitch_auth_token', token);
|
|
18841
18837
|
};
|
|
18842
18838
|
Storage.getAuthToken = function () {
|
|
18843
|
-
// 1. Try Cookie first (best for cross-subdomain)
|
|
18844
18839
|
var token = Storage.getCookie('glitch_auth_token');
|
|
18845
|
-
// 2. Fallback to LocalStorage
|
|
18846
18840
|
if (!token || token === 'null') {
|
|
18847
18841
|
token = Storage.get('glitch_auth_token');
|
|
18848
18842
|
}
|
|
18849
18843
|
return (token === 'null' || !token) ? null : token;
|
|
18850
18844
|
};
|
|
18851
18845
|
Storage.eraseCookie = function (name) {
|
|
18852
|
-
|
|
18846
|
+
// Use typeof check to prevent ReferenceError
|
|
18847
|
+
if (typeof document !== 'undefined') {
|
|
18853
18848
|
document.cookie =
|
|
18854
18849
|
name +
|
|
18855
18850
|
'=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
@@ -18863,7 +18858,6 @@ var Storage = /** @class */ (function () {
|
|
|
18863
18858
|
expires = '; expires=' + date.toUTCString();
|
|
18864
18859
|
}
|
|
18865
18860
|
if (typeof document !== 'undefined') {
|
|
18866
|
-
// If rootDomain is .glitch.fun, this works for all subdomains
|
|
18867
18861
|
document.cookie =
|
|
18868
18862
|
name +
|
|
18869
18863
|
'=' +
|
|
@@ -18875,7 +18869,8 @@ var Storage = /** @class */ (function () {
|
|
|
18875
18869
|
}
|
|
18876
18870
|
};
|
|
18877
18871
|
Storage.getCookie = function (name) {
|
|
18878
|
-
|
|
18872
|
+
// Use typeof check to prevent ReferenceError
|
|
18873
|
+
if (typeof document !== 'undefined') {
|
|
18879
18874
|
var nameEQ = name + '=';
|
|
18880
18875
|
var ca = document.cookie.split(';');
|
|
18881
18876
|
for (var i = 0; i < ca.length; i++) {
|
|
@@ -18891,7 +18886,6 @@ var Storage = /** @class */ (function () {
|
|
|
18891
18886
|
Storage.setTokenExpiry = function (expiresInSeconds) {
|
|
18892
18887
|
var expiryTime = Date.now() + (expiresInSeconds * 1000);
|
|
18893
18888
|
Storage.set('glitch_token_expiry', expiryTime);
|
|
18894
|
-
// Also set a cookie for cross-subdomain consistency if rootDomain exists
|
|
18895
18889
|
if (Storage.rootDomain && typeof document !== 'undefined') {
|
|
18896
18890
|
this.setCookie('glitch_token_expiry', expiryTime.toString(), 31);
|
|
18897
18891
|
}
|
|
@@ -18906,7 +18900,7 @@ var Storage = /** @class */ (function () {
|
|
|
18906
18900
|
Storage.isTokenExpired = function () {
|
|
18907
18901
|
var expiry = this.getTokenExpiry();
|
|
18908
18902
|
if (!expiry)
|
|
18909
|
-
return false;
|
|
18903
|
+
return false;
|
|
18910
18904
|
return Date.now() > expiry;
|
|
18911
18905
|
};
|
|
18912
18906
|
Storage.rootDomain = '';
|