glitch-javascript-sdk 0.1.3 → 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.
@@ -1,12 +1,15 @@
1
1
  import { Config } from "./config";
2
- import { Auth } from "./api";
3
- import { Competitions } from "./api";
2
+ import Auth from "./api/Auth";
3
+ import Competitions from "./api/Competitions";
4
4
  import { Users } from "./api";
5
5
  import { Events } from "./api";
6
6
  import { Teams } from "./api";
7
7
  import { Waitlists } from "./api";
8
8
  import Requests from "./util/Requests";
9
9
  import Parser from "./util/Parser";
10
+ import Session from "./util/Session";
11
+ import Storage from "./util/Storage";
12
+ import Data from './util/Data';
10
13
  declare class Glitch {
11
14
  static config: {
12
15
  Config: typeof Config;
@@ -22,6 +25,9 @@ declare class Glitch {
22
25
  static util: {
23
26
  Requests: typeof Requests;
24
27
  Parser: typeof Parser;
28
+ Session: typeof Session;
29
+ Storage: typeof Storage;
30
+ Data: typeof Data;
25
31
  };
26
32
  }
27
33
  export default Glitch;
package/dist/esm/index.js CHANGED
@@ -31493,6 +31493,164 @@ var Parser = /** @class */ (function () {
31493
31493
  return Parser;
31494
31494
  }());
31495
31495
 
31496
+ var Storage = /** @class */ (function () {
31497
+ function Storage() {
31498
+ }
31499
+ Storage.set = function (key, value) {
31500
+ try {
31501
+ window.localStorage.setItem(key, value);
31502
+ }
31503
+ catch (e) {
31504
+ try {
31505
+ window.sessionStorage.setItem(key, value);
31506
+ }
31507
+ catch (e) {
31508
+ this.setCookie(key, value, 31);
31509
+ //fallback if set cookie fails
31510
+ Storage.data[key] = value;
31511
+ }
31512
+ }
31513
+ };
31514
+ Storage.get = function (key) {
31515
+ try {
31516
+ return window.localStorage.getItem(key);
31517
+ }
31518
+ catch (e) {
31519
+ try {
31520
+ return window.sessionStorage.getItem(key);
31521
+ }
31522
+ catch (e) {
31523
+ var value = Storage.getCookie(key);
31524
+ if (!value) {
31525
+ value = Storage.data[key];
31526
+ }
31527
+ return value;
31528
+ }
31529
+ }
31530
+ };
31531
+ Storage.setAuthToken = function (token) {
31532
+ Storage.set('glitch_auth_token', token);
31533
+ };
31534
+ Storage.getAuthToken = function () {
31535
+ return Storage.get('glitch_auth_token');
31536
+ };
31537
+ Storage.setCookie = function (name, value, days) {
31538
+ var expires = '';
31539
+ if (days) {
31540
+ var date = new Date();
31541
+ date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
31542
+ expires = '; expires=' + date.toUTCString();
31543
+ }
31544
+ //IFrames require HttpyOnly to be false, Chrome require SameSite to be none, and must be secure
31545
+ document.cookie =
31546
+ name +
31547
+ '=' +
31548
+ (value || '') +
31549
+ expires +
31550
+ '; path=/; HttpOnly=false; SameSite=none; Secure';
31551
+ };
31552
+ Storage.getCookie = function (name) {
31553
+ var nameEQ = name + '=';
31554
+ var ca = document.cookie.split(';');
31555
+ for (var i = 0; i < ca.length; i++) {
31556
+ var c = ca[i];
31557
+ while (c.charAt(0) == ' ')
31558
+ c = c.substring(1, c.length);
31559
+ if (c.indexOf(nameEQ) == 0)
31560
+ return c.substring(nameEQ.length, c.length);
31561
+ }
31562
+ return null;
31563
+ };
31564
+ Storage.eraseCookie = function (name) {
31565
+ document.cookie =
31566
+ name +
31567
+ '=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
31568
+ };
31569
+ //Back up data type if no storage is working.
31570
+ Storage.data = {};
31571
+ return Storage;
31572
+ }());
31573
+
31574
+ var Session = /** @class */ (function () {
31575
+ function Session() {
31576
+ }
31577
+ Session.isLoggedIn = function () {
31578
+ var authToken = Storage.getAuthToken();
31579
+ return authToken !== null && authToken !== 'null' && authToken !== undefined;
31580
+ };
31581
+ Session.getAuthToken = function () {
31582
+ return Storage.getAuthToken();
31583
+ };
31584
+ Session.getID = function () {
31585
+ return Storage.get(Session._id_key);
31586
+ };
31587
+ Session.getFirstName = function () {
31588
+ return Storage.get(Session._first_name_key);
31589
+ };
31590
+ Session.getLastName = function () {
31591
+ return Storage.get(Session._last_name_key);
31592
+ };
31593
+ Session.getEmail = function () {
31594
+ return Storage.get(Session._email_key);
31595
+ };
31596
+ Session.end = function () {
31597
+ Storage.setAuthToken(null);
31598
+ Storage.set(Session._id_key, null);
31599
+ Storage.set(Session._first_name_key, null);
31600
+ Storage.set(Session._last_name_key, null);
31601
+ Storage.set(Session._email_key, null);
31602
+ };
31603
+ Session.processAuthentication = function (data) {
31604
+ Storage.setAuthToken(data.token.access_token);
31605
+ Storage.set(Session._id_key, data.id);
31606
+ Storage.set(Session._first_name_key, data.first_name);
31607
+ Storage.set(Session._last_name_key, data.last_name);
31608
+ Storage.set(Session._email_key, data.email);
31609
+ };
31610
+ Session._id_key = 'user_id';
31611
+ Session._first_name_key = 'user_first_name';
31612
+ Session._last_name_key = 'user_last_name';
31613
+ Session._username_key = 'username';
31614
+ Session._email_key = 'email';
31615
+ return Session;
31616
+ }());
31617
+
31618
+ var Data = /** @class */ (function () {
31619
+ function Data() {
31620
+ }
31621
+ Data.dataURItoBlob = function (dataURI) {
31622
+ var byteString = atob(dataURI.split(',')[1]);
31623
+ var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
31624
+ var ab = new ArrayBuffer(byteString.length);
31625
+ var ia = new Uint8Array(ab);
31626
+ for (var i = 0; i < byteString.length; i++) {
31627
+ ia[i] = byteString.charCodeAt(i);
31628
+ }
31629
+ var blob = new Blob([ab], { type: mimeString });
31630
+ return blob;
31631
+ };
31632
+ Data.convertToHHMMSS = function (time) {
31633
+ if (!time) {
31634
+ return time;
31635
+ }
31636
+ var sec_num = parseInt(time, 10);
31637
+ var hours = Math.floor(sec_num / 3600);
31638
+ var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
31639
+ var seconds = sec_num - (hours * 3600) - (minutes * 60);
31640
+ if (hours < 10) {
31641
+ hours = Number('0' + hours);
31642
+ }
31643
+ if (minutes < 10) {
31644
+ minutes = Number('0' + minutes);
31645
+ }
31646
+ if (seconds < 10) {
31647
+ seconds = Number('0' + seconds);
31648
+ }
31649
+ return "".concat(hours, ":").concat(minutes, ":").concat(seconds);
31650
+ };
31651
+ return Data;
31652
+ }());
31653
+
31496
31654
  //Configuration
31497
31655
  var Glitch = /** @class */ (function () {
31498
31656
  function Glitch() {
@@ -31510,7 +31668,10 @@ var Glitch = /** @class */ (function () {
31510
31668
  };
31511
31669
  Glitch.util = {
31512
31670
  Requests: Requests,
31513
- Parser: Parser
31671
+ Parser: Parser,
31672
+ Session: Session,
31673
+ Storage: Storage,
31674
+ Data: Data,
31514
31675
  };
31515
31676
  return Glitch;
31516
31677
  }());