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.
@@ -639,5 +639,22 @@ declare class Communities {
639
639
  amount: number;
640
640
  description: string;
641
641
  }, params?: Record<string, any>): AxiosPromise<Response<T>>;
642
+ /**
643
+ * Get a detailed breakdown of a specific invoice including per-title usage.
644
+ *
645
+ * @param community_id The ID of the community.
646
+ * @param invoice_id The Stripe Invoice ID (e.g., in_123...).
647
+ */
648
+ static getInvoiceDetails<T>(community_id: string, invoice_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
649
+ /**
650
+ * Generate a custom date-range statement for reimbursement.
651
+ *
652
+ * @param community_id The ID of the community.
653
+ * @param params Should include { start_date: 'YYYY-MM-DD', end_date: 'YYYY-MM-DD' }
654
+ */
655
+ static getCustomStatement<T>(community_id: string, params: {
656
+ start_date: string;
657
+ end_date: string;
658
+ }): AxiosPromise<Response<T>>;
642
659
  }
643
660
  export default Communities;
package/dist/esm/index.js CHANGED
@@ -5582,12 +5582,6 @@ var Requests = /** @class */ (function () {
5582
5582
  var Storage = /** @class */ (function () {
5583
5583
  function Storage() {
5584
5584
  }
5585
- /**
5586
- * Sets a root level domain so the data can persist across
5587
- * subdomains
5588
- *
5589
- * @param rootDomain
5590
- */
5591
5585
  Storage.setRootDomain = function (rootDomain) {
5592
5586
  Storage.rootDomain = rootDomain;
5593
5587
  };
@@ -5595,55 +5589,58 @@ var Storage = /** @class */ (function () {
5595
5589
  return Storage.rootDomain ? "".concat(Storage.rootDomain, ":").concat(key) : key;
5596
5590
  };
5597
5591
  Storage.set = function (key, value) {
5598
- try {
5599
- var serializedValue = JSON.stringify(value);
5600
- window.localStorage.setItem(Storage.getStorageKey(key), serializedValue);
5601
- }
5602
- catch (e) {
5592
+ // 1. Always update in-memory fallback for the current process
5593
+ Storage.data[key] = value;
5594
+ // 2. Only attempt browser storage if window exists
5595
+ if (typeof window !== 'undefined') {
5603
5596
  try {
5604
5597
  var serializedValue = JSON.stringify(value);
5605
- window.sessionStorage.setItem(Storage.getStorageKey(key), serializedValue);
5598
+ window.localStorage.setItem(Storage.getStorageKey(key), serializedValue);
5606
5599
  }
5607
5600
  catch (e) {
5608
5601
  try {
5609
- this.setCookie(key, value, 31);
5602
+ var serializedValue = JSON.stringify(value);
5603
+ window.sessionStorage.setItem(Storage.getStorageKey(key), serializedValue);
5610
5604
  }
5611
5605
  catch (e) {
5606
+ try {
5607
+ this.setCookie(key, value, 31);
5608
+ }
5609
+ catch (e) { }
5612
5610
  }
5613
- Storage.data[key] = value;
5614
5611
  }
5615
5612
  }
5616
5613
  };
5617
5614
  Storage.get = function (key) {
5618
- try {
5619
- var serializedValue = window.localStorage.getItem(Storage.getStorageKey(key));
5620
- if (serializedValue !== null) {
5621
- return JSON.parse(serializedValue);
5622
- }
5623
- }
5624
- catch (e) {
5615
+ // 1. Try Browser Storage if available
5616
+ if (typeof window !== 'undefined') {
5625
5617
  try {
5626
- var serializedValue = window.sessionStorage.getItem(Storage.getStorageKey(key));
5627
- if (serializedValue !== null) {
5618
+ var serializedValue = window.localStorage.getItem(Storage.getStorageKey(key));
5619
+ if (serializedValue !== null)
5628
5620
  return JSON.parse(serializedValue);
5629
- }
5630
5621
  }
5631
5622
  catch (e) {
5632
- var value = null;
5633
5623
  try {
5634
- value = Storage.getCookie(key);
5635
- }
5636
- catch (e) {
5637
- }
5638
- if (!value) {
5639
- value = Storage.data[key];
5624
+ var serializedValue = window.sessionStorage.getItem(Storage.getStorageKey(key));
5625
+ if (serializedValue !== null)
5626
+ return JSON.parse(serializedValue);
5640
5627
  }
5641
- return value;
5628
+ catch (e) { }
5642
5629
  }
5643
5630
  }
5631
+ // 2. Try Cookie (getCookie is now SSR safe)
5632
+ var value = null;
5633
+ try {
5634
+ value = Storage.getCookie(key);
5635
+ }
5636
+ catch (e) { }
5637
+ // 3. Fallback to in-memory data
5638
+ if (!value) {
5639
+ value = Storage.data[key];
5640
+ }
5641
+ return value;
5644
5642
  };
5645
5643
  Storage.setAuthToken = function (token) {
5646
- // Always set the cookie if we have a root domain to ensure cross-subdomain sync
5647
5644
  if (Storage.rootDomain) {
5648
5645
  if (token) {
5649
5646
  this.setCookie('glitch_auth_token', token, 31);
@@ -5652,20 +5649,18 @@ var Storage = /** @class */ (function () {
5652
5649
  this.eraseCookie('glitch_auth_token');
5653
5650
  }
5654
5651
  }
5655
- // Still set localStorage for the current domain
5656
5652
  Storage.set('glitch_auth_token', token);
5657
5653
  };
5658
5654
  Storage.getAuthToken = function () {
5659
- // 1. Try Cookie first (best for cross-subdomain)
5660
5655
  var token = Storage.getCookie('glitch_auth_token');
5661
- // 2. Fallback to LocalStorage
5662
5656
  if (!token || token === 'null') {
5663
5657
  token = Storage.get('glitch_auth_token');
5664
5658
  }
5665
5659
  return (token === 'null' || !token) ? null : token;
5666
5660
  };
5667
5661
  Storage.eraseCookie = function (name) {
5668
- if (document) {
5662
+ // Use typeof check to prevent ReferenceError
5663
+ if (typeof document !== 'undefined') {
5669
5664
  document.cookie =
5670
5665
  name +
5671
5666
  '=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
@@ -5679,7 +5674,6 @@ var Storage = /** @class */ (function () {
5679
5674
  expires = '; expires=' + date.toUTCString();
5680
5675
  }
5681
5676
  if (typeof document !== 'undefined') {
5682
- // If rootDomain is .glitch.fun, this works for all subdomains
5683
5677
  document.cookie =
5684
5678
  name +
5685
5679
  '=' +
@@ -5691,7 +5685,8 @@ var Storage = /** @class */ (function () {
5691
5685
  }
5692
5686
  };
5693
5687
  Storage.getCookie = function (name) {
5694
- if (document) {
5688
+ // Use typeof check to prevent ReferenceError
5689
+ if (typeof document !== 'undefined') {
5695
5690
  var nameEQ = name + '=';
5696
5691
  var ca = document.cookie.split(';');
5697
5692
  for (var i = 0; i < ca.length; i++) {
@@ -5707,7 +5702,6 @@ var Storage = /** @class */ (function () {
5707
5702
  Storage.setTokenExpiry = function (expiresInSeconds) {
5708
5703
  var expiryTime = Date.now() + (expiresInSeconds * 1000);
5709
5704
  Storage.set('glitch_token_expiry', expiryTime);
5710
- // Also set a cookie for cross-subdomain consistency if rootDomain exists
5711
5705
  if (Storage.rootDomain && typeof document !== 'undefined') {
5712
5706
  this.setCookie('glitch_token_expiry', expiryTime.toString(), 31);
5713
5707
  }
@@ -5722,7 +5716,7 @@ var Storage = /** @class */ (function () {
5722
5716
  Storage.isTokenExpired = function () {
5723
5717
  var expiry = this.getTokenExpiry();
5724
5718
  if (!expiry)
5725
- return false; // If no expiry set, assume valid or let API handle 401
5719
+ return false;
5726
5720
  return Date.now() > expiry;
5727
5721
  };
5728
5722
  Storage.rootDomain = '';
@@ -7868,6 +7862,19 @@ var CommunitiesRoute = /** @class */ (function () {
7868
7862
  url: '/communities/{community_id}/invoice-once',
7869
7863
  method: HTTP_METHODS.POST
7870
7864
  },
7865
+ // New Invoicing and Statement Routes
7866
+ listInvoices: {
7867
+ url: '/communities/{community_id}/payment/invoices',
7868
+ method: HTTP_METHODS.GET
7869
+ },
7870
+ getInvoiceDetails: {
7871
+ url: '/communities/{community_id}/payment/invoices/{invoice_id}',
7872
+ method: HTTP_METHODS.GET
7873
+ },
7874
+ getCustomStatement: {
7875
+ url: '/communities/{community_id}/payment/statement',
7876
+ method: HTTP_METHODS.GET
7877
+ },
7871
7878
  };
7872
7879
  return CommunitiesRoute;
7873
7880
  }());
@@ -8658,6 +8665,24 @@ var Communities = /** @class */ (function () {
8658
8665
  Communities.createOneTimeInvoice = function (community_id, data, params) {
8659
8666
  return Requests.processRoute(CommunitiesRoute.routes.createOneTimeInvoice, data, { community_id: community_id }, params);
8660
8667
  };
8668
+ /**
8669
+ * Get a detailed breakdown of a specific invoice including per-title usage.
8670
+ *
8671
+ * @param community_id The ID of the community.
8672
+ * @param invoice_id The Stripe Invoice ID (e.g., in_123...).
8673
+ */
8674
+ Communities.getInvoiceDetails = function (community_id, invoice_id, params) {
8675
+ return Requests.processRoute(CommunitiesRoute.routes.getInvoiceDetails, undefined, { community_id: community_id, invoice_id: invoice_id }, params);
8676
+ };
8677
+ /**
8678
+ * Generate a custom date-range statement for reimbursement.
8679
+ *
8680
+ * @param community_id The ID of the community.
8681
+ * @param params Should include { start_date: 'YYYY-MM-DD', end_date: 'YYYY-MM-DD' }
8682
+ */
8683
+ Communities.getCustomStatement = function (community_id, params) {
8684
+ return Requests.processRoute(CommunitiesRoute.routes.getCustomStatement, undefined, { community_id: community_id }, params);
8685
+ };
8661
8686
  return Communities;
8662
8687
  }());
8663
8688