glitch-javascript-sdk 3.0.3 → 3.0.5

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 CHANGED
@@ -18772,10 +18772,11 @@ var Storage = /** @class */ (function () {
18772
18772
  Storage.getStorageKey = function (key) {
18773
18773
  return Storage.rootDomain ? "".concat(Storage.rootDomain, ":").concat(key) : key;
18774
18774
  };
18775
+ Storage.shouldShareAcrossSubdomains = function (key) {
18776
+ return !!Storage.rootDomain && Storage.crossDomainKeys.has(key);
18777
+ };
18775
18778
  Storage.set = function (key, value) {
18776
- // 1. Always update in-memory fallback for the current process
18777
18779
  Storage.data[key] = value;
18778
- // 2. Only attempt browser storage if window exists
18779
18780
  if (typeof window !== 'undefined') {
18780
18781
  try {
18781
18782
  var serializedValue = JSON.stringify(value);
@@ -18786,17 +18787,31 @@ var Storage = /** @class */ (function () {
18786
18787
  var serializedValue = JSON.stringify(value);
18787
18788
  window.sessionStorage.setItem(Storage.getStorageKey(key), serializedValue);
18788
18789
  }
18789
- catch (e) {
18790
- try {
18791
- this.setCookie(key, value, 31);
18792
- }
18793
- catch (e) { }
18794
- }
18790
+ catch (e) { }
18791
+ }
18792
+ }
18793
+ // Important: shared session keys must be written to a root-domain cookie.
18794
+ if (Storage.shouldShareAcrossSubdomains(key)) {
18795
+ if (value === null || value === undefined) {
18796
+ Storage.eraseCookie(key);
18797
+ }
18798
+ else {
18799
+ Storage.setCookie(key, value, 31);
18795
18800
  }
18796
18801
  }
18797
18802
  };
18798
18803
  Storage.get = function (key) {
18799
- // 1. Try Browser Storage if available
18804
+ // Important: for shared session keys, cookie must win over localStorage.
18805
+ // Otherwise stale www.glitch.fun localStorage can override the real shared cookie.
18806
+ if (Storage.shouldShareAcrossSubdomains(key)) {
18807
+ try {
18808
+ var cookieValue = Storage.getCookie(key);
18809
+ if (cookieValue !== null && cookieValue !== undefined && cookieValue !== 'null') {
18810
+ return cookieValue;
18811
+ }
18812
+ }
18813
+ catch (e) { }
18814
+ }
18800
18815
  if (typeof window !== 'undefined') {
18801
18816
  try {
18802
18817
  var serializedValue = window.localStorage.getItem(Storage.getStorageKey(key));
@@ -18812,42 +18827,32 @@ var Storage = /** @class */ (function () {
18812
18827
  catch (e) { }
18813
18828
  }
18814
18829
  }
18815
- // 2. Try Cookie (getCookie is now SSR safe)
18816
- var value = null;
18817
18830
  try {
18818
- value = Storage.getCookie(key);
18831
+ var cookieValue = Storage.getCookie(key);
18832
+ if (cookieValue !== null && cookieValue !== undefined && cookieValue !== 'null') {
18833
+ return cookieValue;
18834
+ }
18819
18835
  }
18820
18836
  catch (e) { }
18821
- // 3. Fallback to in-memory data
18822
- if (!value) {
18823
- value = Storage.data[key];
18824
- }
18825
- return value;
18837
+ return Storage.data[key];
18826
18838
  };
18827
18839
  Storage.setAuthToken = function (token) {
18828
- if (Storage.rootDomain) {
18829
- if (token) {
18830
- this.setCookie('glitch_auth_token', token, 31);
18831
- }
18832
- else {
18833
- this.eraseCookie('glitch_auth_token');
18834
- }
18835
- }
18836
18840
  Storage.set('glitch_auth_token', token);
18837
18841
  };
18838
18842
  Storage.getAuthToken = function () {
18839
- var token = Storage.getCookie('glitch_auth_token');
18840
- if (!token || token === 'null') {
18841
- token = Storage.get('glitch_auth_token');
18842
- }
18843
- return (token === 'null' || !token) ? null : token;
18843
+ var token = Storage.get('glitch_auth_token');
18844
+ return token === 'null' || !token ? null : token;
18844
18845
  };
18845
18846
  Storage.eraseCookie = function (name) {
18846
- // Use typeof check to prevent ReferenceError
18847
- if (typeof document !== 'undefined') {
18847
+ if (typeof document === 'undefined')
18848
+ return;
18849
+ // Clear host-only cookie.
18850
+ document.cookie =
18851
+ "".concat(name, "=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax; Secure");
18852
+ // Clear root-domain cookie.
18853
+ if (Storage.rootDomain) {
18848
18854
  document.cookie =
18849
- name +
18850
- '=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
18855
+ "".concat(name, "=; Path=/; Domain=").concat(Storage.rootDomain, "; Expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax; Secure");
18851
18856
  }
18852
18857
  };
18853
18858
  Storage.setCookie = function (name, value, days) {
@@ -18855,47 +18860,49 @@ var Storage = /** @class */ (function () {
18855
18860
  if (days) {
18856
18861
  var date = new Date();
18857
18862
  date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
18858
- expires = '; expires=' + date.toUTCString();
18863
+ expires = '; Expires=' + date.toUTCString();
18859
18864
  }
18860
18865
  if (typeof document !== 'undefined') {
18866
+ var encodedValue = encodeURIComponent(JSON.stringify(value));
18861
18867
  document.cookie =
18862
- name +
18863
- '=' +
18864
- (value || '') +
18865
- expires +
18866
- '; path=/; domain=' +
18867
- Storage.rootDomain +
18868
- '; SameSite=Lax; Secure';
18868
+ "".concat(name, "=").concat(encodedValue).concat(expires, "; Path=/; Domain=").concat(Storage.rootDomain, "; SameSite=Lax; Secure");
18869
18869
  }
18870
18870
  };
18871
18871
  Storage.getCookie = function (name) {
18872
- // Use typeof check to prevent ReferenceError
18873
18872
  if (typeof document !== 'undefined') {
18874
18873
  var nameEQ = name + '=';
18875
18874
  var ca = document.cookie.split(';');
18876
18875
  for (var i = 0; i < ca.length; i++) {
18877
18876
  var c = ca[i];
18878
- while (c.charAt(0) == ' ')
18877
+ while (c.charAt(0) === ' ') {
18879
18878
  c = c.substring(1, c.length);
18880
- if (c.indexOf(nameEQ) == 0)
18881
- return c.substring(nameEQ.length, c.length);
18879
+ }
18880
+ if (c.indexOf(nameEQ) === 0) {
18881
+ var rawValue = c.substring(nameEQ.length, c.length);
18882
+ try {
18883
+ var decodedValue = decodeURIComponent(rawValue);
18884
+ return JSON.parse(decodedValue);
18885
+ }
18886
+ catch (e) {
18887
+ try {
18888
+ return decodeURIComponent(rawValue);
18889
+ }
18890
+ catch (e2) {
18891
+ return rawValue;
18892
+ }
18893
+ }
18894
+ }
18882
18895
  }
18883
18896
  }
18884
18897
  return null;
18885
18898
  };
18886
18899
  Storage.setTokenExpiry = function (expiresInSeconds) {
18887
- var expiryTime = Date.now() + (expiresInSeconds * 1000);
18900
+ var expiryTime = Date.now() + expiresInSeconds * 1000;
18888
18901
  Storage.set('glitch_token_expiry', expiryTime);
18889
- if (Storage.rootDomain && typeof document !== 'undefined') {
18890
- this.setCookie('glitch_token_expiry', expiryTime.toString(), 31);
18891
- }
18892
18902
  };
18893
18903
  Storage.getTokenExpiry = function () {
18894
- var expiry = Storage.getCookie('glitch_token_expiry');
18895
- if (!expiry) {
18896
- expiry = Storage.get('glitch_token_expiry');
18897
- }
18898
- return expiry ? parseInt(expiry) : null;
18904
+ var expiry = Storage.get('glitch_token_expiry');
18905
+ return expiry ? parseInt(String(expiry), 10) : null;
18899
18906
  };
18900
18907
  Storage.isTokenExpired = function () {
18901
18908
  var expiry = this.getTokenExpiry();
@@ -18905,6 +18912,17 @@ var Storage = /** @class */ (function () {
18905
18912
  };
18906
18913
  Storage.rootDomain = '';
18907
18914
  Storage.data = {};
18915
+ Storage.crossDomainKeys = new Set([
18916
+ 'glitch_auth_token',
18917
+ 'glitch_token_expiry',
18918
+ 'user_id',
18919
+ 'user_first_name',
18920
+ 'user_last_name',
18921
+ 'username',
18922
+ 'email',
18923
+ 'session_id',
18924
+ 'community_id',
18925
+ ]);
18908
18926
  return Storage;
18909
18927
  }());
18910
18928
 
@@ -25067,7 +25085,7 @@ var TitlesRoute = /** @class */ (function () {
25067
25085
  // Aegis Deployment
25068
25086
  getDeploymentUploadUrl: { url: '/titles/{title_id}/deployments/presigned-url', method: HTTP_METHODS.POST },
25069
25087
  confirmDeployment: { url: '/titles/{title_id}/deployments/confirm', method: HTTP_METHODS.POST },
25070
- getPlaySession: { url: '/titles/{title_id}/play', method: HTTP_METHODS.GET },
25088
+ getPlaySession: { url: '/titles/{title_id}/play', method: HTTP_METHODS.POST },
25071
25089
  initiateMultipartUpload: { url: '/titles/{title_id}/deployments/multipart/initiate', method: HTTP_METHODS.POST },
25072
25090
  getMultipartUrls: { url: '/titles/{title_id}/deployments/multipart/urls', method: HTTP_METHODS.POST },
25073
25091
  completeMultipartUpload: { url: '/titles/{title_id}/deployments/multipart/complete', method: HTTP_METHODS.POST },
@@ -25783,8 +25801,8 @@ var Titles = /** @class */ (function () {
25783
25801
  * Initializes a play session. Handles age-gating and license verification.
25784
25802
  * Returns the CDN URL for WASM/iFrame or Signaling URL for Pixel Streaming.
25785
25803
  */
25786
- Titles.getPlaySession = function (title_id, params) {
25787
- return Requests.processRoute(TitlesRoute.routes.getPlaySession, {}, { title_id: title_id }, params);
25804
+ Titles.getPlaySession = function (title_id, data, params) {
25805
+ return Requests.processRoute(TitlesRoute.routes.getPlaySession, data, { title_id: title_id }, params);
25788
25806
  };
25789
25807
  /**
25790
25808
  * List all developer payouts for a title.