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
|
@@ -16,5 +16,8 @@ declare class Storage {
|
|
|
16
16
|
static eraseCookie(name: string): void;
|
|
17
17
|
private static setCookie;
|
|
18
18
|
private static getCookie;
|
|
19
|
+
static setTokenExpiry(expiresInSeconds: number): void;
|
|
20
|
+
static getTokenExpiry(): number | null;
|
|
21
|
+
static isTokenExpired(): boolean;
|
|
19
22
|
}
|
|
20
23
|
export default Storage;
|
package/dist/index.d.ts
CHANGED
|
@@ -1786,6 +1786,16 @@ declare class Communities {
|
|
|
1786
1786
|
* @returns promise
|
|
1787
1787
|
*/
|
|
1788
1788
|
static deleteInvite<T>(community_id: string, invite_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
1789
|
+
/**
|
|
1790
|
+
* Create a one-time immediate invoice for a business account.
|
|
1791
|
+
*
|
|
1792
|
+
* @param community_id The ID of the community.
|
|
1793
|
+
* @param data { amount: number, description: string }
|
|
1794
|
+
*/
|
|
1795
|
+
static createOneTimeInvoice<T>(community_id: string, data: {
|
|
1796
|
+
amount: number;
|
|
1797
|
+
description: string;
|
|
1798
|
+
}, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
1789
1799
|
}
|
|
1790
1800
|
|
|
1791
1801
|
declare class Users {
|
|
@@ -5040,6 +5050,14 @@ declare class Subscriptions {
|
|
|
5040
5050
|
* @returns A promise
|
|
5041
5051
|
*/
|
|
5042
5052
|
static changeCommunityInfluencerSubscription<T>(community_id: string, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
5053
|
+
/**
|
|
5054
|
+
* Create a custom tailored subscription for a business/community.
|
|
5055
|
+
* Only accessible by Glitch administrators.
|
|
5056
|
+
*
|
|
5057
|
+
* @param community_id The ID of the community.
|
|
5058
|
+
* @param data { priceId, paymentMethod, custom_name, limits: { posts, enrichments, invites, ads }, metered_prices: [] }
|
|
5059
|
+
*/
|
|
5060
|
+
static createCustomCommunitySubscription<T>(community_id: string, data: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
5043
5061
|
}
|
|
5044
5062
|
|
|
5045
5063
|
declare class Messages {
|
|
@@ -7399,6 +7417,7 @@ declare class Session {
|
|
|
7399
7417
|
static processAuthentication(data: {
|
|
7400
7418
|
token: {
|
|
7401
7419
|
access_token: string;
|
|
7420
|
+
expires_in: number;
|
|
7402
7421
|
};
|
|
7403
7422
|
id: string;
|
|
7404
7423
|
first_name: string;
|
|
@@ -7434,6 +7453,9 @@ declare class Storage {
|
|
|
7434
7453
|
static eraseCookie(name: string): void;
|
|
7435
7454
|
private static setCookie;
|
|
7436
7455
|
private static getCookie;
|
|
7456
|
+
static setTokenExpiry(expiresInSeconds: number): void;
|
|
7457
|
+
static getTokenExpiry(): number | null;
|
|
7458
|
+
static isTokenExpired(): boolean;
|
|
7437
7459
|
}
|
|
7438
7460
|
|
|
7439
7461
|
declare class Data {
|
package/package.json
CHANGED
package/src/api/Communities.ts
CHANGED
|
@@ -929,6 +929,16 @@ class Communities {
|
|
|
929
929
|
return Requests.processRoute(CommunitiesRoute.routes.deleteInvite, {}, { community_id: community_id, invite_id: invite_id }, params);
|
|
930
930
|
}
|
|
931
931
|
|
|
932
|
+
/**
|
|
933
|
+
* Create a one-time immediate invoice for a business account.
|
|
934
|
+
*
|
|
935
|
+
* @param community_id The ID of the community.
|
|
936
|
+
* @param data { amount: number, description: string }
|
|
937
|
+
*/
|
|
938
|
+
public static createOneTimeInvoice<T>(community_id: string, data: { amount: number, description: string }, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
939
|
+
return Requests.processRoute(CommunitiesRoute.routes.createOneTimeInvoice, data, { community_id }, params);
|
|
940
|
+
}
|
|
941
|
+
|
|
932
942
|
|
|
933
943
|
}
|
|
934
944
|
|
package/src/api/Subscriptions.ts
CHANGED
|
@@ -12,8 +12,8 @@ class Subscriptions {
|
|
|
12
12
|
*
|
|
13
13
|
* @returns promise
|
|
14
14
|
*/
|
|
15
|
-
public static getCreatorSubscription<T>(stripe_subscription_id
|
|
16
|
-
return Requests.processRoute(SubscriptionsRoute.routes.getCreatorSubscription, undefined, {stripe_subscription_id
|
|
15
|
+
public static getCreatorSubscription<T>(stripe_subscription_id: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
16
|
+
return Requests.processRoute(SubscriptionsRoute.routes.getCreatorSubscription, undefined, { stripe_subscription_id: stripe_subscription_id }, params);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -23,8 +23,8 @@ class Subscriptions {
|
|
|
23
23
|
*
|
|
24
24
|
* @returns promise
|
|
25
25
|
*/
|
|
26
|
-
|
|
27
|
-
return Requests.processRoute(SubscriptionsRoute.routes.getCommunityInfluencerSubscription, undefined, {community_id
|
|
26
|
+
public static getCommunityInfluencerSubscription<T>(community_id: string, stripe_subscription_id: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
27
|
+
return Requests.processRoute(SubscriptionsRoute.routes.getCommunityInfluencerSubscription, undefined, { community_id: community_id, stripe_subscription_id: stripe_subscription_id }, params);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -34,7 +34,7 @@ class Subscriptions {
|
|
|
34
34
|
*
|
|
35
35
|
* @returns promise
|
|
36
36
|
*/
|
|
37
|
-
public static listCreatorSubscriptions<T>(
|
|
37
|
+
public static listCreatorSubscriptions<T>(params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
38
38
|
return Requests.processRoute(SubscriptionsRoute.routes.listCreatorSubscriptions, undefined, undefined, params);
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -45,8 +45,8 @@ class Subscriptions {
|
|
|
45
45
|
*
|
|
46
46
|
* @returns promise
|
|
47
47
|
*/
|
|
48
|
-
public static listCommunityInfluencerSubscriptions<T>(community_id
|
|
49
|
-
return Requests.processRoute(SubscriptionsRoute.routes.listCommunityInfluencerSubscriptions, undefined, {community_id
|
|
48
|
+
public static listCommunityInfluencerSubscriptions<T>(community_id: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
49
|
+
return Requests.processRoute(SubscriptionsRoute.routes.listCommunityInfluencerSubscriptions, undefined, { community_id: community_id }, params);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
@@ -56,7 +56,7 @@ class Subscriptions {
|
|
|
56
56
|
*
|
|
57
57
|
* @returns A promise
|
|
58
58
|
*/
|
|
59
|
-
public static createCreatorSubscription<T>(data
|
|
59
|
+
public static createCreatorSubscription<T>(data?: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
60
60
|
return Requests.processRoute(SubscriptionsRoute.routes.createCreatorSubscription, data, {}, params);
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -67,8 +67,8 @@ class Subscriptions {
|
|
|
67
67
|
*
|
|
68
68
|
* @returns A promise
|
|
69
69
|
*/
|
|
70
|
-
public static createCommunityInfluencerSubscription<T>(community_id
|
|
71
|
-
return Requests.processRoute(SubscriptionsRoute.routes.createCommunityInfluencerSubscription, data, {community_id: community_id}, params);
|
|
70
|
+
public static createCommunityInfluencerSubscription<T>(community_id: string, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
71
|
+
return Requests.processRoute(SubscriptionsRoute.routes.createCommunityInfluencerSubscription, data, { community_id: community_id }, params);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
@@ -78,8 +78,8 @@ class Subscriptions {
|
|
|
78
78
|
*
|
|
79
79
|
* @returns A promise
|
|
80
80
|
*/
|
|
81
|
-
public static cancelCreatorSubscription<T>(stripe_subscription_id: string, data
|
|
82
|
-
return Requests.processRoute(SubscriptionsRoute.routes.cancelCreatorSubscription, data, {stripe_subscription_id
|
|
81
|
+
public static cancelCreatorSubscription<T>(stripe_subscription_id: string, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
82
|
+
return Requests.processRoute(SubscriptionsRoute.routes.cancelCreatorSubscription, data, { stripe_subscription_id: stripe_subscription_id }, params);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
@@ -89,8 +89,8 @@ class Subscriptions {
|
|
|
89
89
|
*
|
|
90
90
|
* @returns A promise
|
|
91
91
|
*/
|
|
92
|
-
public static cancelCommunityInfluencerSubscription<T>(community_id
|
|
93
|
-
return Requests.processRoute(SubscriptionsRoute.routes.cancelCommunityInfluencerSubscription, data, {community_id: community_id, stripe_subscription_id
|
|
92
|
+
public static cancelCommunityInfluencerSubscription<T>(community_id: string, stripe_subscription_id: string, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
93
|
+
return Requests.processRoute(SubscriptionsRoute.routes.cancelCommunityInfluencerSubscription, data, { community_id: community_id, stripe_subscription_id: stripe_subscription_id }, params);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
@@ -100,10 +100,20 @@ class Subscriptions {
|
|
|
100
100
|
*
|
|
101
101
|
* @returns A promise
|
|
102
102
|
*/
|
|
103
|
-
public static changeCommunityInfluencerSubscription<T>(community_id
|
|
104
|
-
return Requests.processRoute(SubscriptionsRoute.routes.changeCommunityInfluencerSubscription, data, {community_id: community_id}, params);
|
|
103
|
+
public static changeCommunityInfluencerSubscription<T>(community_id: string, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
104
|
+
return Requests.processRoute(SubscriptionsRoute.routes.changeCommunityInfluencerSubscription, data, { community_id: community_id }, params);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Create a custom tailored subscription for a business/community.
|
|
109
|
+
* Only accessible by Glitch administrators.
|
|
110
|
+
*
|
|
111
|
+
* @param community_id The ID of the community.
|
|
112
|
+
* @param data { priceId, paymentMethod, custom_name, limits: { posts, enrichments, invites, ads }, metered_prices: [] }
|
|
113
|
+
*/
|
|
114
|
+
public static createCustomCommunitySubscription<T>(community_id: string, data: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
115
|
+
return Requests.processRoute(SubscriptionsRoute.routes.createCustomCommunitySubscription, data, { community_id }, params);
|
|
105
116
|
}
|
|
106
|
-
|
|
107
117
|
|
|
108
118
|
}
|
|
109
119
|
|
package/src/config/Config.ts
CHANGED
|
@@ -89,16 +89,13 @@ class Config {
|
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
parts.shift();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
let formattedDomain = parts.join('.');
|
|
99
|
-
|
|
100
|
-
formattedDomain = formattedDomain.replace(/^\./, '');
|
|
92
|
+
// If the domain already starts with a dot, keep it.
|
|
93
|
+
// If not, and it's a standard domain, we usually want the dot for subdomains.
|
|
94
|
+
let formattedDomain = domain;
|
|
101
95
|
|
|
96
|
+
// REMOVE THIS LINE: formattedDomain = formattedDomain.replace(/^\./, '');
|
|
97
|
+
// We WANT the dot.
|
|
98
|
+
|
|
102
99
|
this._rootDomain = formattedDomain;
|
|
103
100
|
|
|
104
101
|
Storage.setRootDomain(formattedDomain);
|
|
@@ -93,6 +93,11 @@ class CommunitiesRoute {
|
|
|
93
93
|
|
|
94
94
|
// Subscriber registration (open route)
|
|
95
95
|
registerNewsletterSubscriber: { url: '/communities/{community_id}/newsletters/{newsletter_id}/subscribers', method: HTTP_METHODS.POST },
|
|
96
|
+
|
|
97
|
+
createOneTimeInvoice: {
|
|
98
|
+
url: '/communities/{community_id}/invoice-once',
|
|
99
|
+
method: HTTP_METHODS.POST
|
|
100
|
+
},
|
|
96
101
|
|
|
97
102
|
};
|
|
98
103
|
|
|
@@ -14,6 +14,11 @@ class SubscriptionsRoute {
|
|
|
14
14
|
cancelCommunityInfluencerSubscription: { url: '/subscriptions/communities/influencers/{community_id}/{stripe_subscription_id}', method: HTTP_METHODS.DELETE },
|
|
15
15
|
listCommunityInfluencerSubscriptions: { url: '/subscriptions/communities/influencers/{community_id}', method: HTTP_METHODS.GET },
|
|
16
16
|
changeCommunityInfluencerSubscription: { url: '/subscriptions/communities/influencers/change/{community_id}', method: HTTP_METHODS.POST },
|
|
17
|
+
|
|
18
|
+
createCustomCommunitySubscription: {
|
|
19
|
+
url: '/subscriptions/communities/custom/{community_id}',
|
|
20
|
+
method: HTTP_METHODS.POST
|
|
21
|
+
},
|
|
17
22
|
};
|
|
18
23
|
|
|
19
24
|
}
|
package/src/util/Session.ts
CHANGED
|
@@ -21,7 +21,7 @@ class BrowserCrypto implements CryptoInterface {
|
|
|
21
21
|
|
|
22
22
|
createHmac(algorithm: string, secret: string): HmacInterface {
|
|
23
23
|
let data = '';
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
const hmac: HmacInterface = {
|
|
26
26
|
update: (updateData: string): HmacInterface => {
|
|
27
27
|
data = updateData;
|
|
@@ -34,7 +34,7 @@ class BrowserCrypto implements CryptoInterface {
|
|
|
34
34
|
return this.CryptoJS.HmacSHA256(data, secret).toString(this.CryptoJS.enc.Hex);
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
return hmac;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -94,9 +94,17 @@ class Session {
|
|
|
94
94
|
|
|
95
95
|
public static isLoggedIn(): boolean {
|
|
96
96
|
const authToken = Storage.getAuthToken();
|
|
97
|
+
const expired = Storage.isTokenExpired();
|
|
98
|
+
|
|
99
|
+
if (expired) {
|
|
100
|
+
Session.end(); // Auto-clear if expired
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
|
|
97
104
|
return authToken !== null && authToken !== 'null' && authToken !== undefined;
|
|
98
105
|
}
|
|
99
106
|
|
|
107
|
+
|
|
100
108
|
public static getAuthToken(): string | null {
|
|
101
109
|
return Storage.getAuthToken();
|
|
102
110
|
}
|
|
@@ -124,6 +132,8 @@ class Session {
|
|
|
124
132
|
|
|
125
133
|
public static end(): void {
|
|
126
134
|
Storage.setAuthToken(null);
|
|
135
|
+
Storage.set('glitch_token_expiry', null); // Clear expiry
|
|
136
|
+
Storage.eraseCookie('glitch_token_expiry');
|
|
127
137
|
Storage.set(Session._id_key, null);
|
|
128
138
|
Storage.set(Session._first_name_key, null);
|
|
129
139
|
Storage.set(Session._last_name_key, null);
|
|
@@ -131,15 +141,17 @@ class Session {
|
|
|
131
141
|
Storage.set(Session._username_key, null);
|
|
132
142
|
}
|
|
133
143
|
|
|
134
|
-
public static processAuthentication(data: {
|
|
135
|
-
token: { access_token: string },
|
|
136
|
-
id: string,
|
|
137
|
-
first_name: string,
|
|
138
|
-
last_name: string,
|
|
139
|
-
email: string,
|
|
140
|
-
username: string
|
|
144
|
+
public static processAuthentication(data: {
|
|
145
|
+
token: { access_token: string, expires_in: number }, // Added expires_in
|
|
146
|
+
id: string,
|
|
147
|
+
first_name: string,
|
|
148
|
+
last_name: string,
|
|
149
|
+
email: string,
|
|
150
|
+
username: string
|
|
141
151
|
}): void {
|
|
142
152
|
Storage.setAuthToken(data.token.access_token);
|
|
153
|
+
Storage.setTokenExpiry(data.token.expires_in); // Save the timeout
|
|
154
|
+
|
|
143
155
|
Storage.set(Session._id_key, data.id);
|
|
144
156
|
Storage.set(Session._first_name_key, data.first_name);
|
|
145
157
|
Storage.set(Session._last_name_key, data.last_name);
|
package/src/util/Storage.ts
CHANGED
|
@@ -27,7 +27,7 @@ class Storage {
|
|
|
27
27
|
} catch (e) {
|
|
28
28
|
try {
|
|
29
29
|
this.setCookie(key, value, 31);
|
|
30
|
-
} catch(e){
|
|
30
|
+
} catch (e) {
|
|
31
31
|
|
|
32
32
|
}
|
|
33
33
|
Storage.data[key] = value;
|
|
@@ -52,10 +52,10 @@ class Storage {
|
|
|
52
52
|
|
|
53
53
|
try {
|
|
54
54
|
value = Storage.getCookie(key);
|
|
55
|
-
} catch(e) {
|
|
55
|
+
} catch (e) {
|
|
56
56
|
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
if (!value) {
|
|
60
60
|
value = Storage.data[key];
|
|
61
61
|
}
|
|
@@ -65,20 +65,37 @@ class Storage {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
public static setAuthToken(token: string | null) {
|
|
68
|
+
// Always set the cookie if we have a root domain to ensure cross-subdomain sync
|
|
69
|
+
if (Storage.rootDomain) {
|
|
70
|
+
if (token) {
|
|
71
|
+
this.setCookie('glitch_auth_token', token, 31);
|
|
72
|
+
} else {
|
|
73
|
+
this.eraseCookie('glitch_auth_token');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Still set localStorage for the current domain
|
|
68
77
|
Storage.set('glitch_auth_token', token);
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
public static getAuthToken(): string | null {
|
|
72
|
-
|
|
81
|
+
// 1. Try Cookie first (best for cross-subdomain)
|
|
82
|
+
let token = Storage.getCookie('glitch_auth_token');
|
|
83
|
+
|
|
84
|
+
// 2. Fallback to LocalStorage
|
|
85
|
+
if (!token || token === 'null') {
|
|
86
|
+
token = Storage.get('glitch_auth_token');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (token === 'null' || !token) ? null : token;
|
|
73
90
|
}
|
|
74
91
|
|
|
75
92
|
public static eraseCookie(name: string) {
|
|
76
93
|
|
|
77
|
-
if(document){
|
|
94
|
+
if (document) {
|
|
78
95
|
document.cookie =
|
|
79
96
|
name +
|
|
80
97
|
'=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
81
|
-
|
|
98
|
+
}
|
|
82
99
|
}
|
|
83
100
|
|
|
84
101
|
private static setCookie(name: string, value: string, days: number) {
|
|
@@ -89,7 +106,8 @@ class Storage {
|
|
|
89
106
|
expires = '; expires=' + date.toUTCString();
|
|
90
107
|
}
|
|
91
108
|
|
|
92
|
-
if(document){
|
|
109
|
+
if (typeof document !== 'undefined') {
|
|
110
|
+
// If rootDomain is .glitch.fun, this works for all subdomains
|
|
93
111
|
document.cookie =
|
|
94
112
|
name +
|
|
95
113
|
'=' +
|
|
@@ -97,12 +115,12 @@ class Storage {
|
|
|
97
115
|
expires +
|
|
98
116
|
'; path=/; domain=' +
|
|
99
117
|
Storage.rootDomain +
|
|
100
|
-
';
|
|
118
|
+
'; SameSite=Lax; Secure';
|
|
101
119
|
}
|
|
102
120
|
}
|
|
103
121
|
|
|
104
122
|
private static getCookie(name: string): string | null {
|
|
105
|
-
if(document){
|
|
123
|
+
if (document) {
|
|
106
124
|
const nameEQ = name + '=';
|
|
107
125
|
const ca = document.cookie.split(';');
|
|
108
126
|
for (let i = 0; i < ca.length; i++) {
|
|
@@ -113,6 +131,31 @@ class Storage {
|
|
|
113
131
|
}
|
|
114
132
|
return null;
|
|
115
133
|
}
|
|
134
|
+
|
|
135
|
+
public static setTokenExpiry(expiresInSeconds: number) {
|
|
136
|
+
const expiryTime = Date.now() + (expiresInSeconds * 1000);
|
|
137
|
+
Storage.set('glitch_token_expiry', expiryTime);
|
|
138
|
+
|
|
139
|
+
// Also set a cookie for cross-subdomain consistency if rootDomain exists
|
|
140
|
+
if (Storage.rootDomain && typeof document !== 'undefined') {
|
|
141
|
+
this.setCookie('glitch_token_expiry', expiryTime.toString(), 31);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public static getTokenExpiry(): number | null {
|
|
146
|
+
let expiry = Storage.getCookie('glitch_token_expiry');
|
|
147
|
+
if (!expiry) {
|
|
148
|
+
expiry = Storage.get('glitch_token_expiry');
|
|
149
|
+
}
|
|
150
|
+
return expiry ? parseInt(expiry) : null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public static isTokenExpired(): boolean {
|
|
154
|
+
const expiry = this.getTokenExpiry();
|
|
155
|
+
if (!expiry) return false; // If no expiry set, assume valid or let API handle 401
|
|
156
|
+
|
|
157
|
+
return Date.now() > expiry;
|
|
158
|
+
}
|
|
116
159
|
}
|
|
117
160
|
|
|
118
161
|
export default Storage;
|