glitch-javascript-sdk 0.2.8 → 0.3.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/index.d.ts CHANGED
@@ -784,6 +784,16 @@ declare class Communities {
784
784
  * @returns promise
785
785
  */
786
786
  static findByDomain<T>(domain: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
787
+ /**
788
+ * Has a user join a community. The join is executed using the current user's authentication token.
789
+ *
790
+ * @see https://api.glitch.fun/api/documentation#/Community%20Route/updateCommunityStorage
791
+ *
792
+ * @param community_id The id of the community to update.
793
+ *
794
+ * @returns promise
795
+ */
796
+ static join<T>(community_id: string, data: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
787
797
  }
788
798
 
789
799
  declare class Users {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glitch-javascript-sdk",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "description": "Javascript SDK for Glitch",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -253,7 +253,7 @@ class Communities {
253
253
  * @returns promise
254
254
  */
255
255
  public static getUser<T>(community_id : string, user_id : string, params?: Record<string, any>): AxiosPromise<Response<T>> {
256
- return Requests.processRoute(CommunitiesRoute.routes.showUser, {}, {community_id : community_id, user_id}, params);
256
+ return Requests.processRoute(CommunitiesRoute.routes.showUser, {}, {community_id : community_id, user_id : user_id}, params);
257
257
  }
258
258
 
259
259
  /**
@@ -265,7 +265,7 @@ class Communities {
265
265
  * @returns promise
266
266
  */
267
267
  public static updatetUser<T>(community_id : string, user_id : string, data? : object, params?: Record<string, any>): AxiosPromise<Response<T>> {
268
- return Requests.processRoute(CommunitiesRoute.routes.updateUser, data, {community_id : community_id, user_id}, params);
268
+ return Requests.processRoute(CommunitiesRoute.routes.updateUser, data, {community_id : community_id, user_id : user_id}, params);
269
269
  }
270
270
 
271
271
  /**
@@ -277,7 +277,7 @@ class Communities {
277
277
  * @returns promise
278
278
  */
279
279
  public static removetUser<T>(community_id : string, user_id : string, params?: Record<string, any>): AxiosPromise<Response<T>> {
280
- return Requests.processRoute(CommunitiesRoute.routes.removeUser, {}, {community_id : community_id, user_id}, params);
280
+ return Requests.processRoute(CommunitiesRoute.routes.removeUser, {}, {community_id : community_id, user_id : user_id}, params);
281
281
  }
282
282
 
283
283
  /**
@@ -291,6 +291,21 @@ class Communities {
291
291
  return Requests.processRoute(CommunitiesRoute.routes.findByDomain, {}, {domain : domain}, params);
292
292
  }
293
293
 
294
+ /**
295
+ * Has a user join a community. The join is executed using the current user's authentication token.
296
+ *
297
+ * @see https://api.glitch.fun/api/documentation#/Community%20Route/updateCommunityStorage
298
+ *
299
+ * @param community_id The id of the community to update.
300
+ *
301
+ * @returns promise
302
+ */
303
+ public static join<T>(community_id : string, data : object, params?: Record<string, any>) : AxiosPromise<Response<T>>{
304
+
305
+ return Requests.processRoute(CommunitiesRoute.routes.join, data, {community_id : community_id}, params);
306
+ }
307
+
308
+
294
309
 
295
310
 
296
311
 
@@ -20,6 +20,7 @@ class CommunitiesRoute {
20
20
  showUser : {url : '/communities/{community_id}/users/{user_id}', method : HTTP_METHODS.GET},
21
21
  updateUser : {url : '/communities/{community_id}/users/{user_id}', method : HTTP_METHODS.PUT},
22
22
  removeUser : {url : '/communities/{community_id}/users/{user_id}', method : HTTP_METHODS.DELETE},
23
+ join : {url : '/communities/{community_id}/join', method : HTTP_METHODS.POST},
23
24
  findByDomain : {url : '/communities/findByDomain/{domain}', method : HTTP_METHODS.GET}
24
25
  };
25
26
 
@@ -6,14 +6,20 @@ class Storage {
6
6
 
7
7
 
8
8
  public static set(key: string, value: any) {
9
+
9
10
  try {
10
- window.localStorage.setItem(key, value);
11
+ const serializedValue = JSON.stringify(value);
12
+ window.localStorage.setItem(key, serializedValue);
11
13
  } catch (e) {
14
+
12
15
  try {
13
- window.sessionStorage.setItem(key, value);
16
+
17
+ const serializedValue = JSON.stringify(value);
18
+ window.sessionStorage.setItem(key, serializedValue);
19
+
14
20
  } catch (e) {
21
+ //fallback
15
22
  this.setCookie(key, value, 31);
16
- //fallback if set cookie fails
17
23
  Storage.data[key] = value;
18
24
  }
19
25
  }
@@ -21,11 +27,25 @@ class Storage {
21
27
 
22
28
  public static get(key: string): any {
23
29
  try {
24
- return window.localStorage.getItem(key);
30
+
31
+ const serializedValue = window.localStorage.getItem(key);
32
+
33
+ if (serializedValue !== null) {
34
+ return JSON.parse(serializedValue);
35
+ }
36
+
25
37
  } catch (e) {
38
+
26
39
  try {
27
- return window.sessionStorage.getItem(key);
40
+
41
+ const serializedValue = window.sessionStorage.getItem(key);
42
+
43
+ if (serializedValue !== null) {
44
+ return JSON.parse(serializedValue);
45
+ }
46
+
28
47
  } catch (e) {
48
+
29
49
  let value = Storage.getCookie(key);
30
50
 
31
51
  if (!value) {
@@ -37,6 +57,7 @@ class Storage {
37
57
  }
38
58
  }
39
59
 
60
+
40
61
  public static setAuthToken(token: string | null) {
41
62
  Storage.set('glitch_auth_token', token);
42
63
  }