glitch-javascript-sdk 0.3.2 → 0.3.4

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,13 @@
1
+ interface CommunityLabels {
2
+ [key: string]: string;
3
+ }
4
+ declare class LabelManager {
5
+ private static community;
6
+ static initialize(community: CommunityLabels): void;
7
+ private static getLabel;
8
+ static getUserLabel(plural: boolean, capitalize: boolean): string;
9
+ static getCompetitionLabel(plural: boolean, capitalize: boolean): string;
10
+ static getStreamLabel(plural: boolean, capitalize: boolean): string;
11
+ static getPostLabel(plural: boolean, capitalize: boolean): string;
12
+ }
13
+ export default LabelManager;
package/dist/index.d.ts CHANGED
@@ -1412,6 +1412,28 @@ declare class Posts {
1412
1412
  * @returns Promise
1413
1413
  */
1414
1414
  static create<T>(data: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
1415
+ /**
1416
+ * Create a new post with a file. The file should either be an image or video.
1417
+ *
1418
+ * @see https://api.glitch.fun/api/documentation#/Post%20Route/newPostResourceStorage
1419
+ *
1420
+ * @param file The file object to upload.
1421
+ * @param data Any additional data to pass along to the upload.
1422
+ *
1423
+ * @returns promise
1424
+ */
1425
+ static createWithFile<T>(file: File, data?: object): AxiosPromise<Response<T>>;
1426
+ /**
1427
+ * Create a new post with a blob. The blob should either be an image or video.
1428
+ *
1429
+ * @see https://api.glitch.fun/api/documentation#/Post%20Route/newPostResourceStorage
1430
+ *
1431
+ * @param file The blob to upload.
1432
+ * @param data Any additional data to pass along to the upload.
1433
+ *
1434
+ * @returns promise
1435
+ */
1436
+ static createWithBlob<T>(blob: Blob, data?: object): AxiosPromise<Response<T>>;
1415
1437
  /**
1416
1438
  * Update a post.
1417
1439
  *
@@ -1645,6 +1667,19 @@ declare class Data {
1645
1667
  static convertToHHMMSS(time: string | undefined): string | undefined;
1646
1668
  }
1647
1669
 
1670
+ interface CommunityLabels {
1671
+ [key: string]: string;
1672
+ }
1673
+ declare class LabelManager {
1674
+ private static community;
1675
+ static initialize(community: CommunityLabels): void;
1676
+ private static getLabel;
1677
+ static getUserLabel(plural: boolean, capitalize: boolean): string;
1678
+ static getCompetitionLabel(plural: boolean, capitalize: boolean): string;
1679
+ static getStreamLabel(plural: boolean, capitalize: boolean): string;
1680
+ static getPostLabel(plural: boolean, capitalize: boolean): string;
1681
+ }
1682
+
1648
1683
  declare enum Modes {
1649
1684
  BROADCAST = 0,
1650
1685
  OBS = 1,
@@ -1727,6 +1762,7 @@ declare class Glitch {
1727
1762
  Session: typeof Session;
1728
1763
  Storage: typeof Storage;
1729
1764
  Data: typeof Data;
1765
+ LabelManager: typeof LabelManager;
1730
1766
  };
1731
1767
  static constants: {
1732
1768
  AcceptanceStatus: Readonly<{
@@ -1755,7 +1791,23 @@ declare class Glitch {
1755
1791
  SEMI_ROUND_ROBINS: 8;
1756
1792
  EXTENDED: 9;
1757
1793
  }>;
1794
+ ContentStatus: Readonly<{
1795
+ UNAPPROVED: 0;
1796
+ APPROVED: 1;
1797
+ IN_REVIEW: 2;
1798
+ PENDING: 3;
1799
+ FLAGGED: 4;
1800
+ REMOVED: 5;
1801
+ DELETED: 6;
1802
+ }>;
1758
1803
  Modes: typeof Modes;
1804
+ PostTypes: Readonly<{
1805
+ TEXT: "text";
1806
+ LINK: "link";
1807
+ POLL: "poll";
1808
+ IMAGE: "image";
1809
+ VIDEO: "video";
1810
+ }>;
1759
1811
  Roles: typeof Roles;
1760
1812
  TeamJoinProcess: typeof TeamJoinProcess;
1761
1813
  TicketTypes: typeof TicketTypes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glitch-javascript-sdk",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "Javascript SDK for Glitch",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
package/src/api/Posts.ts CHANGED
@@ -30,6 +30,37 @@ class Posts {
30
30
  return Requests.processRoute(PostsRoute.routes.create, data, undefined, params);
31
31
  }
32
32
 
33
+ /**
34
+ * Create a new post with a file. The file should either be an image or video.
35
+ *
36
+ * @see https://api.glitch.fun/api/documentation#/Post%20Route/newPostResourceStorage
37
+ *
38
+ * @param file The file object to upload.
39
+ * @param data Any additional data to pass along to the upload.
40
+ *
41
+ * @returns promise
42
+ */
43
+ public static createWithFile<T>(file : File, data? : object): AxiosPromise<Response<T>> {
44
+
45
+ return Requests.uploadFile(PostsRoute.routes.create.url, 'file', file, data);
46
+ }
47
+
48
+ /**
49
+ * Create a new post with a blob. The blob should either be an image or video.
50
+ *
51
+ * @see https://api.glitch.fun/api/documentation#/Post%20Route/newPostResourceStorage
52
+ *
53
+ * @param file The blob to upload.
54
+ * @param data Any additional data to pass along to the upload.
55
+ *
56
+ * @returns promise
57
+ */
58
+ public static createWithBlob<T>(blob : Blob, data? : object): AxiosPromise<Response<T>> {
59
+
60
+ return Requests.uploadBlob(PostsRoute.routes.create.url, 'file', blob, data);
61
+ }
62
+
63
+
33
64
  /**
34
65
  * Update a post.
35
66
  *
@@ -1,4 +1,5 @@
1
1
  import Community from "../models/community";
2
+ import LabelManager from "../util/LabelManager";
2
3
  import Requests from "../util/Requests";
3
4
 
4
5
  /**
@@ -70,6 +71,8 @@ class Config {
70
71
  Config._community = community;
71
72
 
72
73
  Requests.setCommunityID(community.id);
74
+
75
+ LabelManager.initialize(community);
73
76
  }
74
77
 
75
78
  /**
@@ -0,0 +1,9 @@
1
+ export const ContentStatus = Object.freeze({
2
+ UNAPPROVED : 0,
3
+ APPROVED : 1,
4
+ IN_REVIEW : 2,
5
+ PENDING : 3,
6
+ FLAGGED : 4,
7
+ REMOVED : 5,
8
+ DELETED : 6,
9
+ });
@@ -0,0 +1,7 @@
1
+ export const PostTypes = Object.freeze({
2
+ TEXT: 'text',
3
+ LINK : 'link',
4
+ POLL: 'poll',
5
+ IMAGE: 'image',
6
+ VIDEO: 'video',
7
+ });
package/src/index.ts CHANGED
@@ -18,11 +18,14 @@ import Parser from "./util/Parser";
18
18
  import Session from "./util/Session";
19
19
  import Storage from "./util/Storage";
20
20
  import Data from './util/Data';
21
+ import LabelManager from "./util/LabelManager";
21
22
 
22
23
  import { AcceptanceStatus } from "./constants/AcceptanceStatus";
23
24
  import AddressLocationType from "./constants/AddressLocationType";
25
+ import { ContentStatus } from "./constants/ContentStatus";
24
26
  import { CompetitionTypes } from "./constants/CompetitionTypes";
25
27
  import { Modes } from "./constants/Modes";
28
+ import { PostTypes } from "./constants/PostTypes";
26
29
  import { Roles } from "./constants/Roles";
27
30
  import { TeamJoinProcess } from "./constants/TeamJoinProcess";
28
31
  import TicketTypes from "./constants/TicketTypes";
@@ -54,13 +57,16 @@ class Glitch {
54
57
  Session: Session,
55
58
  Storage : Storage,
56
59
  Data : Data,
60
+ LabelManager : LabelManager,
57
61
  }
58
62
 
59
63
  public static constants = {
60
64
  AcceptanceStatus : AcceptanceStatus,
61
65
  AddressLocationType : AddressLocationType,
62
66
  CompetitionTypes : CompetitionTypes,
67
+ ContentStatus : ContentStatus,
63
68
  Modes : Modes,
69
+ PostTypes : PostTypes,
64
70
  Roles: Roles,
65
71
  TeamJoinProcess : TeamJoinProcess,
66
72
  TicketTypes : TicketTypes,
@@ -0,0 +1,39 @@
1
+ interface CommunityLabels {
2
+ [key: string]: string;
3
+ }
4
+
5
+ class LabelManager {
6
+ private static community: CommunityLabels;
7
+
8
+ static initialize(community: CommunityLabels) {
9
+ LabelManager.community = community;
10
+ }
11
+
12
+ private static getLabel(labelName: string, plural: boolean, capitalize: boolean): string {
13
+ let label = LabelManager.community[labelName + (plural ? "_plural" : "_singular")];
14
+
15
+ if (capitalize) {
16
+ label = label.charAt(0).toUpperCase() + label.slice(1);
17
+ }
18
+
19
+ return label;
20
+ }
21
+
22
+ static getUserLabel(plural: boolean, capitalize: boolean): string {
23
+ return LabelManager.getLabel("label_users", plural, capitalize);
24
+ }
25
+
26
+ static getCompetitionLabel(plural: boolean, capitalize: boolean): string {
27
+ return LabelManager.getLabel("label_competitions", plural, capitalize);
28
+ }
29
+
30
+ static getStreamLabel(plural: boolean, capitalize: boolean): string {
31
+ return LabelManager.getLabel("label_streams", plural, capitalize);
32
+ }
33
+
34
+ static getPostLabel(plural: boolean, capitalize: boolean): string {
35
+ return LabelManager.getLabel("label_posts", plural, capitalize);
36
+ }
37
+ }
38
+
39
+ export default LabelManager;
@@ -1,397 +0,0 @@
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;