glitch-javascript-sdk 0.1.2 → 0.1.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.
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
@@ -17248,6 +17248,187 @@ var Waitlists = /** @class */ (function () {
17248
17248
  return Waitlists;
17249
17249
  }());
17250
17250
 
17251
+ var Parser = /** @class */ (function () {
17252
+ function Parser() {
17253
+ }
17254
+ /**
17255
+ * To be used inside a catch close, this function will parse out any JSON in a error response from the api.
17256
+ *
17257
+ * @param error The Error object from the catch clause
17258
+ *
17259
+ * @returns Either returns a JSON object or false.
17260
+ */
17261
+ Parser.parseJSONFromError = function (error) {
17262
+ var errorString = error.toString();
17263
+ errorString = errorString.replace('Error: ', '');
17264
+ try {
17265
+ return JSON.parse(errorString);
17266
+ }
17267
+ catch (e) {
17268
+ return false;
17269
+ }
17270
+ };
17271
+ return Parser;
17272
+ }());
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
+
17251
17432
  //Configuration
17252
17433
  var Glitch = /** @class */ (function () {
17253
17434
  function Glitch() {
@@ -17263,6 +17444,13 @@ var Glitch = /** @class */ (function () {
17263
17444
  Teams: Teams,
17264
17445
  Waitlists: Waitlists
17265
17446
  };
17447
+ Glitch.util = {
17448
+ Requests: Requests,
17449
+ Parser: Parser,
17450
+ Session: Session,
17451
+ Storage: Storage,
17452
+ Data: Data,
17453
+ };
17266
17454
  return Glitch;
17267
17455
  }());
17268
17456