glitch-javascript-sdk 0.3.9 → 0.4.1

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 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
@@ -16087,6 +16204,7 @@ var CompetitionRoutes = /** @class */ (function () {
16087
16204
  userWinsLeaderboard: { url: '/competitions/{competition_id}/userWinsLeaderboard', method: HTTP_METHODS.GET },
16088
16205
  teamWinsLeaderboard: { url: '/competitions/{competition_id}/teamWinsLeaderboard', method: HTTP_METHODS.GET },
16089
16206
  allLeaderboards: { url: '/competitions/{competition_id}/allLeaderboards', method: HTTP_METHODS.GET },
16207
+ me: { url: '/competitions/{competition_id}/me', method: HTTP_METHODS.GET },
16090
16208
  };
16091
16209
  return CompetitionRoutes;
16092
16210
  }());
@@ -16662,7 +16780,7 @@ var Competitions = /** @class */ (function () {
16662
16780
  /**
16663
16781
  * Get a leaderboard by a users wins.
16664
16782
  *
16665
- * @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
16783
+ * @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionLeaderBoardUserWins
16666
16784
  *
16667
16785
  * @param competition_id
16668
16786
  * @returns promise
@@ -16684,7 +16802,7 @@ var Competitions = /** @class */ (function () {
16684
16802
  /**
16685
16803
  * Get a leaderboard by a teams wins.
16686
16804
  *
16687
- * @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
16805
+ * @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionLeaderBoardTeamWins
16688
16806
  *
16689
16807
  * @param competition_id
16690
16808
  * @returns promise
@@ -16695,7 +16813,7 @@ var Competitions = /** @class */ (function () {
16695
16813
  /**
16696
16814
  * Get all leaderboards.
16697
16815
  *
16698
- * @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionUserList
16816
+ * @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionLeaderBoardTeamPoints
16699
16817
  *
16700
16818
  * @param competition_id
16701
16819
  * @returns promise
@@ -16703,6 +16821,17 @@ var Competitions = /** @class */ (function () {
16703
16821
  Competitions.allLeaderboards = function (competition_id, params) {
16704
16822
  return Requests.processRoute(CompetitionRoutes.routes.allLeaderboards, {}, { competition_id: competition_id }, params);
16705
16823
  };
16824
+ /**
16825
+ * Gets all the information about a competition for the current user.
16826
+ *
16827
+ * @see https://api.glitch.fun/api/documentation#/Competitions%20Route/competitionLeaderboardsAll
16828
+ *
16829
+ * @param competition_id
16830
+ * @returns promise
16831
+ */
16832
+ Competitions.me = function (competition_id, params) {
16833
+ return Requests.processRoute(CompetitionRoutes.routes.allLeaderboards, {}, { competition_id: competition_id }, params);
16834
+ };
16706
16835
  return Competitions;
16707
16836
  }());
16708
16837
 
@@ -18157,92 +18286,6 @@ var Parser = /** @class */ (function () {
18157
18286
  return Parser;
18158
18287
  }());
18159
18288
 
18160
- var Storage = /** @class */ (function () {
18161
- function Storage() {
18162
- }
18163
- Storage.set = function (key, value) {
18164
- try {
18165
- var serializedValue = JSON.stringify(value);
18166
- window.localStorage.setItem(key, serializedValue);
18167
- }
18168
- catch (e) {
18169
- try {
18170
- var serializedValue = JSON.stringify(value);
18171
- window.sessionStorage.setItem(key, serializedValue);
18172
- }
18173
- catch (e) {
18174
- //fallback
18175
- this.setCookie(key, value, 31);
18176
- Storage.data[key] = value;
18177
- }
18178
- }
18179
- };
18180
- Storage.get = function (key) {
18181
- try {
18182
- var serializedValue = window.localStorage.getItem(key);
18183
- if (serializedValue !== null) {
18184
- return JSON.parse(serializedValue);
18185
- }
18186
- }
18187
- catch (e) {
18188
- try {
18189
- var serializedValue = window.sessionStorage.getItem(key);
18190
- if (serializedValue !== null) {
18191
- return JSON.parse(serializedValue);
18192
- }
18193
- }
18194
- catch (e) {
18195
- var value = Storage.getCookie(key);
18196
- if (!value) {
18197
- value = Storage.data[key];
18198
- }
18199
- return value;
18200
- }
18201
- }
18202
- };
18203
- Storage.setAuthToken = function (token) {
18204
- Storage.set('glitch_auth_token', token);
18205
- };
18206
- Storage.getAuthToken = function () {
18207
- return Storage.get('glitch_auth_token');
18208
- };
18209
- Storage.setCookie = function (name, value, days) {
18210
- var expires = '';
18211
- if (days) {
18212
- var date = new Date();
18213
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
18214
- expires = '; expires=' + date.toUTCString();
18215
- }
18216
- //IFrames require HttpyOnly to be false, Chrome require SameSite to be none, and must be secure
18217
- document.cookie =
18218
- name +
18219
- '=' +
18220
- (value || '') +
18221
- expires +
18222
- '; path=/; HttpOnly=false; SameSite=none; Secure';
18223
- };
18224
- Storage.getCookie = function (name) {
18225
- var nameEQ = name + '=';
18226
- var ca = document.cookie.split(';');
18227
- for (var i = 0; i < ca.length; i++) {
18228
- var c = ca[i];
18229
- while (c.charAt(0) == ' ')
18230
- c = c.substring(1, c.length);
18231
- if (c.indexOf(nameEQ) == 0)
18232
- return c.substring(nameEQ.length, c.length);
18233
- }
18234
- return null;
18235
- };
18236
- Storage.eraseCookie = function (name) {
18237
- document.cookie =
18238
- name +
18239
- '=; Secure; HttpOnly=false; SameSite=none; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
18240
- };
18241
- //Back up data type if no storage is working.
18242
- Storage.data = {};
18243
- return Storage;
18244
- }());
18245
-
18246
18289
  var Session = /** @class */ (function () {
18247
18290
  function Session() {
18248
18291
  }