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.
package/README.md CHANGED
@@ -1,32 +1,67 @@
1
+
1
2
  # Glitch Javascript SDK
3
+
2
4
  Welcome to the Glitch JavaScript SDK. This SDK is designed to make access Glitch more easy and accessible for developers.
3
5
 
6
+
7
+
4
8
  ### What is Glitch?
5
9
 
10
+
11
+
6
12
  Glitch an open-source live community platform for gaming publishers and esports organizations to establish vibrant gaming communities. While the technology is retro-fitted for gaming, it can be used for various other use cases such as:
7
13
 
14
+
15
+
8
16
  - Live Shopping
17
+
9
18
  - Film Events
19
+
10
20
  - Conference Events
21
+
11
22
  - And more
12
23
 
24
+
25
+
13
26
  ### How To Install
14
27
 
28
+
29
+
15
30
  The library is agnostic to any application that is using Javascript with includes vanilla Javascript, React, Angular, Express and any of the other major frameworks. To install, simply run the following:
16
- ```npm install tbd-command --save```
31
+
32
+ ```npm install glitch-javascript-sdk --save```
33
+
34
+
17
35
 
18
36
  This will add the package to your package.json
19
37
 
38
+
39
+
20
40
  ### How To Use
21
- The API coincendes with the Glitch Backend.
41
+
42
+ The API coincides with the Glitch Backend. You can use the API as such:
43
+
22
44
 
23
45
  ```
24
- import Glitch from tbd-import;
25
46
 
26
- //Set the config
27
- new Glitch.config.Config("http://www.baseUrl.com/", 'some-auth-otken');
47
+ import Glitch from 'glitch-javascript-sdk';
48
+
49
+ //Set the API Url to your backend
50
+ Glitch.config.Config.setBaseUrl("https://api.glitch.local/api/", true);
51
+
52
+ //Set Auth JSON Web Token (if user has loggedin)
53
+ Glitch.config.Config.setAuthToken("some-jwt");
54
+
55
+ //Make API Calls
56
+ Glitch.api.Auth.login("john@example.com", "abc123").then(()=> {
28
57
 
29
- Glitch.Api.Auth.login("john@example.com", "abc123").then(()=> {
30
58
  }).catch(error => {
59
+
31
60
  )
32
- ```
61
+
62
+ ```
63
+
64
+ ## Documentation
65
+ Documentation is produced via typedoc as the code comments are extensive and turned in readable documentation.
66
+
67
+ [https://glitch-gaming-platform.github.io/Glitch-Javascript-SDK/](https://glitch-gaming-platform.github.io/Glitch-Javascript-SDK/)
package/dist/cjs/index.js CHANGED
@@ -17271,6 +17271,244 @@ var Parser = /** @class */ (function () {
17271
17271
  return Parser;
17272
17272
  }());
17273
17273
 
17274
+ var Storage = /** @class */ (function () {
17275
+ function Storage() {
17276
+ }
17277
+ Storage.set = function (key, value) {
17278
+ try {
17279
+ window.localStorage.setItem(key, value);
17280
+ }
17281
+ catch (e) {
17282
+ try {
17283
+ window.sessionStorage.setItem(key, value);
17284
+ }
17285
+ catch (e) {
17286
+ this.setCookie(key, value, 31);
17287
+ //fallback if set cookie fails
17288
+ Storage.data[key] = value;
17289
+ }
17290
+ }
17291
+ };
17292
+ Storage.get = function (key) {
17293
+ try {
17294
+ return window.localStorage.getItem(key);
17295
+ }
17296
+ catch (e) {
17297
+ try {
17298
+ return window.sessionStorage.getItem(key);
17299
+ }
17300
+ catch (e) {
17301
+ var value = Storage.getCookie(key);
17302
+ if (!value) {
17303
+ value = Storage.data[key];
17304
+ }
17305
+ return value;
17306
+ }
17307
+ }
17308
+ };
17309
+ Storage.setAuthToken = function (token) {
17310
+ Storage.set('glitch_auth_token', token);
17311
+ };
17312
+ Storage.getAuthToken = function () {
17313
+ return Storage.get('glitch_auth_token');
17314
+ };
17315
+ Storage.setCookie = function (name, value, days) {
17316
+ var expires = '';
17317
+ if (days) {
17318
+ var date = new Date();
17319
+ date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
17320
+ expires = '; expires=' + date.toUTCString();
17321
+ }
17322
+ //IFrames require HttpyOnly to be false, Chrome require SameSite to be none, and must be secure
17323
+ document.cookie =
17324
+ name +
17325
+ '=' +
17326
+ (value || '') +
17327
+ expires +
17328
+ '; path=/; HttpOnly=false; SameSite=none; Secure';
17329
+ };
17330
+ Storage.getCookie = function (name) {
17331
+ var nameEQ = name + '=';
17332
+ var ca = document.cookie.split(';');
17333
+ for (var i = 0; i < ca.length; i++) {
17334
+ var c = ca[i];
17335
+ while (c.charAt(0) == ' ')
17336
+ c = c.substring(1, c.length);
17337
+ if (c.indexOf(nameEQ) == 0)
17338
+ return c.substring(nameEQ.length, c.length);
17339
+ }
17340
+ return null;
17341
+ };
17342
+ Storage.eraseCookie = function (name) {
17343
+ document.cookie =
17344
+ name +
17345
+ '=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
17346
+ };
17347
+ //Back up data type if no storage is working.
17348
+ Storage.data = {};
17349
+ return Storage;
17350
+ }());
17351
+
17352
+ var Session = /** @class */ (function () {
17353
+ function Session() {
17354
+ }
17355
+ Session.isLoggedIn = function () {
17356
+ var authToken = Storage.getAuthToken();
17357
+ return authToken !== null && authToken !== 'null' && authToken !== undefined;
17358
+ };
17359
+ Session.getAuthToken = function () {
17360
+ return Storage.getAuthToken();
17361
+ };
17362
+ Session.getID = function () {
17363
+ return Storage.get(Session._id_key);
17364
+ };
17365
+ Session.getFirstName = function () {
17366
+ return Storage.get(Session._first_name_key);
17367
+ };
17368
+ Session.getLastName = function () {
17369
+ return Storage.get(Session._last_name_key);
17370
+ };
17371
+ Session.getEmail = function () {
17372
+ return Storage.get(Session._email_key);
17373
+ };
17374
+ Session.end = function () {
17375
+ Storage.setAuthToken(null);
17376
+ Storage.set(Session._id_key, null);
17377
+ Storage.set(Session._first_name_key, null);
17378
+ Storage.set(Session._last_name_key, null);
17379
+ Storage.set(Session._email_key, null);
17380
+ };
17381
+ Session.processAuthentication = function (data) {
17382
+ Storage.setAuthToken(data.token.access_token);
17383
+ Storage.set(Session._id_key, data.id);
17384
+ Storage.set(Session._first_name_key, data.first_name);
17385
+ Storage.set(Session._last_name_key, data.last_name);
17386
+ Storage.set(Session._email_key, data.email);
17387
+ };
17388
+ Session._id_key = 'user_id';
17389
+ Session._first_name_key = 'user_first_name';
17390
+ Session._last_name_key = 'user_last_name';
17391
+ Session._username_key = 'username';
17392
+ Session._email_key = 'email';
17393
+ return Session;
17394
+ }());
17395
+
17396
+ var Data = /** @class */ (function () {
17397
+ function Data() {
17398
+ }
17399
+ Data.dataURItoBlob = function (dataURI) {
17400
+ var byteString = atob(dataURI.split(',')[1]);
17401
+ var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
17402
+ var ab = new ArrayBuffer(byteString.length);
17403
+ var ia = new Uint8Array(ab);
17404
+ for (var i = 0; i < byteString.length; i++) {
17405
+ ia[i] = byteString.charCodeAt(i);
17406
+ }
17407
+ var blob = new Blob([ab], { type: mimeString });
17408
+ return blob;
17409
+ };
17410
+ Data.convertToHHMMSS = function (time) {
17411
+ if (!time) {
17412
+ return time;
17413
+ }
17414
+ var sec_num = parseInt(time, 10);
17415
+ var hours = Math.floor(sec_num / 3600);
17416
+ var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
17417
+ var seconds = sec_num - (hours * 3600) - (minutes * 60);
17418
+ if (hours < 10) {
17419
+ hours = Number('0' + hours);
17420
+ }
17421
+ if (minutes < 10) {
17422
+ minutes = Number('0' + minutes);
17423
+ }
17424
+ if (seconds < 10) {
17425
+ seconds = Number('0' + seconds);
17426
+ }
17427
+ return "".concat(hours, ":").concat(minutes, ":").concat(seconds);
17428
+ };
17429
+ return Data;
17430
+ }());
17431
+
17432
+ var AcceptanceStatus = Object.freeze({
17433
+ UNAPPROVED: 0,
17434
+ APPROVED: 1,
17435
+ IN_REVIEW: 2,
17436
+ PENDING: 3,
17437
+ REQUIRE_MORE_INFORMATION: 4,
17438
+ DENIED: 5,
17439
+ BANNED: 6,
17440
+ PROBATION: 7,
17441
+ });
17442
+
17443
+ var AddressLocationType = Object.freeze({
17444
+ VIRTUAL: 1,
17445
+ IN_PERSON: 2,
17446
+ HYBRID: 3,
17447
+ });
17448
+
17449
+ var CompetitionTypes = Object.freeze({
17450
+ SINGLE_ELIMINATION: 1,
17451
+ DOUBLE_ELIMINATION: 2,
17452
+ MULTILEVEL: 3,
17453
+ STRAIGHT_ROUND_ROBIN: 4,
17454
+ ROUND_ROBIN_DOUBLE_SPLIT: 5,
17455
+ ROUND_ROBIN_TRIPLE_SPLIT: 6,
17456
+ ROUND_ROBIN_QUADRUPLE_SPLIT: 7,
17457
+ SEMI_ROUND_ROBINS: 8,
17458
+ EXTENDED: 9,
17459
+ });
17460
+
17461
+ var Modes;
17462
+ (function (Modes) {
17463
+ Modes[Modes["BROADCAST"] = 0] = "BROADCAST";
17464
+ Modes[Modes["OBS"] = 1] = "OBS";
17465
+ Modes[Modes["RTMP"] = 2] = "RTMP";
17466
+ })(Modes || (Modes = {}));
17467
+
17468
+ var Roles;
17469
+ (function (Roles) {
17470
+ Roles[Roles["NONE"] = 0] = "NONE";
17471
+ Roles[Roles["SUPER_ADMINISTRATOR"] = 1] = "SUPER_ADMINISTRATOR";
17472
+ Roles[Roles["ADMINISTRATOR"] = 2] = "ADMINISTRATOR";
17473
+ Roles[Roles["MODERATOR"] = 3] = "MODERATOR";
17474
+ Roles[Roles["SPEAKER"] = 4] = "SPEAKER";
17475
+ Roles[Roles["SUBSCRIBER"] = 5] = "SUBSCRIBER";
17476
+ Roles[Roles["BLOCKED"] = 6] = "BLOCKED";
17477
+ Roles[Roles["PRODUCER"] = 7] = "PRODUCER";
17478
+ Roles[Roles["PARTICIPANT"] = 8] = "PARTICIPANT";
17479
+ })(Roles || (Roles = {}));
17480
+
17481
+ var TeamJoinProcess;
17482
+ (function (TeamJoinProcess) {
17483
+ TeamJoinProcess[TeamJoinProcess["ANYONE"] = 1] = "ANYONE";
17484
+ TeamJoinProcess[TeamJoinProcess["INVITE"] = 2] = "INVITE";
17485
+ TeamJoinProcess[TeamJoinProcess["APPROVAL"] = 3] = "APPROVAL";
17486
+ })(TeamJoinProcess || (TeamJoinProcess = {}));
17487
+
17488
+ var TicketTypes;
17489
+ (function (TicketTypes) {
17490
+ TicketTypes[TicketTypes["PAID"] = 1] = "PAID";
17491
+ TicketTypes[TicketTypes["FREE"] = 2] = "FREE";
17492
+ TicketTypes[TicketTypes["DONATION"] = 3] = "DONATION";
17493
+ })(TicketTypes || (TicketTypes = {}));
17494
+ var TicketTypes$1 = TicketTypes;
17495
+
17496
+ var TicketUsageTypes;
17497
+ (function (TicketUsageTypes) {
17498
+ TicketUsageTypes[TicketUsageTypes["REGULAR"] = 1] = "REGULAR";
17499
+ TicketUsageTypes[TicketUsageTypes["DAY_PASS"] = 2] = "DAY_PASS";
17500
+ TicketUsageTypes[TicketUsageTypes["TRACK_PASS"] = 3] = "TRACK_PASS";
17501
+ TicketUsageTypes[TicketUsageTypes["WHOLE_EVENT_PASS"] = 4] = "WHOLE_EVENT_PASS";
17502
+ })(TicketUsageTypes || (TicketUsageTypes = {}));
17503
+
17504
+ var TicketVisibility;
17505
+ (function (TicketVisibility) {
17506
+ TicketVisibility[TicketVisibility["VISIBLE"] = 1] = "VISIBLE";
17507
+ TicketVisibility[TicketVisibility["HIDDEN"] = 2] = "HIDDEN";
17508
+ TicketVisibility[TicketVisibility["HIDDEN_WHEN_NO_SALE"] = 3] = "HIDDEN_WHEN_NO_SALE";
17509
+ TicketVisibility[TicketVisibility["SCHEDULED"] = 4] = "SCHEDULED";
17510
+ })(TicketVisibility || (TicketVisibility = {}));
17511
+
17274
17512
  //Configuration
17275
17513
  var Glitch = /** @class */ (function () {
17276
17514
  function Glitch() {
@@ -17288,7 +17526,21 @@ var Glitch = /** @class */ (function () {
17288
17526
  };
17289
17527
  Glitch.util = {
17290
17528
  Requests: Requests,
17291
- Parser: Parser
17529
+ Parser: Parser,
17530
+ Session: Session,
17531
+ Storage: Storage,
17532
+ Data: Data,
17533
+ };
17534
+ Glitch.constants = {
17535
+ AcceptanceStatus: AcceptanceStatus,
17536
+ AddressLocationType: AddressLocationType,
17537
+ CompetitionTypes: CompetitionTypes,
17538
+ Modes: Modes,
17539
+ Roles: Roles,
17540
+ TeamJoinProcess: TeamJoinProcess,
17541
+ TicketTypes: TicketTypes$1,
17542
+ TicketUsageTypes: TicketUsageTypes,
17543
+ TicketVisibility: TicketVisibility
17292
17544
  };
17293
17545
  return Glitch;
17294
17546
  }());