glitch-javascript-sdk 0.1.3 → 0.1.5

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,5 @@
1
+ declare class Data {
2
+ static dataURItoBlob(dataURI: string): Blob;
3
+ static convertToHHMMSS(time: string | undefined): string | undefined;
4
+ }
5
+ export default Data;
@@ -0,0 +1,24 @@
1
+ declare class Session {
2
+ private static _id_key;
3
+ private static _first_name_key;
4
+ private static _last_name_key;
5
+ private static _username_key;
6
+ private static _email_key;
7
+ static isLoggedIn(): boolean;
8
+ static getAuthToken(): string | null;
9
+ static getID(): string | null;
10
+ static getFirstName(): string | null;
11
+ static getLastName(): string | null;
12
+ static getEmail(): string | null;
13
+ static end(): void;
14
+ static processAuthentication(data: {
15
+ token: {
16
+ access_token: string;
17
+ };
18
+ id: string;
19
+ first_name: string;
20
+ last_name: string;
21
+ email: string;
22
+ }): void;
23
+ }
24
+ export default Session;
@@ -0,0 +1,11 @@
1
+ declare class Storage {
2
+ private static data;
3
+ static set(key: string, value: any): void;
4
+ static get(key: string): any;
5
+ static setAuthToken(token: string | null): void;
6
+ static getAuthToken(): string | null;
7
+ private static setCookie;
8
+ private static getCookie;
9
+ static eraseCookie(name: string): void;
10
+ }
11
+ export default Storage;
package/dist/index.d.ts CHANGED
@@ -1188,6 +1188,90 @@ declare class Parser {
1188
1188
  static parseJSONFromError(error: Error): object | boolean;
1189
1189
  }
1190
1190
 
1191
+ declare class Session {
1192
+ private static _id_key;
1193
+ private static _first_name_key;
1194
+ private static _last_name_key;
1195
+ private static _username_key;
1196
+ private static _email_key;
1197
+ static isLoggedIn(): boolean;
1198
+ static getAuthToken(): string | null;
1199
+ static getID(): string | null;
1200
+ static getFirstName(): string | null;
1201
+ static getLastName(): string | null;
1202
+ static getEmail(): string | null;
1203
+ static end(): void;
1204
+ static processAuthentication(data: {
1205
+ token: {
1206
+ access_token: string;
1207
+ };
1208
+ id: string;
1209
+ first_name: string;
1210
+ last_name: string;
1211
+ email: string;
1212
+ }): void;
1213
+ }
1214
+
1215
+ declare class Storage {
1216
+ private static data;
1217
+ static set(key: string, value: any): void;
1218
+ static get(key: string): any;
1219
+ static setAuthToken(token: string | null): void;
1220
+ static getAuthToken(): string | null;
1221
+ private static setCookie;
1222
+ private static getCookie;
1223
+ static eraseCookie(name: string): void;
1224
+ }
1225
+
1226
+ declare class Data {
1227
+ static dataURItoBlob(dataURI: string): Blob;
1228
+ static convertToHHMMSS(time: string | undefined): string | undefined;
1229
+ }
1230
+
1231
+ declare enum Modes {
1232
+ BROADCAST = 0,
1233
+ OBS = 1,
1234
+ RTMP = 2
1235
+ }
1236
+
1237
+ declare enum Roles {
1238
+ NONE = 0,
1239
+ SUPER_ADMINISTRATOR = 1,
1240
+ ADMINISTRATOR = 2,
1241
+ MODERATOR = 3,
1242
+ SPEAKER = 4,
1243
+ SUBSCRIBER = 5,
1244
+ BLOCKED = 6,
1245
+ PRODUCER = 7,
1246
+ PARTICIPANT = 8
1247
+ }
1248
+
1249
+ declare enum TeamJoinProcess {
1250
+ ANYONE = 1,
1251
+ INVITE = 2,
1252
+ APPROVAL = 3
1253
+ }
1254
+
1255
+ declare enum TicketTypes {
1256
+ PAID = 1,
1257
+ FREE = 2,
1258
+ DONATION = 3
1259
+ }
1260
+
1261
+ declare enum TicketUsageTypes {
1262
+ REGULAR = 1,
1263
+ DAY_PASS = 2,
1264
+ TRACK_PASS = 3,
1265
+ WHOLE_EVENT_PASS = 4
1266
+ }
1267
+
1268
+ declare enum TicketVisibility {
1269
+ VISIBLE = 1,
1270
+ HIDDEN = 2,
1271
+ HIDDEN_WHEN_NO_SALE = 3,
1272
+ SCHEDULED = 4
1273
+ }
1274
+
1191
1275
  declare class Glitch {
1192
1276
  static config: {
1193
1277
  Config: typeof Config;
@@ -1203,6 +1287,43 @@ declare class Glitch {
1203
1287
  static util: {
1204
1288
  Requests: typeof Requests;
1205
1289
  Parser: typeof Parser;
1290
+ Session: typeof Session;
1291
+ Storage: typeof Storage;
1292
+ Data: typeof Data;
1293
+ };
1294
+ static constants: {
1295
+ AcceptanceStatus: Readonly<{
1296
+ UNAPPROVED: 0;
1297
+ APPROVED: 1;
1298
+ IN_REVIEW: 2;
1299
+ PENDING: 3;
1300
+ REQUIRE_MORE_INFORMATION: 4;
1301
+ DENIED: 5;
1302
+ BANNED: 6;
1303
+ PROBATION: 7;
1304
+ }>;
1305
+ AddressLocationType: Readonly<{
1306
+ VIRTUAL: 1;
1307
+ IN_PERSON: 2;
1308
+ HYBRID: 3;
1309
+ }>;
1310
+ CompetitionTypes: Readonly<{
1311
+ SINGLE_ELIMINATION: 1;
1312
+ DOUBLE_ELIMINATION: 2;
1313
+ MULTILEVEL: 3;
1314
+ STRAIGHT_ROUND_ROBIN: 4;
1315
+ ROUND_ROBIN_DOUBLE_SPLIT: 5;
1316
+ ROUND_ROBIN_TRIPLE_SPLIT: 6;
1317
+ ROUND_ROBIN_QUADRUPLE_SPLIT: 7;
1318
+ SEMI_ROUND_ROBINS: 8;
1319
+ EXTENDED: 9;
1320
+ }>;
1321
+ Modes: typeof Modes;
1322
+ Roles: typeof Roles;
1323
+ TeamJoinProcess: typeof TeamJoinProcess;
1324
+ TicketTypes: typeof TicketTypes;
1325
+ TicketUsageTypes: typeof TicketUsageTypes;
1326
+ TicketVisibility: typeof TicketVisibility;
1206
1327
  };
1207
1328
  }
1208
1329
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glitch-javascript-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Javascrip SDK for GLitch",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -0,0 +1,10 @@
1
+ export const AcceptanceStatus = Object.freeze({
2
+ UNAPPROVED: 0,
3
+ APPROVED: 1,
4
+ IN_REVIEW: 2,
5
+ PENDING: 3,
6
+ REQUIRE_MORE_INFORMATION: 4,
7
+ DENIED: 5,
8
+ BANNED: 6,
9
+ PROBATION: 7,
10
+ });
@@ -0,0 +1,7 @@
1
+ const AddressLocationType = Object.freeze({
2
+ VIRTUAL: 1,
3
+ IN_PERSON: 2,
4
+ HYBRID: 3,
5
+ });
6
+
7
+ export default AddressLocationType;
@@ -0,0 +1,11 @@
1
+ export const CompetitionTypes = Object.freeze({
2
+ SINGLE_ELIMINATION: 1,
3
+ DOUBLE_ELIMINATION: 2,
4
+ MULTILEVEL: 3,
5
+ STRAIGHT_ROUND_ROBIN: 4,
6
+ ROUND_ROBIN_DOUBLE_SPLIT: 5,
7
+ ROUND_ROBIN_TRIPLE_SPLIT: 6,
8
+ ROUND_ROBIN_QUADRUPLE_SPLIT: 7,
9
+ SEMI_ROUND_ROBINS: 8,
10
+ EXTENDED: 9,
11
+ });
@@ -0,0 +1,5 @@
1
+ export enum Modes {
2
+ BROADCAST = 0,
3
+ OBS = 1,
4
+ RTMP = 2,
5
+ }
@@ -0,0 +1,11 @@
1
+ export enum Roles {
2
+ NONE = 0,
3
+ SUPER_ADMINISTRATOR = 1,
4
+ ADMINISTRATOR = 2,
5
+ MODERATOR = 3,
6
+ SPEAKER = 4,
7
+ SUBSCRIBER = 5,
8
+ BLOCKED = 6,
9
+ PRODUCER = 7,
10
+ PARTICIPANT = 8,
11
+ }
@@ -0,0 +1,5 @@
1
+ export enum TeamJoinProcess {
2
+ ANYONE = 1,
3
+ INVITE = 2,
4
+ APPROVAL = 3,
5
+ }
@@ -0,0 +1,7 @@
1
+ enum TicketTypes {
2
+ PAID = 1,
3
+ FREE = 2,
4
+ DONATION = 3
5
+ }
6
+
7
+ export default TicketTypes;
@@ -0,0 +1,6 @@
1
+ export enum TicketUsageTypes {
2
+ REGULAR = 1,
3
+ DAY_PASS = 2,
4
+ TRACK_PASS = 3,
5
+ WHOLE_EVENT_PASS = 4
6
+ }
@@ -0,0 +1,6 @@
1
+ export enum TicketVisibility {
2
+ VISIBLE = 1,
3
+ HIDDEN = 2,
4
+ HIDDEN_WHEN_NO_SALE = 3,
5
+ SCHEDULED = 4,
6
+ }
package/src/index.ts CHANGED
@@ -3,8 +3,8 @@
3
3
  import { Config } from "./config";
4
4
 
5
5
  //API
6
- import { Auth } from "./api";
7
- import { Competitions } from "./api";
6
+ import Auth from "./api/Auth";
7
+ import Competitions from "./api/Competitions";
8
8
  import { Users } from "./api";
9
9
  import { Events } from "./api";
10
10
  import { Teams } from "./api";
@@ -12,6 +12,19 @@ import { Waitlists } from "./api";
12
12
 
13
13
  import Requests from "./util/Requests";
14
14
  import Parser from "./util/Parser";
15
+ import Session from "./util/Session";
16
+ import Storage from "./util/Storage";
17
+ import Data from './util/Data';
18
+
19
+ import { AcceptanceStatus } from "./constants/AcceptanceStatus";
20
+ import AddressLocationType from "./constants/AddressLocationType";
21
+ import { CompetitionTypes } from "./constants/CompetitionTypes";
22
+ import { Modes } from "./constants/Modes";
23
+ import { Roles } from "./constants/Roles";
24
+ import { TeamJoinProcess } from "./constants/TeamJoinProcess";
25
+ import TicketTypes from "./constants/TicketTypes";
26
+ import { TicketUsageTypes } from "./constants/TicketUsageTypes";
27
+ import { TicketVisibility } from "./constants/TicketVisbility";
15
28
 
16
29
  class Glitch {
17
30
 
@@ -30,7 +43,22 @@ class Glitch {
30
43
 
31
44
  public static util = {
32
45
  Requests : Requests,
33
- Parser : Parser
46
+ Parser : Parser,
47
+ Session: Session,
48
+ Storage : Storage,
49
+ Data : Data,
50
+ }
51
+
52
+ public static constants = {
53
+ AcceptanceStatus : AcceptanceStatus,
54
+ AddressLocationType : AddressLocationType,
55
+ CompetitionTypes : CompetitionTypes,
56
+ Modes : Modes,
57
+ Roles: Roles,
58
+ TeamJoinProcess : TeamJoinProcess,
59
+ TicketTypes : TicketTypes,
60
+ TicketUsageTypes : TicketUsageTypes,
61
+ TicketVisibility : TicketVisibility
34
62
  }
35
63
 
36
64
 
@@ -0,0 +1,41 @@
1
+ class Data {
2
+
3
+ public static dataURItoBlob(dataURI: string): Blob {
4
+ const byteString = atob(dataURI.split(',')[1]);
5
+ const mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
6
+ const ab = new ArrayBuffer(byteString.length);
7
+ const ia = new Uint8Array(ab);
8
+
9
+ for (let i = 0; i < byteString.length; i++) {
10
+ ia[i] = byteString.charCodeAt(i);
11
+ }
12
+
13
+ const blob = new Blob([ab], { type: mimeString });
14
+ return blob;
15
+ }
16
+
17
+ public static convertToHHMMSS(time: string | undefined): string | undefined {
18
+ if (!time) {
19
+ return time;
20
+ }
21
+
22
+ const sec_num = parseInt(time, 10);
23
+ let hours = Math.floor(sec_num / 3600);
24
+ let minutes = Math.floor((sec_num - (hours * 3600)) / 60);
25
+ let seconds = sec_num - (hours * 3600) - (minutes * 60);
26
+
27
+ if (hours < 10) {
28
+ hours = Number('0' + hours);
29
+ }
30
+ if (minutes < 10) {
31
+ minutes = Number('0' + minutes);
32
+ }
33
+ if (seconds < 10) {
34
+ seconds = Number('0' + seconds);
35
+ }
36
+
37
+ return `${hours}:${minutes}:${seconds}`;
38
+ }
39
+ }
40
+
41
+ export default Data;
@@ -0,0 +1,53 @@
1
+ import Storage from "./Storage";
2
+
3
+ class Session {
4
+
5
+ private static _id_key = 'user_id';
6
+ private static _first_name_key = 'user_first_name';
7
+ private static _last_name_key = 'user_last_name';
8
+ private static _username_key = 'username';
9
+ private static _email_key = 'email';
10
+
11
+ public static isLoggedIn(): boolean {
12
+ const authToken = Storage.getAuthToken();
13
+ return authToken !== null && authToken !== 'null' && authToken !== undefined;
14
+ }
15
+
16
+ public static getAuthToken(): string | null {
17
+ return Storage.getAuthToken();
18
+ }
19
+
20
+ public static getID(): string | null {
21
+ return Storage.get(Session._id_key);
22
+ }
23
+
24
+ public static getFirstName(): string | null {
25
+ return Storage.get(Session._first_name_key);
26
+ }
27
+
28
+ public static getLastName(): string | null {
29
+ return Storage.get(Session._last_name_key);
30
+ }
31
+
32
+ public static getEmail(): string | null {
33
+ return Storage.get(Session._email_key);
34
+ }
35
+
36
+ public static end(): void {
37
+ Storage.setAuthToken(null);
38
+ Storage.set(Session._id_key, null);
39
+ Storage.set(Session._first_name_key, null);
40
+ Storage.set(Session._last_name_key, null);
41
+ Storage.set(Session._email_key, null);
42
+ }
43
+
44
+ public static processAuthentication(data: { token: { access_token: string }, id: string, first_name: string, last_name: string, email: string }): void {
45
+ Storage.setAuthToken(data.token.access_token);
46
+ Storage.set(Session._id_key, data.id);
47
+ Storage.set(Session._first_name_key, data.first_name);
48
+ Storage.set(Session._last_name_key, data.last_name);
49
+ Storage.set(Session._email_key, data.email);
50
+ }
51
+ }
52
+
53
+ export default Session;
@@ -0,0 +1,85 @@
1
+ class Storage {
2
+
3
+ //Back up data type if no storage is working.
4
+
5
+ private static data: { [key: string]: any } = {};
6
+
7
+
8
+ public static set(key: string, value: any) {
9
+ try {
10
+ window.localStorage.setItem(key, value);
11
+ } catch (e) {
12
+ try {
13
+ window.sessionStorage.setItem(key, value);
14
+ } catch (e) {
15
+ this.setCookie(key, value, 31);
16
+ //fallback if set cookie fails
17
+ Storage.data[key] = value;
18
+ }
19
+ }
20
+ }
21
+
22
+ public static get(key: string): any {
23
+ try {
24
+ return window.localStorage.getItem(key);
25
+ } catch (e) {
26
+ try {
27
+ return window.sessionStorage.getItem(key);
28
+ } catch (e) {
29
+ let value = Storage.getCookie(key);
30
+
31
+ if (!value) {
32
+ value = Storage.data[key];
33
+ }
34
+
35
+ return value;
36
+ }
37
+ }
38
+ }
39
+
40
+ public static setAuthToken(token: string | null) {
41
+ Storage.set('glitch_auth_token', token);
42
+ }
43
+
44
+ public static getAuthToken(): string | null {
45
+ return Storage.get('glitch_auth_token');
46
+ }
47
+
48
+ private static setCookie(name: string, value: string, days: number) {
49
+ let expires = '';
50
+ if (days) {
51
+ const date = new Date();
52
+ date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
53
+ expires = '; expires=' + date.toUTCString();
54
+ }
55
+
56
+ //IFrames require HttpyOnly to be false, Chrome require SameSite to be none, and must be secure
57
+ document.cookie =
58
+ name +
59
+ '=' +
60
+ (value || '') +
61
+ expires +
62
+ '; path=/; HttpOnly=false; SameSite=none; Secure';
63
+ }
64
+
65
+ private static getCookie(name: string): string | null {
66
+ const nameEQ = name + '=';
67
+ const ca = document.cookie.split(';');
68
+ for (let i = 0; i < ca.length; i++) {
69
+ let c = ca[i];
70
+ while (c.charAt(0) == ' ') c = c.substring(1, c.length);
71
+ if (c.indexOf(nameEQ) == 0)
72
+ return c.substring(nameEQ.length, c.length);
73
+ }
74
+ return null;
75
+ }
76
+
77
+ public static eraseCookie(name: string) {
78
+ document.cookie =
79
+ name +
80
+ '=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
81
+ }
82
+ }
83
+
84
+ export default Storage;
85
+