glitch-javascript-sdk 0.3.8 → 0.4.0
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/dist/cjs/index.js +177 -86
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/Competitions.d.ts +45 -0
- package/dist/esm/config/Config.d.ts +9 -0
- package/dist/esm/index.js +177 -86
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/util/Storage.d.ts +10 -1
- package/dist/index.d.ts +64 -1
- package/package.json +1 -1
- package/src/api/Competitions.ts +60 -0
- package/src/config/Config.ts +34 -5
- package/src/routes/CompetitionRoute.ts +5 -0
- package/src/util/Storage.ts +79 -85
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
declare class Storage {
|
|
2
|
+
private static rootDomain;
|
|
2
3
|
private static data;
|
|
4
|
+
/**
|
|
5
|
+
* Sets a root level domain so the data can persist across
|
|
6
|
+
* subdomains
|
|
7
|
+
*
|
|
8
|
+
* @param rootDomain
|
|
9
|
+
*/
|
|
10
|
+
static setRootDomain(rootDomain: string): void;
|
|
11
|
+
private static getStorageKey;
|
|
3
12
|
static set(key: string, value: any): void;
|
|
4
13
|
static get(key: string): any;
|
|
5
14
|
static setAuthToken(token: string | null): void;
|
|
6
15
|
static getAuthToken(): string | null;
|
|
16
|
+
static eraseCookie(name: string): void;
|
|
7
17
|
private static setCookie;
|
|
8
18
|
private static getCookie;
|
|
9
|
-
static eraseCookie(name: string): void;
|
|
10
19
|
}
|
|
11
20
|
export default Storage;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare class Config {
|
|
|
10
10
|
private static _baseUrl;
|
|
11
11
|
private static _authToken;
|
|
12
12
|
private static _community;
|
|
13
|
+
private static _rootDomain;
|
|
13
14
|
private static _baseUrlLocked;
|
|
14
15
|
/**
|
|
15
16
|
* Set the configuration
|
|
@@ -37,6 +38,14 @@ declare class Config {
|
|
|
37
38
|
* @param community The object of the community
|
|
38
39
|
*/
|
|
39
40
|
static setCommunity(community: Record<string, any>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Sets the root level domain so data can accessed across
|
|
43
|
+
* multiple subdomains
|
|
44
|
+
*
|
|
45
|
+
* @param domain The domain ie: example.com
|
|
46
|
+
*/
|
|
47
|
+
static setRootDomain(domain: string): void;
|
|
48
|
+
static getRootDomain(): string;
|
|
40
49
|
/**
|
|
41
50
|
* Gets base url
|
|
42
51
|
*/
|
|
@@ -577,6 +586,51 @@ declare class Competitions {
|
|
|
577
586
|
* @returns promise
|
|
578
587
|
*/
|
|
579
588
|
static uploadVenueMainImageBlob<T>(competition_id: string, blob: Blob, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
589
|
+
/**
|
|
590
|
+
* Get a leaderboard by a users points.
|
|
591
|
+
*
|
|
592
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
593
|
+
*
|
|
594
|
+
* @param competition_id
|
|
595
|
+
* @returns promise
|
|
596
|
+
*/
|
|
597
|
+
static userPointsLeaderboard<T>(competition_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
598
|
+
/**
|
|
599
|
+
* Get a leaderboard by a users wins.
|
|
600
|
+
*
|
|
601
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
602
|
+
*
|
|
603
|
+
* @param competition_id
|
|
604
|
+
* @returns promise
|
|
605
|
+
*/
|
|
606
|
+
static userWinsLeaderboard<T>(competition_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
607
|
+
/**
|
|
608
|
+
* Get a leaderboard by a teams points.
|
|
609
|
+
*
|
|
610
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
611
|
+
*
|
|
612
|
+
* @param competition_id
|
|
613
|
+
* @returns promise
|
|
614
|
+
*/
|
|
615
|
+
static teamPointsLeaderboard<T>(competition_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
616
|
+
/**
|
|
617
|
+
* Get a leaderboard by a teams wins.
|
|
618
|
+
*
|
|
619
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
620
|
+
*
|
|
621
|
+
* @param competition_id
|
|
622
|
+
* @returns promise
|
|
623
|
+
*/
|
|
624
|
+
static teamWinsLeaderboard<T>(competition_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
625
|
+
/**
|
|
626
|
+
* Get all leaderboards.
|
|
627
|
+
*
|
|
628
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
629
|
+
*
|
|
630
|
+
* @param competition_id
|
|
631
|
+
* @returns promise
|
|
632
|
+
*/
|
|
633
|
+
static allLeaderboards<T>(competition_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
580
634
|
}
|
|
581
635
|
|
|
582
636
|
declare class Communities {
|
|
@@ -1697,14 +1751,23 @@ declare class Session {
|
|
|
1697
1751
|
}
|
|
1698
1752
|
|
|
1699
1753
|
declare class Storage {
|
|
1754
|
+
private static rootDomain;
|
|
1700
1755
|
private static data;
|
|
1756
|
+
/**
|
|
1757
|
+
* Sets a root level domain so the data can persist across
|
|
1758
|
+
* subdomains
|
|
1759
|
+
*
|
|
1760
|
+
* @param rootDomain
|
|
1761
|
+
*/
|
|
1762
|
+
static setRootDomain(rootDomain: string): void;
|
|
1763
|
+
private static getStorageKey;
|
|
1701
1764
|
static set(key: string, value: any): void;
|
|
1702
1765
|
static get(key: string): any;
|
|
1703
1766
|
static setAuthToken(token: string | null): void;
|
|
1704
1767
|
static getAuthToken(): string | null;
|
|
1768
|
+
static eraseCookie(name: string): void;
|
|
1705
1769
|
private static setCookie;
|
|
1706
1770
|
private static getCookie;
|
|
1707
|
-
static eraseCookie(name: string): void;
|
|
1708
1771
|
}
|
|
1709
1772
|
|
|
1710
1773
|
declare class Data {
|
package/package.json
CHANGED
package/src/api/Competitions.ts
CHANGED
|
@@ -620,6 +620,66 @@ class Competitions {
|
|
|
620
620
|
|
|
621
621
|
return Requests.uploadBlob(url, 'image', blob, data);
|
|
622
622
|
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Get a leaderboard by a users points.
|
|
626
|
+
*
|
|
627
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
628
|
+
*
|
|
629
|
+
* @param competition_id
|
|
630
|
+
* @returns promise
|
|
631
|
+
*/
|
|
632
|
+
public static userPointsLeaderboard<T>(competition_id : string, params?: Record<string, any>): AxiosPromise<Response<T>>{
|
|
633
|
+
return Requests.processRoute(CompetitionRoutes.routes.userPointsLeaderboard, {}, {competition_id : competition_id}, params);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Get a leaderboard by a users wins.
|
|
638
|
+
*
|
|
639
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
640
|
+
*
|
|
641
|
+
* @param competition_id
|
|
642
|
+
* @returns promise
|
|
643
|
+
*/
|
|
644
|
+
public static userWinsLeaderboard<T>(competition_id : string, params?: Record<string, any>): AxiosPromise<Response<T>>{
|
|
645
|
+
return Requests.processRoute(CompetitionRoutes.routes.userWinsLeaderboard, {}, {competition_id : competition_id}, params);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Get a leaderboard by a teams points.
|
|
650
|
+
*
|
|
651
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
652
|
+
*
|
|
653
|
+
* @param competition_id
|
|
654
|
+
* @returns promise
|
|
655
|
+
*/
|
|
656
|
+
public static teamPointsLeaderboard<T>(competition_id : string, params?: Record<string, any>): AxiosPromise<Response<T>>{
|
|
657
|
+
return Requests.processRoute(CompetitionRoutes.routes.teamPointsLeaderboard, {}, {competition_id : competition_id}, params);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Get a leaderboard by a teams wins.
|
|
662
|
+
*
|
|
663
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
664
|
+
*
|
|
665
|
+
* @param competition_id
|
|
666
|
+
* @returns promise
|
|
667
|
+
*/
|
|
668
|
+
public static teamWinsLeaderboard<T>(competition_id : string, params?: Record<string, any>): AxiosPromise<Response<T>>{
|
|
669
|
+
return Requests.processRoute(CompetitionRoutes.routes.teamWinsLeaderboard, {}, {competition_id : competition_id}, params);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Get all leaderboards.
|
|
674
|
+
*
|
|
675
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
676
|
+
*
|
|
677
|
+
* @param competition_id
|
|
678
|
+
* @returns promise
|
|
679
|
+
*/
|
|
680
|
+
public static allLeaderboards<T>(competition_id : string, params?: Record<string, any>): AxiosPromise<Response<T>>{
|
|
681
|
+
return Requests.processRoute(CompetitionRoutes.routes.allLeaderboards, {}, {competition_id : competition_id}, params);
|
|
682
|
+
}
|
|
623
683
|
}
|
|
624
684
|
|
|
625
685
|
export default Competitions;
|
package/src/config/Config.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Community from "../models/community";
|
|
2
2
|
import LabelManager from "../util/LabelManager";
|
|
3
3
|
import Requests from "../util/Requests";
|
|
4
|
+
import Storage from "../util/Storage";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Config
|
|
@@ -13,6 +14,7 @@ class Config {
|
|
|
13
14
|
private static _baseUrl: string;
|
|
14
15
|
private static _authToken: string;
|
|
15
16
|
private static _community: object;
|
|
17
|
+
private static _rootDomain: string;
|
|
16
18
|
|
|
17
19
|
private static _baseUrlLocked: boolean = false;
|
|
18
20
|
|
|
@@ -22,7 +24,7 @@ class Config {
|
|
|
22
24
|
* @param baseUrl The url base endpoint of the api
|
|
23
25
|
* @param authToken The JSON Web Token
|
|
24
26
|
*/
|
|
25
|
-
public static setConfig(baseUrl: string, authToken: string, lock
|
|
27
|
+
public static setConfig(baseUrl: string, authToken: string, lock?: boolean) {
|
|
26
28
|
|
|
27
29
|
this.setBaseUrl(baseUrl, lock);
|
|
28
30
|
|
|
@@ -38,15 +40,15 @@ class Config {
|
|
|
38
40
|
* @param baseUrl The url that connects to the APIs base
|
|
39
41
|
* @param lock If set to true, will lock the baseUrl so it cannot be changed
|
|
40
42
|
*/
|
|
41
|
-
public static setBaseUrl(baseUrl: string, lock
|
|
43
|
+
public static setBaseUrl(baseUrl: string, lock?: boolean) {
|
|
42
44
|
|
|
43
|
-
if(!this._baseUrlLocked) {
|
|
45
|
+
if (!this._baseUrlLocked) {
|
|
44
46
|
Config._baseUrl = baseUrl;
|
|
45
47
|
|
|
46
48
|
Requests.setBaseUrl(baseUrl);
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
if(lock) {
|
|
51
|
+
if (lock) {
|
|
50
52
|
this._baseUrlLocked = true;
|
|
51
53
|
}
|
|
52
54
|
}
|
|
@@ -71,10 +73,37 @@ class Config {
|
|
|
71
73
|
Config._community = community;
|
|
72
74
|
|
|
73
75
|
Requests.setCommunityID(community.id);
|
|
74
|
-
|
|
76
|
+
|
|
75
77
|
LabelManager.initialize(community);
|
|
76
78
|
}
|
|
77
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Sets the root level domain so data can accessed across
|
|
82
|
+
* multiple subdomains
|
|
83
|
+
*
|
|
84
|
+
* @param domain The domain ie: example.com
|
|
85
|
+
*/
|
|
86
|
+
public static setRootDomain(domain: string) {
|
|
87
|
+
|
|
88
|
+
const parts = domain.split('.');
|
|
89
|
+
|
|
90
|
+
if (parts.length > 2) {
|
|
91
|
+
parts.shift();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let formattedDomain = parts.join('.');
|
|
95
|
+
|
|
96
|
+
formattedDomain = formattedDomain.replace(/^\./, '');
|
|
97
|
+
|
|
98
|
+
this._rootDomain = formattedDomain;
|
|
99
|
+
|
|
100
|
+
Storage.setRootDomain(formattedDomain);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public static getRootDomain() {
|
|
104
|
+
return this._rootDomain;
|
|
105
|
+
}
|
|
106
|
+
|
|
78
107
|
/**
|
|
79
108
|
* Gets base url
|
|
80
109
|
*/
|
|
@@ -47,6 +47,11 @@ class CompetitionRoutes {
|
|
|
47
47
|
updateVenue : { url: '/competitions/{competition_id}/venues/{venue_id}', method: HTTP_METHODS.PUT },
|
|
48
48
|
destroyVenue : { url: '/competitions/{competition_id}/venues/{venue_id}', method: HTTP_METHODS.DELETE },
|
|
49
49
|
uploadVenueMainImage : { url: '/competitions/{competition_id}/venues/{venue_id}/uploadMainImage', method: HTTP_METHODS.POST },
|
|
50
|
+
userPointsLeaderboard : { url: '/competitions/{competition_id}/userPointsLeaderboard', method: HTTP_METHODS.GET },
|
|
51
|
+
teamPointsLeaderboard : { url: '/competitions/{competition_id}/teamPointsLeaderboard', method: HTTP_METHODS.GET },
|
|
52
|
+
userWinsLeaderboard : { url: '/competitions/{competition_id}/userWinsLeaderboard', method: HTTP_METHODS.GET },
|
|
53
|
+
teamWinsLeaderboard : { url: '/competitions/{competition_id}/teamWinsLeaderboard', method: HTTP_METHODS.GET },
|
|
54
|
+
allLeaderboards : { url: '/competitions/{competition_id}/allLeaderboards', method: HTTP_METHODS.GET },
|
|
50
55
|
};
|
|
51
56
|
|
|
52
57
|
|
package/src/util/Storage.ts
CHANGED
|
@@ -1,106 +1,100 @@
|
|
|
1
1
|
class Storage {
|
|
2
|
+
private static rootDomain: string = '';
|
|
3
|
+
private static data: { [key: string]: any } = {};
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Sets a root level domain so the data can persist across
|
|
7
|
+
* subdomains
|
|
8
|
+
*
|
|
9
|
+
* @param rootDomain
|
|
10
|
+
*/
|
|
11
|
+
public static setRootDomain(rootDomain: string) {
|
|
12
|
+
Storage.rootDomain = rootDomain;
|
|
13
|
+
}
|
|
6
14
|
|
|
7
|
-
|
|
8
|
-
|
|
15
|
+
private static getStorageKey(key: string): string {
|
|
16
|
+
return Storage.rootDomain ? `${Storage.rootDomain}:${key}` : key;
|
|
17
|
+
}
|
|
9
18
|
|
|
19
|
+
public static set(key: string, value: any) {
|
|
20
|
+
try {
|
|
21
|
+
const serializedValue = JSON.stringify(value);
|
|
22
|
+
window.localStorage.setItem(Storage.getStorageKey(key), serializedValue);
|
|
23
|
+
} catch (e) {
|
|
10
24
|
try {
|
|
11
25
|
const serializedValue = JSON.stringify(value);
|
|
12
|
-
window.
|
|
26
|
+
window.sessionStorage.setItem(Storage.getStorageKey(key), serializedValue);
|
|
13
27
|
} catch (e) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const serializedValue = JSON.stringify(value);
|
|
18
|
-
window.sessionStorage.setItem(key, serializedValue);
|
|
19
|
-
|
|
20
|
-
} catch (e) {
|
|
21
|
-
//fallback
|
|
22
|
-
this.setCookie(key, value, 31);
|
|
23
|
-
Storage.data[key] = value;
|
|
24
|
-
}
|
|
28
|
+
this.setCookie(key, value, 31);
|
|
29
|
+
Storage.data[key] = value;
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
|
-
|
|
28
|
-
public static get(key: string): any {
|
|
29
|
-
try {
|
|
32
|
+
}
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
public static get(key: string): any {
|
|
35
|
+
try {
|
|
36
|
+
const serializedValue = window.localStorage.getItem(Storage.getStorageKey(key));
|
|
37
|
+
if (serializedValue !== null) {
|
|
38
|
+
return JSON.parse(serializedValue);
|
|
39
|
+
}
|
|
40
|
+
} catch (e) {
|
|
41
|
+
try {
|
|
42
|
+
const serializedValue = window.sessionStorage.getItem(Storage.getStorageKey(key));
|
|
33
43
|
if (serializedValue !== null) {
|
|
34
44
|
return JSON.parse(serializedValue);
|
|
35
45
|
}
|
|
36
|
-
|
|
37
46
|
} catch (e) {
|
|
47
|
+
let value = Storage.getCookie(key);
|
|
48
|
+
if (!value) {
|
|
49
|
+
value = Storage.data[key];
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
38
55
|
|
|
39
|
-
|
|
56
|
+
public static setAuthToken(token: string | null) {
|
|
57
|
+
Storage.set('glitch_auth_token', token);
|
|
58
|
+
}
|
|
40
59
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return JSON.parse(serializedValue);
|
|
45
|
-
}
|
|
60
|
+
public static getAuthToken(): string | null {
|
|
61
|
+
return Storage.get('glitch_auth_token');
|
|
62
|
+
}
|
|
46
63
|
|
|
47
|
-
|
|
64
|
+
public static eraseCookie(name: string) {
|
|
65
|
+
document.cookie =
|
|
66
|
+
name +
|
|
67
|
+
'=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
68
|
+
}
|
|
48
69
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return value;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
public static setAuthToken(token: string | null) {
|
|
62
|
-
Storage.set('glitch_auth_token', token);
|
|
70
|
+
private static setCookie(name: string, value: string, days: number) {
|
|
71
|
+
let expires = '';
|
|
72
|
+
if (days) {
|
|
73
|
+
const date = new Date();
|
|
74
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
75
|
+
expires = '; expires=' + date.toUTCString();
|
|
63
76
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
expires +
|
|
83
|
-
'; path=/; HttpOnly=false; SameSite=none; Secure';
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private static getCookie(name: string): string | null {
|
|
87
|
-
const nameEQ = name + '=';
|
|
88
|
-
const ca = document.cookie.split(';');
|
|
89
|
-
for (let i = 0; i < ca.length; i++) {
|
|
90
|
-
let c = ca[i];
|
|
91
|
-
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
|
92
|
-
if (c.indexOf(nameEQ) == 0)
|
|
93
|
-
return c.substring(nameEQ.length, c.length);
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public static eraseCookie(name: string) {
|
|
99
|
-
document.cookie =
|
|
100
|
-
name +
|
|
101
|
-
'=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
77
|
+
|
|
78
|
+
document.cookie =
|
|
79
|
+
name +
|
|
80
|
+
'=' +
|
|
81
|
+
(value || '') +
|
|
82
|
+
expires +
|
|
83
|
+
'; path=/; domain=' +
|
|
84
|
+
Storage.rootDomain +
|
|
85
|
+
'; HttpOnly=false; SameSite=none; Secure';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private static getCookie(name: string): string | null {
|
|
89
|
+
const nameEQ = name + '=';
|
|
90
|
+
const ca = document.cookie.split(';');
|
|
91
|
+
for (let i = 0; i < ca.length; i++) {
|
|
92
|
+
let c = ca[i];
|
|
93
|
+
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
|
94
|
+
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
|
102
95
|
}
|
|
96
|
+
return null;
|
|
103
97
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default Storage;
|