glitch-javascript-sdk 2.6.8 → 2.7.0

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
@@ -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
- try {
18783
- var serializedValue = JSON.stringify(value);
18784
- window.localStorage.setItem(Storage.getStorageKey(key), serializedValue);
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.sessionStorage.setItem(Storage.getStorageKey(key), serializedValue);
18782
+ window.localStorage.setItem(Storage.getStorageKey(key), serializedValue);
18790
18783
  }
18791
18784
  catch (e) {
18792
18785
  try {
18793
- this.setCookie(key, value, 31);
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
- try {
18803
- var serializedValue = window.localStorage.getItem(Storage.getStorageKey(key));
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.sessionStorage.getItem(Storage.getStorageKey(key));
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
- value = Storage.getCookie(key);
18819
- }
18820
- catch (e) {
18821
- }
18822
- if (!value) {
18823
- value = Storage.data[key];
18808
+ var serializedValue = window.sessionStorage.getItem(Storage.getStorageKey(key));
18809
+ if (serializedValue !== null)
18810
+ return JSON.parse(serializedValue);
18824
18811
  }
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
- if (document) {
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
- if (document) {
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; // If no expiry set, assume valid or let API handle 401
18903
+ return false;
18910
18904
  return Date.now() > expiry;
18911
18905
  };
18912
18906
  Storage.rootDomain = '';
@@ -21052,6 +21046,19 @@ var CommunitiesRoute = /** @class */ (function () {
21052
21046
  url: '/communities/{community_id}/invoice-once',
21053
21047
  method: HTTP_METHODS.POST
21054
21048
  },
21049
+ // New Invoicing and Statement Routes
21050
+ listInvoices: {
21051
+ url: '/communities/{community_id}/payment/invoices',
21052
+ method: HTTP_METHODS.GET
21053
+ },
21054
+ getInvoiceDetails: {
21055
+ url: '/communities/{community_id}/payment/invoices/{invoice_id}',
21056
+ method: HTTP_METHODS.GET
21057
+ },
21058
+ getCustomStatement: {
21059
+ url: '/communities/{community_id}/payment/statement',
21060
+ method: HTTP_METHODS.GET
21061
+ },
21055
21062
  };
21056
21063
  return CommunitiesRoute;
21057
21064
  }());
@@ -21842,6 +21849,24 @@ var Communities = /** @class */ (function () {
21842
21849
  Communities.createOneTimeInvoice = function (community_id, data, params) {
21843
21850
  return Requests.processRoute(CommunitiesRoute.routes.createOneTimeInvoice, data, { community_id: community_id }, params);
21844
21851
  };
21852
+ /**
21853
+ * Get a detailed breakdown of a specific invoice including per-title usage.
21854
+ *
21855
+ * @param community_id The ID of the community.
21856
+ * @param invoice_id The Stripe Invoice ID (e.g., in_123...).
21857
+ */
21858
+ Communities.getInvoiceDetails = function (community_id, invoice_id, params) {
21859
+ return Requests.processRoute(CommunitiesRoute.routes.getInvoiceDetails, undefined, { community_id: community_id, invoice_id: invoice_id }, params);
21860
+ };
21861
+ /**
21862
+ * Generate a custom date-range statement for reimbursement.
21863
+ *
21864
+ * @param community_id The ID of the community.
21865
+ * @param params Should include { start_date: 'YYYY-MM-DD', end_date: 'YYYY-MM-DD' }
21866
+ */
21867
+ Communities.getCustomStatement = function (community_id, params) {
21868
+ return Requests.processRoute(CommunitiesRoute.routes.getCustomStatement, undefined, { community_id: community_id }, params);
21869
+ };
21845
21870
  return Communities;
21846
21871
  }());
21847
21872