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 +42 -7
- package/dist/cjs/index.js +188 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +14 -2
- package/dist/esm/index.js +188 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/util/Data.d.ts +5 -0
- package/dist/esm/util/Parser.d.ts +11 -0
- package/dist/esm/util/Session.d.ts +24 -0
- package/dist/esm/util/Storage.d.ts +11 -0
- package/dist/index.d.ts +106 -0
- package/package.json +1 -1
- package/src/index.ts +16 -2
- package/src/util/Data.ts +41 -0
- package/src/util/Parser.ts +24 -0
- package/src/util/Session.ts +53 -0
- package/src/util/Storage.ts +85 -0
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { Config } from "./config";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
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
|
+
import Requests from "./util/Requests";
|
|
9
|
+
import Parser from "./util/Parser";
|
|
10
|
+
import Session from "./util/Session";
|
|
11
|
+
import Storage from "./util/Storage";
|
|
12
|
+
import Data from './util/Data';
|
|
8
13
|
declare class Glitch {
|
|
9
14
|
static config: {
|
|
10
15
|
Config: typeof Config;
|
|
@@ -17,5 +22,12 @@ declare class Glitch {
|
|
|
17
22
|
Teams: typeof Teams;
|
|
18
23
|
Waitlists: typeof Waitlists;
|
|
19
24
|
};
|
|
25
|
+
static util: {
|
|
26
|
+
Requests: typeof Requests;
|
|
27
|
+
Parser: typeof Parser;
|
|
28
|
+
Session: typeof Session;
|
|
29
|
+
Storage: typeof Storage;
|
|
30
|
+
Data: typeof Data;
|
|
31
|
+
};
|
|
20
32
|
}
|
|
21
33
|
export default Glitch;
|
package/dist/esm/index.js
CHANGED
|
@@ -31470,6 +31470,187 @@ var Waitlists = /** @class */ (function () {
|
|
|
31470
31470
|
return Waitlists;
|
|
31471
31471
|
}());
|
|
31472
31472
|
|
|
31473
|
+
var Parser = /** @class */ (function () {
|
|
31474
|
+
function Parser() {
|
|
31475
|
+
}
|
|
31476
|
+
/**
|
|
31477
|
+
* To be used inside a catch close, this function will parse out any JSON in a error response from the api.
|
|
31478
|
+
*
|
|
31479
|
+
* @param error The Error object from the catch clause
|
|
31480
|
+
*
|
|
31481
|
+
* @returns Either returns a JSON object or false.
|
|
31482
|
+
*/
|
|
31483
|
+
Parser.parseJSONFromError = function (error) {
|
|
31484
|
+
var errorString = error.toString();
|
|
31485
|
+
errorString = errorString.replace('Error: ', '');
|
|
31486
|
+
try {
|
|
31487
|
+
return JSON.parse(errorString);
|
|
31488
|
+
}
|
|
31489
|
+
catch (e) {
|
|
31490
|
+
return false;
|
|
31491
|
+
}
|
|
31492
|
+
};
|
|
31493
|
+
return Parser;
|
|
31494
|
+
}());
|
|
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
|
+
|
|
31473
31654
|
//Configuration
|
|
31474
31655
|
var Glitch = /** @class */ (function () {
|
|
31475
31656
|
function Glitch() {
|
|
@@ -31485,6 +31666,13 @@ var Glitch = /** @class */ (function () {
|
|
|
31485
31666
|
Teams: Teams,
|
|
31486
31667
|
Waitlists: Waitlists
|
|
31487
31668
|
};
|
|
31669
|
+
Glitch.util = {
|
|
31670
|
+
Requests: Requests,
|
|
31671
|
+
Parser: Parser,
|
|
31672
|
+
Session: Session,
|
|
31673
|
+
Storage: Storage,
|
|
31674
|
+
Data: Data,
|
|
31675
|
+
};
|
|
31488
31676
|
return Glitch;
|
|
31489
31677
|
}());
|
|
31490
31678
|
|