glitch-javascript-sdk 0.2.5 → 0.2.7
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 +291 -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 +11 -0
- package/dist/esm/index.js +447 -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 +126 -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 +104 -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,17 @@ 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
|
+
console.log("setting communty_id", community_id);
|
|
50
|
+
this.community_id = community_id;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
40
54
|
|
|
41
55
|
private static request<T>(
|
|
42
56
|
method: 'GET' | 'POST' | 'PUT' | 'DELETE',
|
|
@@ -81,19 +95,82 @@ class Requests {
|
|
|
81
95
|
* @param url
|
|
82
96
|
* @returns
|
|
83
97
|
*/
|
|
84
|
-
public static get<T>(url: string): AxiosPromise<Response<T>> {
|
|
98
|
+
public static get<T>(url: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
99
|
+
|
|
100
|
+
if (params && Object.keys(params).length > 0) {
|
|
101
|
+
const queryString = Object.entries(params)
|
|
102
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
103
|
+
.join('&');
|
|
104
|
+
url = `${url}?${queryString}`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
console.log("Community ID in Request", this.community_id);
|
|
108
|
+
if (this.community_id) {
|
|
109
|
+
// Check if the URL already contains query parameters
|
|
110
|
+
const separator = url.includes('?') ? '&' : '?';
|
|
111
|
+
// Append the community_id query parameter
|
|
112
|
+
url = `${url}${separator}community_id=${this.community_id}`;
|
|
113
|
+
}
|
|
114
|
+
|
|
85
115
|
return this.request<T>('GET', url);
|
|
86
116
|
}
|
|
87
117
|
|
|
88
|
-
public static post<T>(url: string, data: any): AxiosPromise<Response<T>> {
|
|
118
|
+
public static post<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
119
|
+
|
|
120
|
+
if (params && Object.keys(params).length > 0) {
|
|
121
|
+
const queryString = Object.entries(params)
|
|
122
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
123
|
+
.join('&');
|
|
124
|
+
url = `${url}?${queryString}`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (this.community_id) {
|
|
128
|
+
// Add the community_id to the request body
|
|
129
|
+
data = {
|
|
130
|
+
...data,
|
|
131
|
+
communities: [ this.community_id ]
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
89
135
|
return this.request<T>('POST', url, data);
|
|
90
136
|
}
|
|
91
137
|
|
|
92
|
-
public static put<T>(url: string, data: any): AxiosPromise<Response<T>> {
|
|
138
|
+
public static put<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
139
|
+
|
|
140
|
+
if (params && Object.keys(params).length > 0) {
|
|
141
|
+
const queryString = Object.entries(params)
|
|
142
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
143
|
+
.join('&');
|
|
144
|
+
url = `${url}?${queryString}`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (this.community_id) {
|
|
148
|
+
// Add the community_id to the request body
|
|
149
|
+
data = {
|
|
150
|
+
...data,
|
|
151
|
+
community_id: this.community_id
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
93
155
|
return this.request<T>('PUT', url, data);
|
|
94
156
|
}
|
|
95
157
|
|
|
96
|
-
public static delete<T>(url: string): AxiosPromise<Response<T>> {
|
|
158
|
+
public static delete<T>(url: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
159
|
+
|
|
160
|
+
if (params && Object.keys(params).length > 0) {
|
|
161
|
+
const queryString = Object.entries(params)
|
|
162
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
163
|
+
.join('&');
|
|
164
|
+
url = `${url}?${queryString}`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (this.community_id) {
|
|
168
|
+
// Check if the URL already contains query parameters
|
|
169
|
+
const separator = url.includes('?') ? '&' : '?';
|
|
170
|
+
// Append the community_id query parameter
|
|
171
|
+
url = `${url}${separator}community_id=${this.community_id}`;
|
|
172
|
+
}
|
|
173
|
+
|
|
97
174
|
return this.request<T>('DELETE', url);
|
|
98
175
|
}
|
|
99
176
|
|
|
@@ -101,8 +178,16 @@ class Requests {
|
|
|
101
178
|
url: string,
|
|
102
179
|
filename : string,
|
|
103
180
|
file: File,
|
|
104
|
-
data?: any
|
|
181
|
+
data?: any,
|
|
182
|
+
params?: Record<string, any>
|
|
105
183
|
): AxiosPromise<Response<T>> {
|
|
184
|
+
|
|
185
|
+
if (params && Object.keys(params).length > 0) {
|
|
186
|
+
const queryString = Object.entries(params)
|
|
187
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
188
|
+
.join('&');
|
|
189
|
+
url = `${url}?${queryString}`;
|
|
190
|
+
}
|
|
106
191
|
|
|
107
192
|
const formData = new FormData();
|
|
108
193
|
|
|
@@ -119,9 +204,17 @@ class Requests {
|
|
|
119
204
|
url: string,
|
|
120
205
|
filename : string,
|
|
121
206
|
blob: Blob,
|
|
122
|
-
data?: any
|
|
207
|
+
data?: any,
|
|
208
|
+
params?: Record<string, any>
|
|
123
209
|
): AxiosPromise<Response<T>> {
|
|
124
210
|
|
|
211
|
+
if (params && Object.keys(params).length > 0) {
|
|
212
|
+
const queryString = Object.entries(params)
|
|
213
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
214
|
+
.join('&');
|
|
215
|
+
url = `${url}?${queryString}`;
|
|
216
|
+
}
|
|
217
|
+
|
|
125
218
|
const formData = new FormData();
|
|
126
219
|
|
|
127
220
|
formData.append(filename, blob);
|
|
@@ -141,7 +234,7 @@ class Requests {
|
|
|
141
234
|
* @param data
|
|
142
235
|
* @returns
|
|
143
236
|
*/
|
|
144
|
-
public static processRoute<T>(route : Route, data? : object, routeReplace? : {[key: string]: any}) : AxiosPromise<Response<T>> {
|
|
237
|
+
public static processRoute<T>(route : Route, data? : object, routeReplace? : {[key: string]: any}, params?: Record<string, any>) : AxiosPromise<Response<T>> {
|
|
145
238
|
|
|
146
239
|
let url = route.url;
|
|
147
240
|
|
|
@@ -154,13 +247,13 @@ class Requests {
|
|
|
154
247
|
}
|
|
155
248
|
|
|
156
249
|
if(route.method == HTTP_METHODS.GET) {
|
|
157
|
-
return this.get(url);
|
|
250
|
+
return this.get(url, params);
|
|
158
251
|
} else if(route.method == HTTP_METHODS.POST) {
|
|
159
|
-
return this.post(url, data);
|
|
252
|
+
return this.post(url, data, params);
|
|
160
253
|
} else if(route.method == HTTP_METHODS.PUT) {
|
|
161
|
-
return this.put(url, data);
|
|
254
|
+
return this.put(url, data, params);
|
|
162
255
|
} else if(route.method == HTTP_METHODS.DELETE) {
|
|
163
|
-
return this.delete(url);
|
|
256
|
+
return this.delete(url, params);
|
|
164
257
|
}
|
|
165
258
|
|
|
166
259
|
return this.get(url);
|