glitch-javascript-sdk 2.6.6 → 2.6.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 +81 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/Communities.d.ts +10 -0
- package/dist/esm/api/Subscriptions.d.ts +8 -0
- package/dist/esm/index.js +81 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/util/Session.d.ts +1 -0
- package/dist/esm/util/Storage.d.ts +3 -0
- package/dist/index.d.ts +22 -0
- package/package.json +1 -1
- package/src/api/Communities.ts +10 -0
- package/src/api/Subscriptions.ts +27 -17
- package/src/config/Config.ts +6 -9
- package/src/routes/CommunitiesRoute.ts +5 -0
- package/src/routes/SubscriptionsRoute.ts +5 -0
- package/src/util/Session.ts +21 -9
- package/src/util/Storage.ts +52 -9
package/dist/cjs/index.js
CHANGED
|
@@ -18827,10 +18827,26 @@ var Storage = /** @class */ (function () {
|
|
|
18827
18827
|
}
|
|
18828
18828
|
};
|
|
18829
18829
|
Storage.setAuthToken = function (token) {
|
|
18830
|
+
// Always set the cookie if we have a root domain to ensure cross-subdomain sync
|
|
18831
|
+
if (Storage.rootDomain) {
|
|
18832
|
+
if (token) {
|
|
18833
|
+
this.setCookie('glitch_auth_token', token, 31);
|
|
18834
|
+
}
|
|
18835
|
+
else {
|
|
18836
|
+
this.eraseCookie('glitch_auth_token');
|
|
18837
|
+
}
|
|
18838
|
+
}
|
|
18839
|
+
// Still set localStorage for the current domain
|
|
18830
18840
|
Storage.set('glitch_auth_token', token);
|
|
18831
18841
|
};
|
|
18832
18842
|
Storage.getAuthToken = function () {
|
|
18833
|
-
|
|
18843
|
+
// 1. Try Cookie first (best for cross-subdomain)
|
|
18844
|
+
var token = Storage.getCookie('glitch_auth_token');
|
|
18845
|
+
// 2. Fallback to LocalStorage
|
|
18846
|
+
if (!token || token === 'null') {
|
|
18847
|
+
token = Storage.get('glitch_auth_token');
|
|
18848
|
+
}
|
|
18849
|
+
return (token === 'null' || !token) ? null : token;
|
|
18834
18850
|
};
|
|
18835
18851
|
Storage.eraseCookie = function (name) {
|
|
18836
18852
|
if (document) {
|
|
@@ -18846,7 +18862,8 @@ var Storage = /** @class */ (function () {
|
|
|
18846
18862
|
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
18847
18863
|
expires = '; expires=' + date.toUTCString();
|
|
18848
18864
|
}
|
|
18849
|
-
if (document) {
|
|
18865
|
+
if (typeof document !== 'undefined') {
|
|
18866
|
+
// If rootDomain is .glitch.fun, this works for all subdomains
|
|
18850
18867
|
document.cookie =
|
|
18851
18868
|
name +
|
|
18852
18869
|
'=' +
|
|
@@ -18854,7 +18871,7 @@ var Storage = /** @class */ (function () {
|
|
|
18854
18871
|
expires +
|
|
18855
18872
|
'; path=/; domain=' +
|
|
18856
18873
|
Storage.rootDomain +
|
|
18857
|
-
';
|
|
18874
|
+
'; SameSite=Lax; Secure';
|
|
18858
18875
|
}
|
|
18859
18876
|
};
|
|
18860
18877
|
Storage.getCookie = function (name) {
|
|
@@ -18871,6 +18888,27 @@ var Storage = /** @class */ (function () {
|
|
|
18871
18888
|
}
|
|
18872
18889
|
return null;
|
|
18873
18890
|
};
|
|
18891
|
+
Storage.setTokenExpiry = function (expiresInSeconds) {
|
|
18892
|
+
var expiryTime = Date.now() + (expiresInSeconds * 1000);
|
|
18893
|
+
Storage.set('glitch_token_expiry', expiryTime);
|
|
18894
|
+
// Also set a cookie for cross-subdomain consistency if rootDomain exists
|
|
18895
|
+
if (Storage.rootDomain && typeof document !== 'undefined') {
|
|
18896
|
+
this.setCookie('glitch_token_expiry', expiryTime.toString(), 31);
|
|
18897
|
+
}
|
|
18898
|
+
};
|
|
18899
|
+
Storage.getTokenExpiry = function () {
|
|
18900
|
+
var expiry = Storage.getCookie('glitch_token_expiry');
|
|
18901
|
+
if (!expiry) {
|
|
18902
|
+
expiry = Storage.get('glitch_token_expiry');
|
|
18903
|
+
}
|
|
18904
|
+
return expiry ? parseInt(expiry) : null;
|
|
18905
|
+
};
|
|
18906
|
+
Storage.isTokenExpired = function () {
|
|
18907
|
+
var expiry = this.getTokenExpiry();
|
|
18908
|
+
if (!expiry)
|
|
18909
|
+
return false; // If no expiry set, assume valid or let API handle 401
|
|
18910
|
+
return Date.now() > expiry;
|
|
18911
|
+
};
|
|
18874
18912
|
Storage.rootDomain = '';
|
|
18875
18913
|
Storage.data = {};
|
|
18876
18914
|
return Storage;
|
|
@@ -18942,12 +18980,11 @@ var Config = /** @class */ (function () {
|
|
|
18942
18980
|
console.error("setRootDomain: domain is undefined or null");
|
|
18943
18981
|
return;
|
|
18944
18982
|
}
|
|
18945
|
-
|
|
18946
|
-
|
|
18947
|
-
|
|
18948
|
-
|
|
18949
|
-
|
|
18950
|
-
formattedDomain = formattedDomain.replace(/^\./, '');
|
|
18983
|
+
// If the domain already starts with a dot, keep it.
|
|
18984
|
+
// If not, and it's a standard domain, we usually want the dot for subdomains.
|
|
18985
|
+
var formattedDomain = domain;
|
|
18986
|
+
// REMOVE THIS LINE: formattedDomain = formattedDomain.replace(/^\./, '');
|
|
18987
|
+
// We WANT the dot.
|
|
18951
18988
|
this._rootDomain = formattedDomain;
|
|
18952
18989
|
Storage.setRootDomain(formattedDomain);
|
|
18953
18990
|
};
|
|
@@ -21011,6 +21048,10 @@ var CommunitiesRoute = /** @class */ (function () {
|
|
|
21011
21048
|
deleteNewsletterSubscriber: { url: '/communities/{community_id}/newsletters/{newsletter_id}/subscribers/{subscriber_id}', method: HTTP_METHODS.DELETE },
|
|
21012
21049
|
// Subscriber registration (open route)
|
|
21013
21050
|
registerNewsletterSubscriber: { url: '/communities/{community_id}/newsletters/{newsletter_id}/subscribers', method: HTTP_METHODS.POST },
|
|
21051
|
+
createOneTimeInvoice: {
|
|
21052
|
+
url: '/communities/{community_id}/invoice-once',
|
|
21053
|
+
method: HTTP_METHODS.POST
|
|
21054
|
+
},
|
|
21014
21055
|
};
|
|
21015
21056
|
return CommunitiesRoute;
|
|
21016
21057
|
}());
|
|
@@ -21792,6 +21833,15 @@ var Communities = /** @class */ (function () {
|
|
|
21792
21833
|
Communities.deleteInvite = function (community_id, invite_id, params) {
|
|
21793
21834
|
return Requests.processRoute(CommunitiesRoute.routes.deleteInvite, {}, { community_id: community_id, invite_id: invite_id }, params);
|
|
21794
21835
|
};
|
|
21836
|
+
/**
|
|
21837
|
+
* Create a one-time immediate invoice for a business account.
|
|
21838
|
+
*
|
|
21839
|
+
* @param community_id The ID of the community.
|
|
21840
|
+
* @param data { amount: number, description: string }
|
|
21841
|
+
*/
|
|
21842
|
+
Communities.createOneTimeInvoice = function (community_id, data, params) {
|
|
21843
|
+
return Requests.processRoute(CommunitiesRoute.routes.createOneTimeInvoice, data, { community_id: community_id }, params);
|
|
21844
|
+
};
|
|
21795
21845
|
return Communities;
|
|
21796
21846
|
}());
|
|
21797
21847
|
|
|
@@ -26398,6 +26448,10 @@ var SubscriptionsRoute = /** @class */ (function () {
|
|
|
26398
26448
|
cancelCommunityInfluencerSubscription: { url: '/subscriptions/communities/influencers/{community_id}/{stripe_subscription_id}', method: HTTP_METHODS.DELETE },
|
|
26399
26449
|
listCommunityInfluencerSubscriptions: { url: '/subscriptions/communities/influencers/{community_id}', method: HTTP_METHODS.GET },
|
|
26400
26450
|
changeCommunityInfluencerSubscription: { url: '/subscriptions/communities/influencers/change/{community_id}', method: HTTP_METHODS.POST },
|
|
26451
|
+
createCustomCommunitySubscription: {
|
|
26452
|
+
url: '/subscriptions/communities/custom/{community_id}',
|
|
26453
|
+
method: HTTP_METHODS.POST
|
|
26454
|
+
},
|
|
26401
26455
|
};
|
|
26402
26456
|
return SubscriptionsRoute;
|
|
26403
26457
|
}());
|
|
@@ -26495,6 +26549,16 @@ var Subscriptions = /** @class */ (function () {
|
|
|
26495
26549
|
Subscriptions.changeCommunityInfluencerSubscription = function (community_id, data, params) {
|
|
26496
26550
|
return Requests.processRoute(SubscriptionsRoute.routes.changeCommunityInfluencerSubscription, data, { community_id: community_id }, params);
|
|
26497
26551
|
};
|
|
26552
|
+
/**
|
|
26553
|
+
* Create a custom tailored subscription for a business/community.
|
|
26554
|
+
* Only accessible by Glitch administrators.
|
|
26555
|
+
*
|
|
26556
|
+
* @param community_id The ID of the community.
|
|
26557
|
+
* @param data { priceId, paymentMethod, custom_name, limits: { posts, enrichments, invites, ads }, metered_prices: [] }
|
|
26558
|
+
*/
|
|
26559
|
+
Subscriptions.createCustomCommunitySubscription = function (community_id, data, params) {
|
|
26560
|
+
return Requests.processRoute(SubscriptionsRoute.routes.createCustomCommunitySubscription, data, { community_id: community_id }, params);
|
|
26561
|
+
};
|
|
26498
26562
|
return Subscriptions;
|
|
26499
26563
|
}());
|
|
26500
26564
|
|
|
@@ -30287,6 +30351,11 @@ var Session = /** @class */ (function () {
|
|
|
30287
30351
|
}
|
|
30288
30352
|
Session.isLoggedIn = function () {
|
|
30289
30353
|
var authToken = Storage.getAuthToken();
|
|
30354
|
+
var expired = Storage.isTokenExpired();
|
|
30355
|
+
if (expired) {
|
|
30356
|
+
Session.end(); // Auto-clear if expired
|
|
30357
|
+
return false;
|
|
30358
|
+
}
|
|
30290
30359
|
return authToken !== null && authToken !== 'null' && authToken !== undefined;
|
|
30291
30360
|
};
|
|
30292
30361
|
Session.getAuthToken = function () {
|
|
@@ -30310,6 +30379,8 @@ var Session = /** @class */ (function () {
|
|
|
30310
30379
|
};
|
|
30311
30380
|
Session.end = function () {
|
|
30312
30381
|
Storage.setAuthToken(null);
|
|
30382
|
+
Storage.set('glitch_token_expiry', null); // Clear expiry
|
|
30383
|
+
Storage.eraseCookie('glitch_token_expiry');
|
|
30313
30384
|
Storage.set(Session._id_key, null);
|
|
30314
30385
|
Storage.set(Session._first_name_key, null);
|
|
30315
30386
|
Storage.set(Session._last_name_key, null);
|
|
@@ -30318,6 +30389,7 @@ var Session = /** @class */ (function () {
|
|
|
30318
30389
|
};
|
|
30319
30390
|
Session.processAuthentication = function (data) {
|
|
30320
30391
|
Storage.setAuthToken(data.token.access_token);
|
|
30392
|
+
Storage.setTokenExpiry(data.token.expires_in); // Save the timeout
|
|
30321
30393
|
Storage.set(Session._id_key, data.id);
|
|
30322
30394
|
Storage.set(Session._first_name_key, data.first_name);
|
|
30323
30395
|
Storage.set(Session._last_name_key, data.last_name);
|