glitch-javascript-sdk 0.2.5 → 0.2.6
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 +289 -160
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/Communities.d.ts +20 -20
- package/dist/esm/api/Competitions.d.ts +40 -40
- package/dist/esm/api/Events.d.ts +17 -17
- package/dist/esm/api/Teams.d.ts +7 -7
- package/dist/esm/api/Templates.d.ts +9 -9
- package/dist/esm/api/Users.d.ts +3 -3
- package/dist/esm/api/Waitlist.d.ts +5 -5
- package/dist/esm/config/Config.d.ts +12 -0
- package/dist/esm/index.js +445 -316
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/models/community.d.ts +40 -0
- package/dist/esm/models/template.d.ts +15 -0
- package/dist/esm/models/user.d.ts +29 -0
- package/dist/esm/util/Requests.d.ts +14 -7
- package/dist/index.d.ts +208 -108
- package/package.json +1 -1
- package/src/api/Communities.ts +39 -39
- package/src/api/Competitions.ts +45 -45
- package/src/api/Events.ts +21 -21
- package/src/api/Teams.ts +14 -14
- package/src/api/Templates.ts +14 -14
- package/src/api/Users.ts +7 -6
- package/src/api/Waitlist.ts +10 -10
- package/src/config/Config.ts +20 -0
- package/src/models/community.ts +42 -0
- package/src/models/template.ts +16 -0
- package/src/models/user.ts +31 -0
- package/src/util/Requests.ts +102 -11
package/src/util/Requests.ts
CHANGED
|
@@ -15,6 +15,9 @@ class Requests {
|
|
|
15
15
|
//The Json Web Token to send in the header
|
|
16
16
|
private static authToken = "";
|
|
17
17
|
|
|
18
|
+
//The ID of the community that will be added to request
|
|
19
|
+
private static community_id? = "";
|
|
20
|
+
|
|
18
21
|
constructor(config: Config) {
|
|
19
22
|
this.config = config;
|
|
20
23
|
}
|
|
@@ -37,6 +40,16 @@ class Requests {
|
|
|
37
40
|
this.authToken = token;
|
|
38
41
|
}
|
|
39
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Sets the community id that will be associated with all requests
|
|
45
|
+
*
|
|
46
|
+
* @param token
|
|
47
|
+
*/
|
|
48
|
+
public static setCommunityID(community_id : string | undefined) {
|
|
49
|
+
this.community_id = community_id;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
40
53
|
|
|
41
54
|
private static request<T>(
|
|
42
55
|
method: 'GET' | 'POST' | 'PUT' | 'DELETE',
|
|
@@ -81,19 +94,81 @@ class Requests {
|
|
|
81
94
|
* @param url
|
|
82
95
|
* @returns
|
|
83
96
|
*/
|
|
84
|
-
public static get<T>(url: string): AxiosPromise<Response<T>> {
|
|
97
|
+
public static get<T>(url: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
98
|
+
|
|
99
|
+
if (params && Object.keys(params).length > 0) {
|
|
100
|
+
const queryString = Object.entries(params)
|
|
101
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
102
|
+
.join('&');
|
|
103
|
+
url = `${url}?${queryString}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (this.community_id) {
|
|
107
|
+
// Check if the URL already contains query parameters
|
|
108
|
+
const separator = url.includes('?') ? '&' : '?';
|
|
109
|
+
// Append the community_id query parameter
|
|
110
|
+
url = `${url}${separator}community_id=${this.community_id}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
85
113
|
return this.request<T>('GET', url);
|
|
86
114
|
}
|
|
87
115
|
|
|
88
|
-
public static post<T>(url: string, data: any): AxiosPromise<Response<T>> {
|
|
116
|
+
public static post<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
117
|
+
|
|
118
|
+
if (params && Object.keys(params).length > 0) {
|
|
119
|
+
const queryString = Object.entries(params)
|
|
120
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
121
|
+
.join('&');
|
|
122
|
+
url = `${url}?${queryString}`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (this.community_id) {
|
|
126
|
+
// Add the community_id to the request body
|
|
127
|
+
data = {
|
|
128
|
+
...data,
|
|
129
|
+
communities: [ this.community_id ]
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
89
133
|
return this.request<T>('POST', url, data);
|
|
90
134
|
}
|
|
91
135
|
|
|
92
|
-
public static put<T>(url: string, data: any): AxiosPromise<Response<T>> {
|
|
136
|
+
public static put<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
137
|
+
|
|
138
|
+
if (params && Object.keys(params).length > 0) {
|
|
139
|
+
const queryString = Object.entries(params)
|
|
140
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
141
|
+
.join('&');
|
|
142
|
+
url = `${url}?${queryString}`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (this.community_id) {
|
|
146
|
+
// Add the community_id to the request body
|
|
147
|
+
data = {
|
|
148
|
+
...data,
|
|
149
|
+
community_id: this.community_id
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
93
153
|
return this.request<T>('PUT', url, data);
|
|
94
154
|
}
|
|
95
155
|
|
|
96
|
-
public static delete<T>(url: string): AxiosPromise<Response<T>> {
|
|
156
|
+
public static delete<T>(url: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
157
|
+
|
|
158
|
+
if (params && Object.keys(params).length > 0) {
|
|
159
|
+
const queryString = Object.entries(params)
|
|
160
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
161
|
+
.join('&');
|
|
162
|
+
url = `${url}?${queryString}`;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (this.community_id) {
|
|
166
|
+
// Check if the URL already contains query parameters
|
|
167
|
+
const separator = url.includes('?') ? '&' : '?';
|
|
168
|
+
// Append the community_id query parameter
|
|
169
|
+
url = `${url}${separator}community_id=${this.community_id}`;
|
|
170
|
+
}
|
|
171
|
+
|
|
97
172
|
return this.request<T>('DELETE', url);
|
|
98
173
|
}
|
|
99
174
|
|
|
@@ -101,8 +176,16 @@ class Requests {
|
|
|
101
176
|
url: string,
|
|
102
177
|
filename : string,
|
|
103
178
|
file: File,
|
|
104
|
-
data?: any
|
|
179
|
+
data?: any,
|
|
180
|
+
params?: Record<string, any>
|
|
105
181
|
): AxiosPromise<Response<T>> {
|
|
182
|
+
|
|
183
|
+
if (params && Object.keys(params).length > 0) {
|
|
184
|
+
const queryString = Object.entries(params)
|
|
185
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
186
|
+
.join('&');
|
|
187
|
+
url = `${url}?${queryString}`;
|
|
188
|
+
}
|
|
106
189
|
|
|
107
190
|
const formData = new FormData();
|
|
108
191
|
|
|
@@ -119,9 +202,17 @@ class Requests {
|
|
|
119
202
|
url: string,
|
|
120
203
|
filename : string,
|
|
121
204
|
blob: Blob,
|
|
122
|
-
data?: any
|
|
205
|
+
data?: any,
|
|
206
|
+
params?: Record<string, any>
|
|
123
207
|
): AxiosPromise<Response<T>> {
|
|
124
208
|
|
|
209
|
+
if (params && Object.keys(params).length > 0) {
|
|
210
|
+
const queryString = Object.entries(params)
|
|
211
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
212
|
+
.join('&');
|
|
213
|
+
url = `${url}?${queryString}`;
|
|
214
|
+
}
|
|
215
|
+
|
|
125
216
|
const formData = new FormData();
|
|
126
217
|
|
|
127
218
|
formData.append(filename, blob);
|
|
@@ -141,7 +232,7 @@ class Requests {
|
|
|
141
232
|
* @param data
|
|
142
233
|
* @returns
|
|
143
234
|
*/
|
|
144
|
-
public static processRoute<T>(route : Route, data? : object, routeReplace? : {[key: string]: any}) : AxiosPromise<Response<T>> {
|
|
235
|
+
public static processRoute<T>(route : Route, data? : object, routeReplace? : {[key: string]: any}, params?: Record<string, any>) : AxiosPromise<Response<T>> {
|
|
145
236
|
|
|
146
237
|
let url = route.url;
|
|
147
238
|
|
|
@@ -154,13 +245,13 @@ class Requests {
|
|
|
154
245
|
}
|
|
155
246
|
|
|
156
247
|
if(route.method == HTTP_METHODS.GET) {
|
|
157
|
-
return this.get(url);
|
|
248
|
+
return this.get(url, params);
|
|
158
249
|
} else if(route.method == HTTP_METHODS.POST) {
|
|
159
|
-
return this.post(url, data);
|
|
250
|
+
return this.post(url, data, params);
|
|
160
251
|
} else if(route.method == HTTP_METHODS.PUT) {
|
|
161
|
-
return this.put(url, data);
|
|
252
|
+
return this.put(url, data, params);
|
|
162
253
|
} else if(route.method == HTTP_METHODS.DELETE) {
|
|
163
|
-
return this.delete(url);
|
|
254
|
+
return this.delete(url, params);
|
|
164
255
|
}
|
|
165
256
|
|
|
166
257
|
return this.get(url);
|