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
package/dist/cjs/index.js
CHANGED
|
@@ -15855,6 +15855,104 @@ var Requests = /** @class */ (function () {
|
|
|
15855
15855
|
return Requests;
|
|
15856
15856
|
}());
|
|
15857
15857
|
|
|
15858
|
+
var Storage = /** @class */ (function () {
|
|
15859
|
+
function Storage() {
|
|
15860
|
+
}
|
|
15861
|
+
/**
|
|
15862
|
+
* Sets a root level domain so the data can persist across
|
|
15863
|
+
* subdomains
|
|
15864
|
+
*
|
|
15865
|
+
* @param rootDomain
|
|
15866
|
+
*/
|
|
15867
|
+
Storage.setRootDomain = function (rootDomain) {
|
|
15868
|
+
Storage.rootDomain = rootDomain;
|
|
15869
|
+
};
|
|
15870
|
+
Storage.getStorageKey = function (key) {
|
|
15871
|
+
return Storage.rootDomain ? "".concat(Storage.rootDomain, ":").concat(key) : key;
|
|
15872
|
+
};
|
|
15873
|
+
Storage.set = function (key, value) {
|
|
15874
|
+
try {
|
|
15875
|
+
var serializedValue = JSON.stringify(value);
|
|
15876
|
+
window.localStorage.setItem(Storage.getStorageKey(key), serializedValue);
|
|
15877
|
+
}
|
|
15878
|
+
catch (e) {
|
|
15879
|
+
try {
|
|
15880
|
+
var serializedValue = JSON.stringify(value);
|
|
15881
|
+
window.sessionStorage.setItem(Storage.getStorageKey(key), serializedValue);
|
|
15882
|
+
}
|
|
15883
|
+
catch (e) {
|
|
15884
|
+
this.setCookie(key, value, 31);
|
|
15885
|
+
Storage.data[key] = value;
|
|
15886
|
+
}
|
|
15887
|
+
}
|
|
15888
|
+
};
|
|
15889
|
+
Storage.get = function (key) {
|
|
15890
|
+
try {
|
|
15891
|
+
var serializedValue = window.localStorage.getItem(Storage.getStorageKey(key));
|
|
15892
|
+
if (serializedValue !== null) {
|
|
15893
|
+
return JSON.parse(serializedValue);
|
|
15894
|
+
}
|
|
15895
|
+
}
|
|
15896
|
+
catch (e) {
|
|
15897
|
+
try {
|
|
15898
|
+
var serializedValue = window.sessionStorage.getItem(Storage.getStorageKey(key));
|
|
15899
|
+
if (serializedValue !== null) {
|
|
15900
|
+
return JSON.parse(serializedValue);
|
|
15901
|
+
}
|
|
15902
|
+
}
|
|
15903
|
+
catch (e) {
|
|
15904
|
+
var value = Storage.getCookie(key);
|
|
15905
|
+
if (!value) {
|
|
15906
|
+
value = Storage.data[key];
|
|
15907
|
+
}
|
|
15908
|
+
return value;
|
|
15909
|
+
}
|
|
15910
|
+
}
|
|
15911
|
+
};
|
|
15912
|
+
Storage.setAuthToken = function (token) {
|
|
15913
|
+
Storage.set('glitch_auth_token', token);
|
|
15914
|
+
};
|
|
15915
|
+
Storage.getAuthToken = function () {
|
|
15916
|
+
return Storage.get('glitch_auth_token');
|
|
15917
|
+
};
|
|
15918
|
+
Storage.eraseCookie = function (name) {
|
|
15919
|
+
document.cookie =
|
|
15920
|
+
name +
|
|
15921
|
+
'=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
15922
|
+
};
|
|
15923
|
+
Storage.setCookie = function (name, value, days) {
|
|
15924
|
+
var expires = '';
|
|
15925
|
+
if (days) {
|
|
15926
|
+
var date = new Date();
|
|
15927
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
15928
|
+
expires = '; expires=' + date.toUTCString();
|
|
15929
|
+
}
|
|
15930
|
+
document.cookie =
|
|
15931
|
+
name +
|
|
15932
|
+
'=' +
|
|
15933
|
+
(value || '') +
|
|
15934
|
+
expires +
|
|
15935
|
+
'; path=/; domain=' +
|
|
15936
|
+
Storage.rootDomain +
|
|
15937
|
+
'; HttpOnly=false; SameSite=none; Secure';
|
|
15938
|
+
};
|
|
15939
|
+
Storage.getCookie = function (name) {
|
|
15940
|
+
var nameEQ = name + '=';
|
|
15941
|
+
var ca = document.cookie.split(';');
|
|
15942
|
+
for (var i = 0; i < ca.length; i++) {
|
|
15943
|
+
var c = ca[i];
|
|
15944
|
+
while (c.charAt(0) == ' ')
|
|
15945
|
+
c = c.substring(1, c.length);
|
|
15946
|
+
if (c.indexOf(nameEQ) == 0)
|
|
15947
|
+
return c.substring(nameEQ.length, c.length);
|
|
15948
|
+
}
|
|
15949
|
+
return null;
|
|
15950
|
+
};
|
|
15951
|
+
Storage.rootDomain = '';
|
|
15952
|
+
Storage.data = {};
|
|
15953
|
+
return Storage;
|
|
15954
|
+
}());
|
|
15955
|
+
|
|
15858
15956
|
/**
|
|
15859
15957
|
* Config
|
|
15860
15958
|
*
|
|
@@ -15910,6 +16008,25 @@ var Config = /** @class */ (function () {
|
|
|
15910
16008
|
Requests.setCommunityID(community.id);
|
|
15911
16009
|
LabelManager.initialize(community);
|
|
15912
16010
|
};
|
|
16011
|
+
/**
|
|
16012
|
+
* Sets the root level domain so data can accessed across
|
|
16013
|
+
* multiple subdomains
|
|
16014
|
+
*
|
|
16015
|
+
* @param domain The domain ie: example.com
|
|
16016
|
+
*/
|
|
16017
|
+
Config.setRootDomain = function (domain) {
|
|
16018
|
+
var parts = domain.split('.');
|
|
16019
|
+
if (parts.length > 2) {
|
|
16020
|
+
parts.shift();
|
|
16021
|
+
}
|
|
16022
|
+
var formattedDomain = parts.join('.');
|
|
16023
|
+
formattedDomain = formattedDomain.replace(/^\./, '');
|
|
16024
|
+
this._rootDomain = formattedDomain;
|
|
16025
|
+
Storage.setRootDomain(formattedDomain);
|
|
16026
|
+
};
|
|
16027
|
+
Config.getRootDomain = function () {
|
|
16028
|
+
return this._rootDomain;
|
|
16029
|
+
};
|
|
15913
16030
|
Object.defineProperty(Config, "baseUrl", {
|
|
15914
16031
|
/**
|
|
15915
16032
|
* Gets base url
|
|
@@ -16082,6 +16199,11 @@ var CompetitionRoutes = /** @class */ (function () {
|
|
|
16082
16199
|
updateVenue: { url: '/competitions/{competition_id}/venues/{venue_id}', method: HTTP_METHODS.PUT },
|
|
16083
16200
|
destroyVenue: { url: '/competitions/{competition_id}/venues/{venue_id}', method: HTTP_METHODS.DELETE },
|
|
16084
16201
|
uploadVenueMainImage: { url: '/competitions/{competition_id}/venues/{venue_id}/uploadMainImage', method: HTTP_METHODS.POST },
|
|
16202
|
+
userPointsLeaderboard: { url: '/competitions/{competition_id}/userPointsLeaderboard', method: HTTP_METHODS.GET },
|
|
16203
|
+
teamPointsLeaderboard: { url: '/competitions/{competition_id}/teamPointsLeaderboard', method: HTTP_METHODS.GET },
|
|
16204
|
+
userWinsLeaderboard: { url: '/competitions/{competition_id}/userWinsLeaderboard', method: HTTP_METHODS.GET },
|
|
16205
|
+
teamWinsLeaderboard: { url: '/competitions/{competition_id}/teamWinsLeaderboard', method: HTTP_METHODS.GET },
|
|
16206
|
+
allLeaderboards: { url: '/competitions/{competition_id}/allLeaderboards', method: HTTP_METHODS.GET },
|
|
16085
16207
|
};
|
|
16086
16208
|
return CompetitionRoutes;
|
|
16087
16209
|
}());
|
|
@@ -16643,6 +16765,61 @@ var Competitions = /** @class */ (function () {
|
|
|
16643
16765
|
var url = CompetitionRoutes.routes.uploadVenueMainImage.url.replace('{competition_id}', competition_id);
|
|
16644
16766
|
return Requests.uploadBlob(url, 'image', blob, data);
|
|
16645
16767
|
};
|
|
16768
|
+
/**
|
|
16769
|
+
* Get a leaderboard by a users points.
|
|
16770
|
+
*
|
|
16771
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
16772
|
+
*
|
|
16773
|
+
* @param competition_id
|
|
16774
|
+
* @returns promise
|
|
16775
|
+
*/
|
|
16776
|
+
Competitions.userPointsLeaderboard = function (competition_id, params) {
|
|
16777
|
+
return Requests.processRoute(CompetitionRoutes.routes.userPointsLeaderboard, {}, { competition_id: competition_id }, params);
|
|
16778
|
+
};
|
|
16779
|
+
/**
|
|
16780
|
+
* Get a leaderboard by a users wins.
|
|
16781
|
+
*
|
|
16782
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
16783
|
+
*
|
|
16784
|
+
* @param competition_id
|
|
16785
|
+
* @returns promise
|
|
16786
|
+
*/
|
|
16787
|
+
Competitions.userWinsLeaderboard = function (competition_id, params) {
|
|
16788
|
+
return Requests.processRoute(CompetitionRoutes.routes.userWinsLeaderboard, {}, { competition_id: competition_id }, params);
|
|
16789
|
+
};
|
|
16790
|
+
/**
|
|
16791
|
+
* Get a leaderboard by a teams points.
|
|
16792
|
+
*
|
|
16793
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
16794
|
+
*
|
|
16795
|
+
* @param competition_id
|
|
16796
|
+
* @returns promise
|
|
16797
|
+
*/
|
|
16798
|
+
Competitions.teamPointsLeaderboard = function (competition_id, params) {
|
|
16799
|
+
return Requests.processRoute(CompetitionRoutes.routes.teamPointsLeaderboard, {}, { competition_id: competition_id }, params);
|
|
16800
|
+
};
|
|
16801
|
+
/**
|
|
16802
|
+
* Get a leaderboard by a teams wins.
|
|
16803
|
+
*
|
|
16804
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
16805
|
+
*
|
|
16806
|
+
* @param competition_id
|
|
16807
|
+
* @returns promise
|
|
16808
|
+
*/
|
|
16809
|
+
Competitions.teamWinsLeaderboard = function (competition_id, params) {
|
|
16810
|
+
return Requests.processRoute(CompetitionRoutes.routes.teamWinsLeaderboard, {}, { competition_id: competition_id }, params);
|
|
16811
|
+
};
|
|
16812
|
+
/**
|
|
16813
|
+
* Get all leaderboards.
|
|
16814
|
+
*
|
|
16815
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
16816
|
+
*
|
|
16817
|
+
* @param competition_id
|
|
16818
|
+
* @returns promise
|
|
16819
|
+
*/
|
|
16820
|
+
Competitions.allLeaderboards = function (competition_id, params) {
|
|
16821
|
+
return Requests.processRoute(CompetitionRoutes.routes.allLeaderboards, {}, { competition_id: competition_id }, params);
|
|
16822
|
+
};
|
|
16646
16823
|
return Competitions;
|
|
16647
16824
|
}());
|
|
16648
16825
|
|
|
@@ -18097,92 +18274,6 @@ var Parser = /** @class */ (function () {
|
|
|
18097
18274
|
return Parser;
|
|
18098
18275
|
}());
|
|
18099
18276
|
|
|
18100
|
-
var Storage = /** @class */ (function () {
|
|
18101
|
-
function Storage() {
|
|
18102
|
-
}
|
|
18103
|
-
Storage.set = function (key, value) {
|
|
18104
|
-
try {
|
|
18105
|
-
var serializedValue = JSON.stringify(value);
|
|
18106
|
-
window.localStorage.setItem(key, serializedValue);
|
|
18107
|
-
}
|
|
18108
|
-
catch (e) {
|
|
18109
|
-
try {
|
|
18110
|
-
var serializedValue = JSON.stringify(value);
|
|
18111
|
-
window.sessionStorage.setItem(key, serializedValue);
|
|
18112
|
-
}
|
|
18113
|
-
catch (e) {
|
|
18114
|
-
//fallback
|
|
18115
|
-
this.setCookie(key, value, 31);
|
|
18116
|
-
Storage.data[key] = value;
|
|
18117
|
-
}
|
|
18118
|
-
}
|
|
18119
|
-
};
|
|
18120
|
-
Storage.get = function (key) {
|
|
18121
|
-
try {
|
|
18122
|
-
var serializedValue = window.localStorage.getItem(key);
|
|
18123
|
-
if (serializedValue !== null) {
|
|
18124
|
-
return JSON.parse(serializedValue);
|
|
18125
|
-
}
|
|
18126
|
-
}
|
|
18127
|
-
catch (e) {
|
|
18128
|
-
try {
|
|
18129
|
-
var serializedValue = window.sessionStorage.getItem(key);
|
|
18130
|
-
if (serializedValue !== null) {
|
|
18131
|
-
return JSON.parse(serializedValue);
|
|
18132
|
-
}
|
|
18133
|
-
}
|
|
18134
|
-
catch (e) {
|
|
18135
|
-
var value = Storage.getCookie(key);
|
|
18136
|
-
if (!value) {
|
|
18137
|
-
value = Storage.data[key];
|
|
18138
|
-
}
|
|
18139
|
-
return value;
|
|
18140
|
-
}
|
|
18141
|
-
}
|
|
18142
|
-
};
|
|
18143
|
-
Storage.setAuthToken = function (token) {
|
|
18144
|
-
Storage.set('glitch_auth_token', token);
|
|
18145
|
-
};
|
|
18146
|
-
Storage.getAuthToken = function () {
|
|
18147
|
-
return Storage.get('glitch_auth_token');
|
|
18148
|
-
};
|
|
18149
|
-
Storage.setCookie = function (name, value, days) {
|
|
18150
|
-
var expires = '';
|
|
18151
|
-
if (days) {
|
|
18152
|
-
var date = new Date();
|
|
18153
|
-
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
18154
|
-
expires = '; expires=' + date.toUTCString();
|
|
18155
|
-
}
|
|
18156
|
-
//IFrames require HttpyOnly to be false, Chrome require SameSite to be none, and must be secure
|
|
18157
|
-
document.cookie =
|
|
18158
|
-
name +
|
|
18159
|
-
'=' +
|
|
18160
|
-
(value || '') +
|
|
18161
|
-
expires +
|
|
18162
|
-
'; path=/; HttpOnly=false; SameSite=none; Secure';
|
|
18163
|
-
};
|
|
18164
|
-
Storage.getCookie = function (name) {
|
|
18165
|
-
var nameEQ = name + '=';
|
|
18166
|
-
var ca = document.cookie.split(';');
|
|
18167
|
-
for (var i = 0; i < ca.length; i++) {
|
|
18168
|
-
var c = ca[i];
|
|
18169
|
-
while (c.charAt(0) == ' ')
|
|
18170
|
-
c = c.substring(1, c.length);
|
|
18171
|
-
if (c.indexOf(nameEQ) == 0)
|
|
18172
|
-
return c.substring(nameEQ.length, c.length);
|
|
18173
|
-
}
|
|
18174
|
-
return null;
|
|
18175
|
-
};
|
|
18176
|
-
Storage.eraseCookie = function (name) {
|
|
18177
|
-
document.cookie =
|
|
18178
|
-
name +
|
|
18179
|
-
'=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
18180
|
-
};
|
|
18181
|
-
//Back up data type if no storage is working.
|
|
18182
|
-
Storage.data = {};
|
|
18183
|
-
return Storage;
|
|
18184
|
-
}());
|
|
18185
|
-
|
|
18186
18277
|
var Session = /** @class */ (function () {
|
|
18187
18278
|
function Session() {
|
|
18188
18279
|
}
|