glitch-javascript-sdk 0.0.1 → 0.0.3
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 +55 -186
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/Auth.d.ts +34 -2
- package/dist/esm/api/Competitions.d.ts +50 -5
- package/dist/esm/api/Events.d.ts +53 -0
- package/dist/esm/api/Users.d.ts +62 -0
- package/dist/esm/api/index.d.ts +4 -0
- package/dist/esm/index.d.ts +8 -2
- package/dist/esm/index.js +211 -342
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/routes/EventsRoute.d.ts +7 -0
- package/dist/esm/routes/UserRoutes.d.ts +7 -0
- package/dist/esm/util/Requests.d.ts +27 -5
- package/dist/index.d.ts +199 -9
- package/package.json +1 -1
- package/src/api/Auth.ts +38 -3
- package/src/api/Competitions.ts +50 -5
- package/src/api/Events.ts +81 -0
- package/src/api/Users.ts +92 -0
- package/src/api/index.ts +5 -1
- package/src/index.ts +8 -2
- package/src/routes/EventsRoute.ts +33 -0
- package/src/routes/UserRoutes.ts +20 -0
- package/src/util/Requests.ts +46 -31
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Route from "./interface";
|
|
2
|
+
import HTTP_METHODS from "../constants/HttpMethods";
|
|
3
|
+
|
|
4
|
+
class UserRoutes {
|
|
5
|
+
|
|
6
|
+
public static routes: { [key: string]: Route } = {
|
|
7
|
+
list: { url: '/users', method: HTTP_METHODS.GET },
|
|
8
|
+
update: { url: '/users', method: HTTP_METHODS.PUT },
|
|
9
|
+
follow : { url: '/users/{user_id}/follow', method: HTTP_METHODS.POST },
|
|
10
|
+
profile :{ url: '/users/{uuid}/profile', method: HTTP_METHODS.GET },
|
|
11
|
+
me : { url: '/users/me', method: HTTP_METHODS.GET },
|
|
12
|
+
oneTimeToken : { url: '/users/oneTimeToken', method: HTTP_METHODS.GET },
|
|
13
|
+
uploadAvatar : { url: '/users/uploadAvatarImage', method: HTTP_METHODS.POST },
|
|
14
|
+
uploadBanner : { url: '/users/uploadBannerImage', method: HTTP_METHODS.POST },
|
|
15
|
+
createDonationPage : { url: '/users/createDonationPage', method: HTTP_METHODS.POST },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default UserRoutes;
|
package/src/util/Requests.ts
CHANGED
|
@@ -3,19 +3,27 @@ import Config from '../config/Config';
|
|
|
3
3
|
import HTTP_METHODS from '../constants/HttpMethods';
|
|
4
4
|
import Route from '../routes/interface';
|
|
5
5
|
import Response from './Response';
|
|
6
|
+
import { AxiosPromise } from 'axios';
|
|
6
7
|
|
|
7
8
|
class Requests {
|
|
8
9
|
|
|
9
10
|
config: Config;
|
|
10
11
|
|
|
12
|
+
//The base url of the API.
|
|
11
13
|
private static baseUrl = "";
|
|
12
14
|
|
|
15
|
+
//The Json Web Token to send in the header
|
|
13
16
|
private static authToken = "";
|
|
14
17
|
|
|
15
18
|
constructor(config: Config) {
|
|
16
19
|
this.config = config;
|
|
17
20
|
}
|
|
18
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Sets the configuration of the system.
|
|
24
|
+
*
|
|
25
|
+
* @param config Config The config class.
|
|
26
|
+
*/
|
|
19
27
|
public static setConfig(config: Config) {
|
|
20
28
|
|
|
21
29
|
this.baseUrl = config.baseUrl;
|
|
@@ -23,57 +31,62 @@ class Requests {
|
|
|
23
31
|
this.authToken = config.authToken;
|
|
24
32
|
}
|
|
25
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Sets the base url of the API.
|
|
36
|
+
*
|
|
37
|
+
* @param url The url to of the API.
|
|
38
|
+
*/
|
|
26
39
|
public static setBaseUrl(url : string) {
|
|
27
40
|
this.baseUrl = url;
|
|
28
41
|
}
|
|
29
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Sets the JSON Web token
|
|
45
|
+
*
|
|
46
|
+
* @param token
|
|
47
|
+
*/
|
|
30
48
|
public static setAuthToken(token : string) {
|
|
31
49
|
this.authToken = token;
|
|
32
50
|
}
|
|
33
51
|
|
|
34
|
-
|
|
52
|
+
|
|
53
|
+
private static request<T>(
|
|
35
54
|
method: 'GET' | 'POST' | 'PUT' | 'DELETE',
|
|
36
55
|
url: string,
|
|
37
56
|
data?: any
|
|
38
|
-
):
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
data: response.data,
|
|
51
|
-
success: true,
|
|
52
|
-
};
|
|
53
|
-
} catch (error) {
|
|
54
|
-
|
|
55
|
-
const message = error.response?.data?.message || 'An error occurred';
|
|
56
|
-
return {
|
|
57
|
-
data: null,
|
|
58
|
-
success: false,
|
|
59
|
-
message,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
57
|
+
): AxiosPromise<Response<T>> {
|
|
58
|
+
const axiosPromise = axios({
|
|
59
|
+
method,
|
|
60
|
+
url: `${this.baseUrl}${url}`,
|
|
61
|
+
data,
|
|
62
|
+
headers: {
|
|
63
|
+
Authorization: `Bearer ${this.authToken}`,
|
|
64
|
+
'Content-Type': 'application/json',
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return axiosPromise;
|
|
62
69
|
}
|
|
63
70
|
|
|
64
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Calls a GET request to the url endpoint.
|
|
73
|
+
*
|
|
74
|
+
* @param url
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
public static get<T>(url: string): AxiosPromise<Response<T>> {
|
|
65
78
|
return this.request<T>('GET', url);
|
|
66
79
|
}
|
|
67
80
|
|
|
68
|
-
public static
|
|
81
|
+
public static post<T>(url: string, data: any): AxiosPromise<Response<T>> {
|
|
69
82
|
return this.request<T>('POST', url, data);
|
|
70
83
|
}
|
|
71
84
|
|
|
72
|
-
public static
|
|
85
|
+
public static put<T>(url: string, data: any): AxiosPromise<Response<T>> {
|
|
73
86
|
return this.request<T>('PUT', url, data);
|
|
74
87
|
}
|
|
75
88
|
|
|
76
|
-
public static
|
|
89
|
+
public static delete<T>(url: string): AxiosPromise<Response<T>> {
|
|
77
90
|
return this.request<T>('DELETE', url);
|
|
78
91
|
}
|
|
79
92
|
|
|
@@ -85,14 +98,14 @@ class Requests {
|
|
|
85
98
|
* @param data
|
|
86
99
|
* @returns
|
|
87
100
|
*/
|
|
88
|
-
public static
|
|
101
|
+
public static processRoute<T>(route : Route, data? : object, routeReplace? : object) : AxiosPromise<Response<T>> {
|
|
89
102
|
|
|
90
103
|
let url = route.url;
|
|
91
104
|
|
|
92
105
|
if(routeReplace) {
|
|
93
106
|
|
|
94
107
|
for (let key in routeReplace) {
|
|
95
|
-
|
|
108
|
+
url = url.replace("{" + key + "}", routeReplace[key]);
|
|
96
109
|
}
|
|
97
110
|
|
|
98
111
|
}
|
|
@@ -107,6 +120,8 @@ class Requests {
|
|
|
107
120
|
return this.delete(url);
|
|
108
121
|
}
|
|
109
122
|
|
|
123
|
+
return this.get(url);
|
|
124
|
+
|
|
110
125
|
}
|
|
111
126
|
|
|
112
127
|
}
|