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 +66 -41
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/Communities.d.ts +17 -0
- package/dist/esm/index.js +66 -41
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/util/Storage.d.ts +0 -6
- package/dist/index.d.ts +17 -6
- package/package.json +1 -1
- package/src/api/Communities.ts +24 -5
- package/src/api/Subscriptions.ts +1 -0
- package/src/routes/CommunitiesRoute.ts +17 -4
- package/src/util/Storage.ts +35 -46
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
declare class Storage {
|
|
2
2
|
private static rootDomain;
|
|
3
3
|
private static data;
|
|
4
|
-
/**
|
|
5
|
-
* Sets a root level domain so the data can persist across
|
|
6
|
-
* subdomains
|
|
7
|
-
*
|
|
8
|
-
* @param rootDomain
|
|
9
|
-
*/
|
|
10
4
|
static setRootDomain(rootDomain: string): void;
|
|
11
5
|
private static getStorageKey;
|
|
12
6
|
static set(key: string, value: any): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1796,6 +1796,23 @@ declare class Communities {
|
|
|
1796
1796
|
amount: number;
|
|
1797
1797
|
description: string;
|
|
1798
1798
|
}, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
1799
|
+
/**
|
|
1800
|
+
* Get a detailed breakdown of a specific invoice including per-title usage.
|
|
1801
|
+
*
|
|
1802
|
+
* @param community_id The ID of the community.
|
|
1803
|
+
* @param invoice_id The Stripe Invoice ID (e.g., in_123...).
|
|
1804
|
+
*/
|
|
1805
|
+
static getInvoiceDetails<T>(community_id: string, invoice_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
1806
|
+
/**
|
|
1807
|
+
* Generate a custom date-range statement for reimbursement.
|
|
1808
|
+
*
|
|
1809
|
+
* @param community_id The ID of the community.
|
|
1810
|
+
* @param params Should include { start_date: 'YYYY-MM-DD', end_date: 'YYYY-MM-DD' }
|
|
1811
|
+
*/
|
|
1812
|
+
static getCustomStatement<T>(community_id: string, params: {
|
|
1813
|
+
start_date: string;
|
|
1814
|
+
end_date: string;
|
|
1815
|
+
}): AxiosPromise<Response<T>>;
|
|
1799
1816
|
}
|
|
1800
1817
|
|
|
1801
1818
|
declare class Users {
|
|
@@ -7438,12 +7455,6 @@ declare class Session {
|
|
|
7438
7455
|
declare class Storage {
|
|
7439
7456
|
private static rootDomain;
|
|
7440
7457
|
private static data;
|
|
7441
|
-
/**
|
|
7442
|
-
* Sets a root level domain so the data can persist across
|
|
7443
|
-
* subdomains
|
|
7444
|
-
*
|
|
7445
|
-
* @param rootDomain
|
|
7446
|
-
*/
|
|
7447
7458
|
static setRootDomain(rootDomain: string): void;
|
|
7448
7459
|
private static getStorageKey;
|
|
7449
7460
|
static set(key: string, value: any): void;
|
package/package.json
CHANGED
package/src/api/Communities.ts
CHANGED
|
@@ -929,16 +929,35 @@ 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
|
-
|
|
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
|
+
|
|
942
|
+
/**
|
|
943
|
+
* Get a detailed breakdown of a specific invoice including per-title usage.
|
|
934
944
|
*
|
|
935
945
|
* @param community_id The ID of the community.
|
|
936
|
-
* @param
|
|
946
|
+
* @param invoice_id The Stripe Invoice ID (e.g., in_123...).
|
|
937
947
|
*/
|
|
938
|
-
public static
|
|
939
|
-
return Requests.processRoute(CommunitiesRoute.routes.
|
|
948
|
+
public static getInvoiceDetails<T>(community_id: string, invoice_id: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
949
|
+
return Requests.processRoute(CommunitiesRoute.routes.getInvoiceDetails, undefined, { community_id, invoice_id }, params);
|
|
940
950
|
}
|
|
941
951
|
|
|
952
|
+
/**
|
|
953
|
+
* Generate a custom date-range statement for reimbursement.
|
|
954
|
+
*
|
|
955
|
+
* @param community_id The ID of the community.
|
|
956
|
+
* @param params Should include { start_date: 'YYYY-MM-DD', end_date: 'YYYY-MM-DD' }
|
|
957
|
+
*/
|
|
958
|
+
public static getCustomStatement<T>(community_id: string, params: { start_date: string, end_date: string }): AxiosPromise<Response<T>> {
|
|
959
|
+
return Requests.processRoute(CommunitiesRoute.routes.getCustomStatement, undefined, { community_id }, params);
|
|
960
|
+
}
|
|
942
961
|
|
|
943
962
|
}
|
|
944
963
|
|
package/src/api/Subscriptions.ts
CHANGED
|
@@ -94,11 +94,24 @@ class CommunitiesRoute {
|
|
|
94
94
|
// Subscriber registration (open route)
|
|
95
95
|
registerNewsletterSubscriber: { url: '/communities/{community_id}/newsletters/{newsletter_id}/subscribers', method: HTTP_METHODS.POST },
|
|
96
96
|
|
|
97
|
-
createOneTimeInvoice: {
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
createOneTimeInvoice: {
|
|
98
|
+
url: '/communities/{community_id}/invoice-once',
|
|
99
|
+
method: HTTP_METHODS.POST
|
|
100
|
+
},
|
|
101
|
+
// New Invoicing and Statement Routes
|
|
102
|
+
listInvoices: {
|
|
103
|
+
url: '/communities/{community_id}/payment/invoices',
|
|
104
|
+
method: HTTP_METHODS.GET
|
|
105
|
+
},
|
|
106
|
+
getInvoiceDetails: {
|
|
107
|
+
url: '/communities/{community_id}/payment/invoices/{invoice_id}',
|
|
108
|
+
method: HTTP_METHODS.GET
|
|
100
109
|
},
|
|
101
|
-
|
|
110
|
+
getCustomStatement: {
|
|
111
|
+
url: '/communities/{community_id}/payment/statement',
|
|
112
|
+
method: HTTP_METHODS.GET
|
|
113
|
+
},
|
|
114
|
+
|
|
102
115
|
};
|
|
103
116
|
|
|
104
117
|
|
package/src/util/Storage.ts
CHANGED
|
@@ -2,12 +2,6 @@ class Storage {
|
|
|
2
2
|
private static rootDomain: string = '';
|
|
3
3
|
private static data: { [key: string]: any } = {};
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Sets a root level domain so the data can persist across
|
|
7
|
-
* subdomains
|
|
8
|
-
*
|
|
9
|
-
* @param rootDomain
|
|
10
|
-
*/
|
|
11
5
|
public static setRootDomain(rootDomain: string) {
|
|
12
6
|
Storage.rootDomain = rootDomain;
|
|
13
7
|
}
|
|
@@ -17,55 +11,55 @@ class Storage {
|
|
|
17
11
|
}
|
|
18
12
|
|
|
19
13
|
public static set(key: string, value: any) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
// 1. Always update in-memory fallback for the current process
|
|
15
|
+
Storage.data[key] = value;
|
|
16
|
+
|
|
17
|
+
// 2. Only attempt browser storage if window exists
|
|
18
|
+
if (typeof window !== 'undefined') {
|
|
24
19
|
try {
|
|
25
20
|
const serializedValue = JSON.stringify(value);
|
|
26
|
-
window.
|
|
21
|
+
window.localStorage.setItem(Storage.getStorageKey(key), serializedValue);
|
|
27
22
|
} catch (e) {
|
|
28
23
|
try {
|
|
29
|
-
|
|
24
|
+
const serializedValue = JSON.stringify(value);
|
|
25
|
+
window.sessionStorage.setItem(Storage.getStorageKey(key), serializedValue);
|
|
30
26
|
} catch (e) {
|
|
31
|
-
|
|
27
|
+
try {
|
|
28
|
+
this.setCookie(key, value, 31);
|
|
29
|
+
} catch (e) {}
|
|
32
30
|
}
|
|
33
|
-
Storage.data[key] = value;
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
34
|
|
|
38
35
|
public static get(key: string): any {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (serializedValue !== null) {
|
|
42
|
-
return JSON.parse(serializedValue);
|
|
43
|
-
}
|
|
44
|
-
} catch (e) {
|
|
36
|
+
// 1. Try Browser Storage if available
|
|
37
|
+
if (typeof window !== 'undefined') {
|
|
45
38
|
try {
|
|
46
|
-
const serializedValue = window.
|
|
47
|
-
if (serializedValue !== null)
|
|
48
|
-
return JSON.parse(serializedValue);
|
|
49
|
-
}
|
|
39
|
+
const serializedValue = window.localStorage.getItem(Storage.getStorageKey(key));
|
|
40
|
+
if (serializedValue !== null) return JSON.parse(serializedValue);
|
|
50
41
|
} catch (e) {
|
|
51
|
-
let value = null;
|
|
52
|
-
|
|
53
42
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
const serializedValue = window.sessionStorage.getItem(Storage.getStorageKey(key));
|
|
44
|
+
if (serializedValue !== null) return JSON.parse(serializedValue);
|
|
45
|
+
} catch (e) {}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
56
48
|
|
|
57
|
-
|
|
49
|
+
// 2. Try Cookie (getCookie is now SSR safe)
|
|
50
|
+
let value = null;
|
|
51
|
+
try {
|
|
52
|
+
value = Storage.getCookie(key);
|
|
53
|
+
} catch (e) {}
|
|
58
54
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return value;
|
|
63
|
-
}
|
|
55
|
+
// 3. Fallback to in-memory data
|
|
56
|
+
if (!value) {
|
|
57
|
+
value = Storage.data[key];
|
|
64
58
|
}
|
|
59
|
+
return value;
|
|
65
60
|
}
|
|
66
61
|
|
|
67
62
|
public static setAuthToken(token: string | null) {
|
|
68
|
-
// Always set the cookie if we have a root domain to ensure cross-subdomain sync
|
|
69
63
|
if (Storage.rootDomain) {
|
|
70
64
|
if (token) {
|
|
71
65
|
this.setCookie('glitch_auth_token', token, 31);
|
|
@@ -73,15 +67,12 @@ class Storage {
|
|
|
73
67
|
this.eraseCookie('glitch_auth_token');
|
|
74
68
|
}
|
|
75
69
|
}
|
|
76
|
-
// Still set localStorage for the current domain
|
|
77
70
|
Storage.set('glitch_auth_token', token);
|
|
78
71
|
}
|
|
79
72
|
|
|
80
73
|
public static getAuthToken(): string | null {
|
|
81
|
-
// 1. Try Cookie first (best for cross-subdomain)
|
|
82
74
|
let token = Storage.getCookie('glitch_auth_token');
|
|
83
75
|
|
|
84
|
-
// 2. Fallback to LocalStorage
|
|
85
76
|
if (!token || token === 'null') {
|
|
86
77
|
token = Storage.get('glitch_auth_token');
|
|
87
78
|
}
|
|
@@ -90,8 +81,8 @@ class Storage {
|
|
|
90
81
|
}
|
|
91
82
|
|
|
92
83
|
public static eraseCookie(name: string) {
|
|
93
|
-
|
|
94
|
-
if (document) {
|
|
84
|
+
// Use typeof check to prevent ReferenceError
|
|
85
|
+
if (typeof document !== 'undefined') {
|
|
95
86
|
document.cookie =
|
|
96
87
|
name +
|
|
97
88
|
'=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
@@ -107,7 +98,6 @@ class Storage {
|
|
|
107
98
|
}
|
|
108
99
|
|
|
109
100
|
if (typeof document !== 'undefined') {
|
|
110
|
-
// If rootDomain is .glitch.fun, this works for all subdomains
|
|
111
101
|
document.cookie =
|
|
112
102
|
name +
|
|
113
103
|
'=' +
|
|
@@ -120,7 +110,8 @@ class Storage {
|
|
|
120
110
|
}
|
|
121
111
|
|
|
122
112
|
private static getCookie(name: string): string | null {
|
|
123
|
-
|
|
113
|
+
// Use typeof check to prevent ReferenceError
|
|
114
|
+
if (typeof document !== 'undefined') {
|
|
124
115
|
const nameEQ = name + '=';
|
|
125
116
|
const ca = document.cookie.split(';');
|
|
126
117
|
for (let i = 0; i < ca.length; i++) {
|
|
@@ -136,7 +127,6 @@ class Storage {
|
|
|
136
127
|
const expiryTime = Date.now() + (expiresInSeconds * 1000);
|
|
137
128
|
Storage.set('glitch_token_expiry', expiryTime);
|
|
138
129
|
|
|
139
|
-
// Also set a cookie for cross-subdomain consistency if rootDomain exists
|
|
140
130
|
if (Storage.rootDomain && typeof document !== 'undefined') {
|
|
141
131
|
this.setCookie('glitch_token_expiry', expiryTime.toString(), 31);
|
|
142
132
|
}
|
|
@@ -152,10 +142,9 @@ class Storage {
|
|
|
152
142
|
|
|
153
143
|
public static isTokenExpired(): boolean {
|
|
154
144
|
const expiry = this.getTokenExpiry();
|
|
155
|
-
if (!expiry) return false;
|
|
156
|
-
|
|
145
|
+
if (!expiry) return false;
|
|
157
146
|
return Date.now() > expiry;
|
|
158
147
|
}
|
|
159
148
|
}
|
|
160
149
|
|
|
161
|
-
export default Storage;
|
|
150
|
+
export default Storage;
|