glitch-javascript-sdk 0.2.9 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glitch-javascript-sdk",
3
- "version": "0.2.9",
3
+ "version": "0.3.1",
4
4
  "description": "Javascript SDK for Glitch",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -97,8 +97,14 @@ class Requests {
97
97
  public static get<T>(url: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
98
98
 
99
99
  if (params && Object.keys(params).length > 0) {
100
+
100
101
  const queryString = Object.entries(params)
101
- .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
102
+ .map(([key, value]) => {
103
+ if (Array.isArray(value)) {
104
+ return value.map((item) => `${key}[]=${encodeURIComponent(item)}`).join('&');
105
+ }
106
+ return `${key}=${encodeURIComponent(value)}`;
107
+ })
102
108
  .join('&');
103
109
  url = `${url}?${queryString}`;
104
110
  }
@@ -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
  }