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
|
@@ -457,5 +457,50 @@ declare class Competitions {
|
|
|
457
457
|
* @returns promise
|
|
458
458
|
*/
|
|
459
459
|
static uploadVenueMainImageBlob<T>(competition_id: string, blob: Blob, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
460
|
+
/**
|
|
461
|
+
* Get a leaderboard by a users points.
|
|
462
|
+
*
|
|
463
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
464
|
+
*
|
|
465
|
+
* @param competition_id
|
|
466
|
+
* @returns promise
|
|
467
|
+
*/
|
|
468
|
+
static userPointsLeaderboard<T>(competition_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
469
|
+
/**
|
|
470
|
+
* Get a leaderboard by a users wins.
|
|
471
|
+
*
|
|
472
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
473
|
+
*
|
|
474
|
+
* @param competition_id
|
|
475
|
+
* @returns promise
|
|
476
|
+
*/
|
|
477
|
+
static userWinsLeaderboard<T>(competition_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
478
|
+
/**
|
|
479
|
+
* Get a leaderboard by a teams points.
|
|
480
|
+
*
|
|
481
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
482
|
+
*
|
|
483
|
+
* @param competition_id
|
|
484
|
+
* @returns promise
|
|
485
|
+
*/
|
|
486
|
+
static teamPointsLeaderboard<T>(competition_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
487
|
+
/**
|
|
488
|
+
* Get a leaderboard by a teams wins.
|
|
489
|
+
*
|
|
490
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
491
|
+
*
|
|
492
|
+
* @param competition_id
|
|
493
|
+
* @returns promise
|
|
494
|
+
*/
|
|
495
|
+
static teamWinsLeaderboard<T>(competition_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
496
|
+
/**
|
|
497
|
+
* Get all leaderboards.
|
|
498
|
+
*
|
|
499
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
500
|
+
*
|
|
501
|
+
* @param competition_id
|
|
502
|
+
* @returns promise
|
|
503
|
+
*/
|
|
504
|
+
static allLeaderboards<T>(competition_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
460
505
|
}
|
|
461
506
|
export default Competitions;
|
|
@@ -8,6 +8,7 @@ declare class Config {
|
|
|
8
8
|
private static _baseUrl;
|
|
9
9
|
private static _authToken;
|
|
10
10
|
private static _community;
|
|
11
|
+
private static _rootDomain;
|
|
11
12
|
private static _baseUrlLocked;
|
|
12
13
|
/**
|
|
13
14
|
* Set the configuration
|
|
@@ -35,6 +36,14 @@ declare class Config {
|
|
|
35
36
|
* @param community The object of the community
|
|
36
37
|
*/
|
|
37
38
|
static setCommunity(community: Record<string, any>): void;
|
|
39
|
+
/**
|
|
40
|
+
* Sets the root level domain so data can accessed across
|
|
41
|
+
* multiple subdomains
|
|
42
|
+
*
|
|
43
|
+
* @param domain The domain ie: example.com
|
|
44
|
+
*/
|
|
45
|
+
static setRootDomain(domain: string): void;
|
|
46
|
+
static getRootDomain(): string;
|
|
38
47
|
/**
|
|
39
48
|
* Gets base url
|
|
40
49
|
*/
|
package/dist/esm/index.js
CHANGED
|
@@ -30077,6 +30077,104 @@ var Requests = /** @class */ (function () {
|
|
|
30077
30077
|
return Requests;
|
|
30078
30078
|
}());
|
|
30079
30079
|
|
|
30080
|
+
var Storage = /** @class */ (function () {
|
|
30081
|
+
function Storage() {
|
|
30082
|
+
}
|
|
30083
|
+
/**
|
|
30084
|
+
* Sets a root level domain so the data can persist across
|
|
30085
|
+
* subdomains
|
|
30086
|
+
*
|
|
30087
|
+
* @param rootDomain
|
|
30088
|
+
*/
|
|
30089
|
+
Storage.setRootDomain = function (rootDomain) {
|
|
30090
|
+
Storage.rootDomain = rootDomain;
|
|
30091
|
+
};
|
|
30092
|
+
Storage.getStorageKey = function (key) {
|
|
30093
|
+
return Storage.rootDomain ? "".concat(Storage.rootDomain, ":").concat(key) : key;
|
|
30094
|
+
};
|
|
30095
|
+
Storage.set = function (key, value) {
|
|
30096
|
+
try {
|
|
30097
|
+
var serializedValue = JSON.stringify(value);
|
|
30098
|
+
window.localStorage.setItem(Storage.getStorageKey(key), serializedValue);
|
|
30099
|
+
}
|
|
30100
|
+
catch (e) {
|
|
30101
|
+
try {
|
|
30102
|
+
var serializedValue = JSON.stringify(value);
|
|
30103
|
+
window.sessionStorage.setItem(Storage.getStorageKey(key), serializedValue);
|
|
30104
|
+
}
|
|
30105
|
+
catch (e) {
|
|
30106
|
+
this.setCookie(key, value, 31);
|
|
30107
|
+
Storage.data[key] = value;
|
|
30108
|
+
}
|
|
30109
|
+
}
|
|
30110
|
+
};
|
|
30111
|
+
Storage.get = function (key) {
|
|
30112
|
+
try {
|
|
30113
|
+
var serializedValue = window.localStorage.getItem(Storage.getStorageKey(key));
|
|
30114
|
+
if (serializedValue !== null) {
|
|
30115
|
+
return JSON.parse(serializedValue);
|
|
30116
|
+
}
|
|
30117
|
+
}
|
|
30118
|
+
catch (e) {
|
|
30119
|
+
try {
|
|
30120
|
+
var serializedValue = window.sessionStorage.getItem(Storage.getStorageKey(key));
|
|
30121
|
+
if (serializedValue !== null) {
|
|
30122
|
+
return JSON.parse(serializedValue);
|
|
30123
|
+
}
|
|
30124
|
+
}
|
|
30125
|
+
catch (e) {
|
|
30126
|
+
var value = Storage.getCookie(key);
|
|
30127
|
+
if (!value) {
|
|
30128
|
+
value = Storage.data[key];
|
|
30129
|
+
}
|
|
30130
|
+
return value;
|
|
30131
|
+
}
|
|
30132
|
+
}
|
|
30133
|
+
};
|
|
30134
|
+
Storage.setAuthToken = function (token) {
|
|
30135
|
+
Storage.set('glitch_auth_token', token);
|
|
30136
|
+
};
|
|
30137
|
+
Storage.getAuthToken = function () {
|
|
30138
|
+
return Storage.get('glitch_auth_token');
|
|
30139
|
+
};
|
|
30140
|
+
Storage.eraseCookie = function (name) {
|
|
30141
|
+
document.cookie =
|
|
30142
|
+
name +
|
|
30143
|
+
'=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
30144
|
+
};
|
|
30145
|
+
Storage.setCookie = function (name, value, days) {
|
|
30146
|
+
var expires = '';
|
|
30147
|
+
if (days) {
|
|
30148
|
+
var date = new Date();
|
|
30149
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
30150
|
+
expires = '; expires=' + date.toUTCString();
|
|
30151
|
+
}
|
|
30152
|
+
document.cookie =
|
|
30153
|
+
name +
|
|
30154
|
+
'=' +
|
|
30155
|
+
(value || '') +
|
|
30156
|
+
expires +
|
|
30157
|
+
'; path=/; domain=' +
|
|
30158
|
+
Storage.rootDomain +
|
|
30159
|
+
'; HttpOnly=false; SameSite=none; Secure';
|
|
30160
|
+
};
|
|
30161
|
+
Storage.getCookie = function (name) {
|
|
30162
|
+
var nameEQ = name + '=';
|
|
30163
|
+
var ca = document.cookie.split(';');
|
|
30164
|
+
for (var i = 0; i < ca.length; i++) {
|
|
30165
|
+
var c = ca[i];
|
|
30166
|
+
while (c.charAt(0) == ' ')
|
|
30167
|
+
c = c.substring(1, c.length);
|
|
30168
|
+
if (c.indexOf(nameEQ) == 0)
|
|
30169
|
+
return c.substring(nameEQ.length, c.length);
|
|
30170
|
+
}
|
|
30171
|
+
return null;
|
|
30172
|
+
};
|
|
30173
|
+
Storage.rootDomain = '';
|
|
30174
|
+
Storage.data = {};
|
|
30175
|
+
return Storage;
|
|
30176
|
+
}());
|
|
30177
|
+
|
|
30080
30178
|
/**
|
|
30081
30179
|
* Config
|
|
30082
30180
|
*
|
|
@@ -30132,6 +30230,25 @@ var Config = /** @class */ (function () {
|
|
|
30132
30230
|
Requests.setCommunityID(community.id);
|
|
30133
30231
|
LabelManager.initialize(community);
|
|
30134
30232
|
};
|
|
30233
|
+
/**
|
|
30234
|
+
* Sets the root level domain so data can accessed across
|
|
30235
|
+
* multiple subdomains
|
|
30236
|
+
*
|
|
30237
|
+
* @param domain The domain ie: example.com
|
|
30238
|
+
*/
|
|
30239
|
+
Config.setRootDomain = function (domain) {
|
|
30240
|
+
var parts = domain.split('.');
|
|
30241
|
+
if (parts.length > 2) {
|
|
30242
|
+
parts.shift();
|
|
30243
|
+
}
|
|
30244
|
+
var formattedDomain = parts.join('.');
|
|
30245
|
+
formattedDomain = formattedDomain.replace(/^\./, '');
|
|
30246
|
+
this._rootDomain = formattedDomain;
|
|
30247
|
+
Storage.setRootDomain(formattedDomain);
|
|
30248
|
+
};
|
|
30249
|
+
Config.getRootDomain = function () {
|
|
30250
|
+
return this._rootDomain;
|
|
30251
|
+
};
|
|
30135
30252
|
Object.defineProperty(Config, "baseUrl", {
|
|
30136
30253
|
/**
|
|
30137
30254
|
* Gets base url
|
|
@@ -30304,6 +30421,11 @@ var CompetitionRoutes = /** @class */ (function () {
|
|
|
30304
30421
|
updateVenue: { url: '/competitions/{competition_id}/venues/{venue_id}', method: HTTP_METHODS.PUT },
|
|
30305
30422
|
destroyVenue: { url: '/competitions/{competition_id}/venues/{venue_id}', method: HTTP_METHODS.DELETE },
|
|
30306
30423
|
uploadVenueMainImage: { url: '/competitions/{competition_id}/venues/{venue_id}/uploadMainImage', method: HTTP_METHODS.POST },
|
|
30424
|
+
userPointsLeaderboard: { url: '/competitions/{competition_id}/userPointsLeaderboard', method: HTTP_METHODS.GET },
|
|
30425
|
+
teamPointsLeaderboard: { url: '/competitions/{competition_id}/teamPointsLeaderboard', method: HTTP_METHODS.GET },
|
|
30426
|
+
userWinsLeaderboard: { url: '/competitions/{competition_id}/userWinsLeaderboard', method: HTTP_METHODS.GET },
|
|
30427
|
+
teamWinsLeaderboard: { url: '/competitions/{competition_id}/teamWinsLeaderboard', method: HTTP_METHODS.GET },
|
|
30428
|
+
allLeaderboards: { url: '/competitions/{competition_id}/allLeaderboards', method: HTTP_METHODS.GET },
|
|
30307
30429
|
};
|
|
30308
30430
|
return CompetitionRoutes;
|
|
30309
30431
|
}());
|
|
@@ -30865,6 +30987,61 @@ var Competitions = /** @class */ (function () {
|
|
|
30865
30987
|
var url = CompetitionRoutes.routes.uploadVenueMainImage.url.replace('{competition_id}', competition_id);
|
|
30866
30988
|
return Requests.uploadBlob(url, 'image', blob, data);
|
|
30867
30989
|
};
|
|
30990
|
+
/**
|
|
30991
|
+
* Get a leaderboard by a users points.
|
|
30992
|
+
*
|
|
30993
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
30994
|
+
*
|
|
30995
|
+
* @param competition_id
|
|
30996
|
+
* @returns promise
|
|
30997
|
+
*/
|
|
30998
|
+
Competitions.userPointsLeaderboard = function (competition_id, params) {
|
|
30999
|
+
return Requests.processRoute(CompetitionRoutes.routes.userPointsLeaderboard, {}, { competition_id: competition_id }, params);
|
|
31000
|
+
};
|
|
31001
|
+
/**
|
|
31002
|
+
* Get a leaderboard by a users wins.
|
|
31003
|
+
*
|
|
31004
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
31005
|
+
*
|
|
31006
|
+
* @param competition_id
|
|
31007
|
+
* @returns promise
|
|
31008
|
+
*/
|
|
31009
|
+
Competitions.userWinsLeaderboard = function (competition_id, params) {
|
|
31010
|
+
return Requests.processRoute(CompetitionRoutes.routes.userWinsLeaderboard, {}, { competition_id: competition_id }, params);
|
|
31011
|
+
};
|
|
31012
|
+
/**
|
|
31013
|
+
* Get a leaderboard by a teams points.
|
|
31014
|
+
*
|
|
31015
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
31016
|
+
*
|
|
31017
|
+
* @param competition_id
|
|
31018
|
+
* @returns promise
|
|
31019
|
+
*/
|
|
31020
|
+
Competitions.teamPointsLeaderboard = function (competition_id, params) {
|
|
31021
|
+
return Requests.processRoute(CompetitionRoutes.routes.teamPointsLeaderboard, {}, { competition_id: competition_id }, params);
|
|
31022
|
+
};
|
|
31023
|
+
/**
|
|
31024
|
+
* Get a leaderboard by a teams wins.
|
|
31025
|
+
*
|
|
31026
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
31027
|
+
*
|
|
31028
|
+
* @param competition_id
|
|
31029
|
+
* @returns promise
|
|
31030
|
+
*/
|
|
31031
|
+
Competitions.teamWinsLeaderboard = function (competition_id, params) {
|
|
31032
|
+
return Requests.processRoute(CompetitionRoutes.routes.teamWinsLeaderboard, {}, { competition_id: competition_id }, params);
|
|
31033
|
+
};
|
|
31034
|
+
/**
|
|
31035
|
+
* Get all leaderboards.
|
|
31036
|
+
*
|
|
31037
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
|
|
31038
|
+
*
|
|
31039
|
+
* @param competition_id
|
|
31040
|
+
* @returns promise
|
|
31041
|
+
*/
|
|
31042
|
+
Competitions.allLeaderboards = function (competition_id, params) {
|
|
31043
|
+
return Requests.processRoute(CompetitionRoutes.routes.allLeaderboards, {}, { competition_id: competition_id }, params);
|
|
31044
|
+
};
|
|
30868
31045
|
return Competitions;
|
|
30869
31046
|
}());
|
|
30870
31047
|
|
|
@@ -32319,92 +32496,6 @@ var Parser = /** @class */ (function () {
|
|
|
32319
32496
|
return Parser;
|
|
32320
32497
|
}());
|
|
32321
32498
|
|
|
32322
|
-
var Storage = /** @class */ (function () {
|
|
32323
|
-
function Storage() {
|
|
32324
|
-
}
|
|
32325
|
-
Storage.set = function (key, value) {
|
|
32326
|
-
try {
|
|
32327
|
-
var serializedValue = JSON.stringify(value);
|
|
32328
|
-
window.localStorage.setItem(key, serializedValue);
|
|
32329
|
-
}
|
|
32330
|
-
catch (e) {
|
|
32331
|
-
try {
|
|
32332
|
-
var serializedValue = JSON.stringify(value);
|
|
32333
|
-
window.sessionStorage.setItem(key, serializedValue);
|
|
32334
|
-
}
|
|
32335
|
-
catch (e) {
|
|
32336
|
-
//fallback
|
|
32337
|
-
this.setCookie(key, value, 31);
|
|
32338
|
-
Storage.data[key] = value;
|
|
32339
|
-
}
|
|
32340
|
-
}
|
|
32341
|
-
};
|
|
32342
|
-
Storage.get = function (key) {
|
|
32343
|
-
try {
|
|
32344
|
-
var serializedValue = window.localStorage.getItem(key);
|
|
32345
|
-
if (serializedValue !== null) {
|
|
32346
|
-
return JSON.parse(serializedValue);
|
|
32347
|
-
}
|
|
32348
|
-
}
|
|
32349
|
-
catch (e) {
|
|
32350
|
-
try {
|
|
32351
|
-
var serializedValue = window.sessionStorage.getItem(key);
|
|
32352
|
-
if (serializedValue !== null) {
|
|
32353
|
-
return JSON.parse(serializedValue);
|
|
32354
|
-
}
|
|
32355
|
-
}
|
|
32356
|
-
catch (e) {
|
|
32357
|
-
var value = Storage.getCookie(key);
|
|
32358
|
-
if (!value) {
|
|
32359
|
-
value = Storage.data[key];
|
|
32360
|
-
}
|
|
32361
|
-
return value;
|
|
32362
|
-
}
|
|
32363
|
-
}
|
|
32364
|
-
};
|
|
32365
|
-
Storage.setAuthToken = function (token) {
|
|
32366
|
-
Storage.set('glitch_auth_token', token);
|
|
32367
|
-
};
|
|
32368
|
-
Storage.getAuthToken = function () {
|
|
32369
|
-
return Storage.get('glitch_auth_token');
|
|
32370
|
-
};
|
|
32371
|
-
Storage.setCookie = function (name, value, days) {
|
|
32372
|
-
var expires = '';
|
|
32373
|
-
if (days) {
|
|
32374
|
-
var date = new Date();
|
|
32375
|
-
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
32376
|
-
expires = '; expires=' + date.toUTCString();
|
|
32377
|
-
}
|
|
32378
|
-
//IFrames require HttpyOnly to be false, Chrome require SameSite to be none, and must be secure
|
|
32379
|
-
document.cookie =
|
|
32380
|
-
name +
|
|
32381
|
-
'=' +
|
|
32382
|
-
(value || '') +
|
|
32383
|
-
expires +
|
|
32384
|
-
'; path=/; HttpOnly=false; SameSite=none; Secure';
|
|
32385
|
-
};
|
|
32386
|
-
Storage.getCookie = function (name) {
|
|
32387
|
-
var nameEQ = name + '=';
|
|
32388
|
-
var ca = document.cookie.split(';');
|
|
32389
|
-
for (var i = 0; i < ca.length; i++) {
|
|
32390
|
-
var c = ca[i];
|
|
32391
|
-
while (c.charAt(0) == ' ')
|
|
32392
|
-
c = c.substring(1, c.length);
|
|
32393
|
-
if (c.indexOf(nameEQ) == 0)
|
|
32394
|
-
return c.substring(nameEQ.length, c.length);
|
|
32395
|
-
}
|
|
32396
|
-
return null;
|
|
32397
|
-
};
|
|
32398
|
-
Storage.eraseCookie = function (name) {
|
|
32399
|
-
document.cookie =
|
|
32400
|
-
name +
|
|
32401
|
-
'=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
32402
|
-
};
|
|
32403
|
-
//Back up data type if no storage is working.
|
|
32404
|
-
Storage.data = {};
|
|
32405
|
-
return Storage;
|
|
32406
|
-
}());
|
|
32407
|
-
|
|
32408
32499
|
var Session = /** @class */ (function () {
|
|
32409
32500
|
function Session() {
|
|
32410
32501
|
}
|