glitch-javascript-sdk 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ import Route from "./interface";
2
+ declare class AuthRoutes {
3
+ static routes: {
4
+ [key: string]: Route;
5
+ };
6
+ }
7
+ export default AuthRoutes;
@@ -0,0 +1,7 @@
1
+ import Route from "./interface";
2
+ declare class CompetitionRoutes {
3
+ static routes: {
4
+ [key: string]: Route;
5
+ };
6
+ }
7
+ export default CompetitionRoutes;
@@ -0,0 +1,5 @@
1
+ interface Route {
2
+ url: string;
3
+ method: string;
4
+ }
5
+ export default Route;
@@ -0,0 +1,27 @@
1
+ import Config from '../config/Config';
2
+ import Route from '../routes/interface';
3
+ import Response from './Response';
4
+ declare class Requests {
5
+ config: Config;
6
+ private static baseUrl;
7
+ private static authToken;
8
+ constructor(config: Config);
9
+ static setConfig(config: Config): void;
10
+ static setBaseUrl(url: string): void;
11
+ static setAuthToken(token: string): void;
12
+ private static request;
13
+ static get<T>(url: string): Promise<Response<T>>;
14
+ static post<T>(url: string, data: any): Promise<Response<T>>;
15
+ static put<T>(url: string, data: any): Promise<Response<T>>;
16
+ static delete<T>(url: string): Promise<Response<T>>;
17
+ /**
18
+ * The Route class contains the method and url, thereforce items can be
19
+ * automatically routed depending on the configuration.
20
+ *
21
+ * @param route
22
+ * @param data
23
+ * @returns
24
+ */
25
+ static processRoute(route: Route, data?: object, routeReplace?: object): Promise<Response<unknown> | undefined>;
26
+ }
27
+ export default Requests;
@@ -0,0 +1,6 @@
1
+ interface Response<T> {
2
+ data: T;
3
+ success: boolean;
4
+ message?: string;
5
+ }
6
+ export default Response;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Config
3
+ *
4
+ * The configuration class will hold the configuration information used when accessing the
5
+ * API.
6
+ */
7
+ declare class Config {
8
+ baseUrl: string;
9
+ authToken: string;
10
+ constructor(baseUrl: string, authToken: string);
11
+ setBaseUrl(baseUrl: string): void;
12
+ setAuthToken(authToken: string): void;
13
+ }
14
+
15
+ interface Response<T> {
16
+ data: T;
17
+ success: boolean;
18
+ message?: string;
19
+ }
20
+
21
+ declare class Auth {
22
+ static login(login: string, password: string): Promise<Response<unknown>>;
23
+ static register(data: object): Promise<Response<unknown> | undefined>;
24
+ }
25
+
26
+ declare class Competitions {
27
+ static list(): Promise<Response<unknown> | undefined>;
28
+ static create(data: object): Promise<Response<unknown> | undefined>;
29
+ static update(competition_id: string, data: object): Promise<Response<unknown> | undefined>;
30
+ static view(competition_id: string): Promise<Response<unknown> | undefined>;
31
+ static delete(competition_id: string): Promise<Response<unknown> | undefined>;
32
+ }
33
+
34
+ declare class Glitch {
35
+ static config: typeof Config;
36
+ static auth: typeof Auth;
37
+ static competitions: typeof Competitions;
38
+ }
39
+
40
+ export { Glitch };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "glitch-javascript-sdk",
3
+ "version": "0.0.1",
4
+ "description": "Javascrip SDK for GLitch",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "files": [
8
+ "dist",
9
+ "src"
10
+ ],
11
+ "types": "dist/index.d.ts",
12
+ "scripts": {
13
+ "test": "echo \"Error: no test specified\" && exit 1",
14
+ "build": "rm -Rf dist && rollup -c --bundleConfigAsCjs",
15
+ "build-docs": "rm -rf docs && typedoc --tsconfig tsconfig.json src/"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "src"
20
+ ],
21
+ "author": "",
22
+ "license": "ISC",
23
+ "devDependencies": {
24
+ "@rollup/plugin-commonjs": "^23.0.2",
25
+ "@rollup/plugin-json": "^5.0.1",
26
+ "@rollup/plugin-node-resolve": "^15.0.1",
27
+ "@rollup/plugin-typescript": "^9.0.2",
28
+ "@types/isomorphic-form-data": "^2.0.1",
29
+ "@types/node": "^18.11.6",
30
+ "get-file-object-from-local-path": "^1.0.2",
31
+ "rollup": "^3.2.5",
32
+ "rollup-plugin-dts": "^5.0.0",
33
+ "rollup-plugin-polyfill-node": "^0.11.0",
34
+ "typedoc": "^0.23.15",
35
+ "typescript": "^4.8.4"
36
+ },
37
+ "dependencies": {
38
+ "axios": "^0.27.2",
39
+ "buffer": "^6.0.3",
40
+ "fetch-blob": "^3.2.0",
41
+ "isomorphic-form-data": "^2.0.0",
42
+ "tslib": "^2.4.0"
43
+ }
44
+ }
@@ -0,0 +1,15 @@
1
+ import AuthRoutes from "../routes/AuthRoute";
2
+ import Requests from "../util/Requests";
3
+
4
+ class Auth {
5
+
6
+ public static login(login: string, password: string) {
7
+ return Requests.post(AuthRoutes.routes.login.url, {email : login, password: password});
8
+ }
9
+
10
+ public static register(data : object) {
11
+ return Requests.processRoute(AuthRoutes.routes.register, data);
12
+ }
13
+ }
14
+
15
+ export default Auth;
@@ -0,0 +1,34 @@
1
+ import CompetitionRoutes from "../routes/CompetitionRoute";
2
+ import Requests from "../util/Requests";
3
+
4
+ class Competitions {
5
+
6
+ public static list() {
7
+ return Requests.processRoute(CompetitionRoutes.routes.list);
8
+ }
9
+
10
+ public static create(data : object) {
11
+
12
+ return Requests.processRoute(CompetitionRoutes.routes.create, data);
13
+ }
14
+
15
+ public static update(competition_id : string, data : object) {
16
+
17
+ return Requests.processRoute(CompetitionRoutes.routes.create, data, {competition_id : competition_id});
18
+ }
19
+
20
+ public static view(competition_id : string) {
21
+
22
+ return Requests.processRoute(CompetitionRoutes.routes.view, {}, {competition_id : competition_id});
23
+ }
24
+
25
+ public static delete(competition_id : string) {
26
+
27
+ return Requests.processRoute(CompetitionRoutes.routes.delete, {}, {competition_id : competition_id});
28
+ }
29
+
30
+
31
+
32
+ }
33
+
34
+ export default Competitions;
@@ -0,0 +1,5 @@
1
+ import Auth from "./Auth";
2
+ import Competitions from "./Competitions";
3
+
4
+ export {Auth};
5
+ export {Competitions};
@@ -0,0 +1,37 @@
1
+ import Requests from "../util/Requests";
2
+
3
+ /**
4
+ * Config
5
+ *
6
+ * The configuration class will hold the configuration information used when accessing the
7
+ * API.
8
+ */
9
+ class Config {
10
+ //The base url of the API, ie: http://api.example.com/v1/
11
+ baseUrl: string;
12
+
13
+ //The JWT token used to access the api.
14
+ authToken: string;
15
+
16
+ constructor(baseUrl: string, authToken: string) {
17
+ this.baseUrl = baseUrl;
18
+ this.authToken = authToken;
19
+
20
+ Requests.setConfig(this);
21
+ }
22
+
23
+ setBaseUrl(baseUrl: string) {
24
+ this.baseUrl = baseUrl;
25
+
26
+ Requests.setBaseUrl(baseUrl);
27
+ }
28
+
29
+ setAuthToken(authToken: string) {
30
+ this.authToken = authToken;
31
+
32
+ Requests.setAuthToken(authToken);
33
+ }
34
+
35
+ }
36
+
37
+ export default Config;
@@ -0,0 +1,8 @@
1
+ const HTTP_METHODS = {
2
+ GET: 'GET',
3
+ POST: 'POST',
4
+ PUT: 'PUT',
5
+ DELETE: 'DELETE',
6
+ } as const;
7
+
8
+ export default HTTP_METHODS;
@@ -0,0 +1,397 @@
1
+
2
+ /**
3
+ * The routes to the endpoints.
4
+ */
5
+
6
+ const api_routes = {
7
+ //Authentication Routes
8
+ auth_login : {
9
+ route : '/auth/login',
10
+ method : 'POST',
11
+ },
12
+ auth_register : {
13
+ route :'/auth/register',
14
+ method : 'POST'
15
+ },
16
+ auth_one_time_login : {
17
+ route :'/auth/oneTimeLoginWithToken',
18
+ method : 'POST'
19
+ },
20
+ auth_forgot_password : {
21
+ route :'/auth/forgotpassword',
22
+ method : 'POST'
23
+ },
24
+ auth_reset_password : {
25
+ route :'/auth/resetpassword',
26
+ method : 'POST'
27
+ },
28
+
29
+ //Competitions
30
+ competitions_list : {
31
+ route: '/competitions',
32
+ method : 'GET'
33
+ },
34
+ competitions_create : {
35
+ route : '/competitions',
36
+ method : 'POST'
37
+ },
38
+ competitions_view : {
39
+ route : '/competitions/{competition_id}',
40
+ method : 'GET'
41
+ },
42
+ competitions_update : {
43
+ route : '/competitions/{competition_id}',
44
+ method : 'PUT'
45
+ },
46
+ competitions_delete : {
47
+ route : '/competitions/{competition_id}',
48
+ method : 'DELETE'
49
+ },
50
+ competitions_upload_main_image : {
51
+ route : '/competitions/{competition_id}/uploadMainImage',
52
+ method : 'POST'
53
+ },
54
+ competitions_upload_main_banner : {
55
+ route : '/competitions/{competition_id}/uploadBannerImage',
56
+ method : 'POST'
57
+ },
58
+ competitions_register_team : {
59
+ route : '/competitions/{competition_id}/registerTeam',
60
+ method : 'POST'
61
+ },
62
+ competitions_register_individual : {
63
+ route : '/competitions/{competition_id}/registerUser',
64
+ method : 'POST'
65
+ },
66
+ competitions_rounds_list : {
67
+ route: '/competitions/{competition_id}/rounds',
68
+ method : 'GET'
69
+ },
70
+ competitions_rounds_create : {
71
+ route : '/competitions/{competition_id}/rounds',
72
+ method : 'POST'
73
+ },
74
+ competitions_rounds_view : {
75
+ route : '/competitions/{competition_id}/rounds/{round_id}',
76
+ method : 'GET'
77
+ },
78
+ competitions_rounds_update : {
79
+ route : '/competitions/{competition_id}/rounds/{round_id}',
80
+ method : 'PUT'
81
+ },
82
+ competitions_rounds_delete : {
83
+ route : '/competitions/{competition_id}/rounds/{round_id}',
84
+ method : 'DELETE'
85
+ },
86
+ competitions_teams_list : {
87
+ route: '/competitions/{competition_id}/teams',
88
+ method : 'GET'
89
+ },
90
+ competitions_teams_create : {
91
+ route : '/competitions/{competition_id}/teams',
92
+ method : 'POST'
93
+ },
94
+ competitions_teams_view : {
95
+ route : '/competitions/{competition_id}/teams/{team_id}',
96
+ method : 'GET'
97
+ },
98
+ competitions_teams_update : {
99
+ route : '/competitions/{competition_id}/teams/{team_id}',
100
+ method : 'PUT'
101
+ },
102
+ competitions_teams_delete : {
103
+ route : '/competitions/{competition_id}/teams/{team_id}',
104
+ method : 'DELETE'
105
+ },
106
+ competitions_teams_list : {
107
+ route: '/competitions/{competition_id}/teams',
108
+ method : 'GET'
109
+ },
110
+ competitions_users_create : {
111
+ route : '/competitions/{competition_id}/users',
112
+ method : 'POST'
113
+ },
114
+ competitions_users_view : {
115
+ route : '/competitions/{competition_id}/users/{user_id}',
116
+ method : 'GET'
117
+ },
118
+ competitions_users_update : {
119
+ route : '/competitions/{competition_id}/users/{user_id}',
120
+ method : 'PUT'
121
+ },
122
+ competitions_users_delete : {
123
+ route : '/competitions/{competition_id}/users/{user_id}',
124
+ method : 'DELETE'
125
+ },
126
+ competitions_venues_list : {
127
+ route: '/competitions/{competition_id}/venues',
128
+ method : 'GET'
129
+ },
130
+ competitions_venues_create : {
131
+ route : '/competitions/{competition_id}/venues',
132
+ method : 'POST'
133
+ },
134
+ competitions_venues_view : {
135
+ route : '/competitions/{competition_id}/venues/{venue_id}',
136
+ method : 'GET'
137
+ },
138
+ competitions_venues_update : {
139
+ route : '/competitions/{competition_id}/venues/{venue_id}',
140
+ method : 'PUT'
141
+ },
142
+ competitions_venues_delete : {
143
+ route : '/competitions/{competition_id}/venues/{venue_id}',
144
+ method : 'DELETE'
145
+ },
146
+ competitions_round_brackets_list : {
147
+ route: '/competitions/{competition_id}/rounds/{round_id}/brackets',
148
+ method : 'GET'
149
+ },
150
+ competitions_round_brackets_create : {
151
+ route : '/competitions/{competition_id}/rounds/{round_id}/brackets',
152
+ method : 'POST'
153
+ },
154
+ competitions_round_brackets_view : {
155
+ route : '/competitions/{competition_id}/rounds/{round_id}/brackets/{bracket_id}',
156
+ method : 'GET'
157
+ },
158
+ competitions_round_brackets_update : {
159
+ route : '/competitions/{competition_id}/rounds/{round_id}/brackets/{bracket_id}',
160
+ method : 'PUT'
161
+ },
162
+ competitions_round_brackets_delete : {
163
+ route : '/competitions/{competition_id}/rounds/{round_id}/brackets/{bracket_id}',
164
+ method : 'DELETE'
165
+ },
166
+
167
+
168
+
169
+
170
+
171
+
172
+ //Events
173
+ events_list : {
174
+ route: '/events',
175
+ method : 'GET'
176
+ },
177
+ events_create : {
178
+ route : '/events',
179
+ method : 'POST'
180
+ },
181
+ events_view : {
182
+ route : '/events/{event_id}',
183
+ method : 'GET'
184
+ },
185
+ events_update : {
186
+ route : '/events/{event_id}',
187
+ method : 'PUT'
188
+ },
189
+ events_delete : {
190
+ route : '/events/{event_id}',
191
+ method : 'DELETE'
192
+ },
193
+ events_add_rtmp_source : {
194
+ route : '/events/{event_id}/addRTMPSource',
195
+ method : 'POST'
196
+ },
197
+ events_update_rtmp_source : {
198
+ route : '/events/{event_id}/updateRTMPSource/{stream_id}',
199
+ method : 'PUT'
200
+ },
201
+ events_remove_rtmp_source : {
202
+ route : '/events/{event_id}/removeRTMPSource/{stream_id}',
203
+ method : 'DELETE'
204
+ },
205
+ events_upload_main_image : {
206
+ route : '/events/{event_id}/uploadMainImage',
207
+ method : 'POST'
208
+ },
209
+ events_upload_main_banner : {
210
+ route : '/events/{event_id}/uploadBannerImage',
211
+ method : 'POST'
212
+ },
213
+ events_set_broadcast_mode : {
214
+ route : '/events/{event_id}/enableBroadcastMode',
215
+ method : 'POST'
216
+ },
217
+ events_set_livestream_mode : {
218
+ route : '/events/{event_id}/enableLivestreamMode',
219
+ method : 'POST'
220
+ },
221
+ events_sync_as_live : {
222
+ route : '/events/{event_id}/syncAsLive',
223
+ method : 'POST'
224
+ },
225
+ events_send_invite : {
226
+ route : '/events/{event_id}/sendInvite',
227
+ method : 'POST'
228
+ },
229
+ events_accept_invite : {
230
+ route : '/events/{event_id}/acceptInvite',
231
+ method : 'POST'
232
+ },
233
+ events_send_onscreen_content : {
234
+ route : '/events/{event_id}/sendOnScreenContent',
235
+ method : 'POST'
236
+ },
237
+ events_update_invirtu_event : {
238
+ route : '/events/{event_id}/invirtu',
239
+ method : 'PUT'
240
+ },
241
+ events_add_overlay : {
242
+ route : '/events/{event_id}/addOverlay',
243
+ method : 'POST'
244
+ },
245
+ events_remove_overlay : {
246
+ route : '/events/{event_id}/removeOverlay/{overlay_id}',
247
+ method : 'DELETE'
248
+ },
249
+ events_enable_overlay : {
250
+ route : '/events/{event_id}/enableOverlay/{overlay_id}',
251
+ method : 'POST'
252
+ },
253
+ events_disable_overlay : {
254
+ route : '/events/{event_id}/disableOverlay',
255
+ method : 'POST'
256
+ },
257
+ events_enable_donations : {
258
+ route : '/events/{event_id}/enableDonations',
259
+ method : 'POST'
260
+ },
261
+ events_disable_donations : {
262
+ route : '/events/{event_id}/disableDonations',
263
+ method : 'POST'
264
+ },
265
+
266
+ //Messages
267
+ messages_list : {
268
+ route: '/messages',
269
+ method : 'GET'
270
+ },
271
+ messages_all_conversations : {
272
+ route: '/messages/threads',
273
+ method : 'GET'
274
+ },
275
+ messages_create_thread : {
276
+ route: '/messages/threads',
277
+ method : 'GET'
278
+ },
279
+ messages_send : {
280
+ route: '/messages',
281
+ method : 'POST'
282
+ },
283
+ messages_update : {
284
+ route: '/messages/{message_id}',
285
+ method : 'PUT'
286
+ },
287
+ messages_delete : {
288
+ route: '/messages/{message_id}',
289
+ method : 'DELETE'
290
+ },
291
+
292
+ //Teams
293
+ teams_list : {
294
+ route: '/teams',
295
+ method : 'GET'
296
+ },
297
+ teams_create : {
298
+ route : '/teams',
299
+ method : 'POST'
300
+ },
301
+ teams_view : {
302
+ route : '/teams/{team_id}',
303
+ method : 'GET'
304
+ },
305
+ teams_update : {
306
+ route : '/teams/{team_id}',
307
+ method : 'PUT'
308
+ },
309
+ teams_delete : {
310
+ route : '/teams/{team_id}',
311
+ method : 'DELETE'
312
+ },
313
+ teams_users_create : {
314
+ route : '/teams/{team_id}/users',
315
+ method : 'POST'
316
+ },
317
+ teams_users_view : {
318
+ route : '/teams/{team_id}/users/{user_id}',
319
+ method : 'GET'
320
+ },
321
+ teams_users_update : {
322
+ route : '/teams/{team_id}/users/{user_id}',
323
+ method : 'PUT'
324
+ },
325
+ teams_users_delete : {
326
+ route : '/teams/{team_id}/users/{user_id}',
327
+ method : 'DELETE'
328
+ },
329
+ teams_upload_main_image : {
330
+ route : '/teams/{team_id}/uploadMainImage',
331
+ method : 'POST'
332
+ },
333
+ teams_upload_main_banner : {
334
+ route : '/teams/{team_id}/uploadBannerImage',
335
+ method : 'POST'
336
+ },
337
+
338
+ //Recordings
339
+ recordings_update : {
340
+ route: '/events/{event_id}/recording/{recording_id}',
341
+ method : 'PUT'
342
+ },
343
+
344
+ //Users
345
+ users_list : {
346
+ route: '/users',
347
+ method : 'GET'
348
+ },
349
+ users_update : {
350
+ route: '/users',
351
+ method : 'PUT'
352
+ },
353
+ users_profile : {
354
+ route: '/users/{user_id}/profile',
355
+ method : 'GET'
356
+ },
357
+ users_me : {
358
+ route: '/users/me',
359
+ method : 'GET'
360
+ },
361
+ users_one_time_token : {
362
+ route: '/users/oneTimeToken',
363
+ method : 'GET'
364
+ },
365
+ users_profile : {
366
+ route: '/users/{user_id}/profile',
367
+ method : 'GET'
368
+ },
369
+ users_followers : {
370
+ route: '/users/{user_id}/followers',
371
+ method : 'GET'
372
+ },
373
+ users_following : {
374
+ route: '/users/{user_id}/following',
375
+ method : 'GET'
376
+ },
377
+ users_toggle_follow : {
378
+ route: '/users/{user_id}/follow',
379
+ method : 'POST'
380
+ },
381
+ users_upload_avatar : {
382
+ route: '/users/uploadAvatarImage',
383
+ method : 'POST'
384
+ },
385
+ users_upload_banner : {
386
+ route: '/users/uploadBannerImage',
387
+ method : 'POST'
388
+ },
389
+ users_create_donation_page : {
390
+ route: '/users/createDonationPage',
391
+ method : 'POST'
392
+ },
393
+
394
+
395
+ }
396
+
397
+ export default api_routes;
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+
2
+ //Configuration
3
+ import Config from "./config/Config";
4
+
5
+ //API
6
+ import { Auth } from "./api";
7
+ import { Competitions } from "./api";
8
+
9
+ class Glitch {
10
+
11
+ public static config: typeof Config = Config;
12
+
13
+ public static auth: typeof Auth = Auth;
14
+ public static competitions: typeof Competitions = Competitions;
15
+
16
+
17
+ }
18
+
19
+ export {Glitch};
@@ -0,0 +1,16 @@
1
+ import Route from "./interface";
2
+ import HTTP_METHODS from "../constants/HttpMethods";
3
+
4
+ class AuthRoutes {
5
+
6
+ public static routes: { [key: string]: Route } = {
7
+ login: { url: '/auth/login', method: HTTP_METHODS.POST },
8
+ register: { url: '/auth/register', method: HTTP_METHODS.POST },
9
+ one_time_login : { url: '/auth/oneTimeLoginWithToken', method: HTTP_METHODS.POST },
10
+ forgot_password :{ url: '/auth/forgotpassword', method: HTTP_METHODS.POST },
11
+ reset_password : { url: '/auth/resetpassword', method: HTTP_METHODS.POST },
12
+ };
13
+
14
+ }
15
+
16
+ export default AuthRoutes;