glitch-javascript-sdk 0.6.0 → 0.6.2
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 +122 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/Posts.d.ts +21 -0
- package/dist/esm/api/SocialPosts.d.ts +31 -0
- package/dist/esm/api/Users.d.ts +16 -0
- package/dist/esm/api/index.d.ts +2 -0
- package/dist/esm/index.js +122 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/routes/SocialPostsRoute.d.ts +7 -0
- package/dist/esm/util/Requests.d.ts +1 -1
- package/dist/index.d.ts +38 -1
- package/package.json +1 -1
- package/src/api/Posts.ts +77 -22
- package/src/api/SocialPosts.ts +46 -0
- package/src/api/Users.ts +24 -0
- package/src/api/index.ts +3 -1
- package/src/index.ts +2 -0
- package/src/routes/SocialPostsRoute.ts +14 -0
- package/src/routes/UserRoutes.ts +2 -0
- package/src/util/Requests.ts +1 -1
|
@@ -16,7 +16,7 @@ declare class Requests {
|
|
|
16
16
|
static post<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
17
17
|
static put<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
18
18
|
static delete<T>(url: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
19
|
-
static uploadFile<T>(url: string, filename: string, file: File, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
19
|
+
static uploadFile<T>(url: string, filename: string, file: File | Blob, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
20
20
|
static uploadBlob<T>(url: string, filename: string, blob: Blob, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
21
21
|
static processRoute<T>(route: Route, data?: object, routeReplace?: {
|
|
22
22
|
[key: string]: any;
|
package/dist/index.d.ts
CHANGED
|
@@ -1029,6 +1029,22 @@ declare class Users {
|
|
|
1029
1029
|
* @returns promise
|
|
1030
1030
|
*/
|
|
1031
1031
|
static clearYoutubeAuth<T>(): AxiosPromise<Response<T>>;
|
|
1032
|
+
/**
|
|
1033
|
+
* Clear Reddit authentication information from the current user.
|
|
1034
|
+
*
|
|
1035
|
+
* @see https://api.glitch.fun/api/documentation#/Users%20Route/userCreateDonationPage
|
|
1036
|
+
*
|
|
1037
|
+
* @returns promise
|
|
1038
|
+
*/
|
|
1039
|
+
static clearRedditAuth<T>(): AxiosPromise<Response<T>>;
|
|
1040
|
+
/**
|
|
1041
|
+
* Clear Twitter authentication information from the current user.
|
|
1042
|
+
*
|
|
1043
|
+
* @see https://api.glitch.fun/api/documentation#/Users%20Route/userCreateDonationPage
|
|
1044
|
+
*
|
|
1045
|
+
* @returns promise
|
|
1046
|
+
*/
|
|
1047
|
+
static clearTwitterAuth<T>(): AxiosPromise<Response<T>>;
|
|
1032
1048
|
/**
|
|
1033
1049
|
* Clear StreamElements authentication information from the current user.
|
|
1034
1050
|
*
|
|
@@ -1732,6 +1748,27 @@ declare class Posts {
|
|
|
1732
1748
|
* @returns promise
|
|
1733
1749
|
*/
|
|
1734
1750
|
static createWithBlob<T>(blob: Blob, data?: object): AxiosPromise<Response<T>>;
|
|
1751
|
+
/**
|
|
1752
|
+
* Create a new post with a file divided into chunks.
|
|
1753
|
+
*
|
|
1754
|
+
* @param file The file object to upload.
|
|
1755
|
+
* @param chunkSize Size of each chunk in bytes. Default is 1MB.
|
|
1756
|
+
* @param data Any additional data to pass along to the upload.
|
|
1757
|
+
*
|
|
1758
|
+
* @returns Promise
|
|
1759
|
+
*/
|
|
1760
|
+
/**
|
|
1761
|
+
* Create a new post with a file divided into chunks.
|
|
1762
|
+
*
|
|
1763
|
+
* @param file The file object to upload.
|
|
1764
|
+
* @param chunkSize Size of each chunk in bytes. Default is 1MB.
|
|
1765
|
+
* @param data Any additional data to pass along to the upload.
|
|
1766
|
+
*
|
|
1767
|
+
* @returns Promise
|
|
1768
|
+
*/
|
|
1769
|
+
static createWithFileInChunks<T>(file: File, chunkSize?: number, data?: {
|
|
1770
|
+
[key: string]: any;
|
|
1771
|
+
}): Promise<AxiosPromise<Response<T>>>;
|
|
1735
1772
|
/**
|
|
1736
1773
|
* Update a post.
|
|
1737
1774
|
*
|
|
@@ -2053,7 +2090,7 @@ declare class Requests {
|
|
|
2053
2090
|
static post<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2054
2091
|
static put<T>(url: string, data: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2055
2092
|
static delete<T>(url: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2056
|
-
static uploadFile<T>(url: string, filename: string, file: File, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2093
|
+
static uploadFile<T>(url: string, filename: string, file: File | Blob, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2057
2094
|
static uploadBlob<T>(url: string, filename: string, blob: Blob, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2058
2095
|
static processRoute<T>(route: Route, data?: object, routeReplace?: {
|
|
2059
2096
|
[key: string]: any;
|
package/package.json
CHANGED
package/src/api/Posts.ts
CHANGED
|
@@ -12,7 +12,7 @@ class Posts {
|
|
|
12
12
|
*
|
|
13
13
|
* @returns promise
|
|
14
14
|
*/
|
|
15
|
-
public static list<T>(params?: Record<string, any>)
|
|
15
|
+
public static list<T>(params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
16
16
|
return Requests.processRoute(PostsRoute.routes.list, undefined, undefined, params);
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -25,22 +25,22 @@ class Posts {
|
|
|
25
25
|
*
|
|
26
26
|
* @returns Promise
|
|
27
27
|
*/
|
|
28
|
-
public static create<T>(data
|
|
28
|
+
public static create<T>(data: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
29
29
|
|
|
30
30
|
return Requests.processRoute(PostsRoute.routes.create, data, undefined, params);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Create a new post with a file. The file should either be an image or video.
|
|
35
|
+
*
|
|
36
|
+
* @see https://api.glitch.fun/api/documentation#/Post%20Route/newPostResourceStorage
|
|
37
|
+
*
|
|
38
|
+
* @param file The file object to upload.
|
|
39
|
+
* @param data Any additional data to pass along to the upload.
|
|
40
|
+
*
|
|
41
|
+
* @returns promise
|
|
42
|
+
*/
|
|
43
|
+
public static createWithFile<T>(file: File, data?: object): AxiosPromise<Response<T>> {
|
|
44
44
|
|
|
45
45
|
return Requests.uploadFile(PostsRoute.routes.create.url, 'file', file, data);
|
|
46
46
|
}
|
|
@@ -55,11 +55,66 @@ class Posts {
|
|
|
55
55
|
*
|
|
56
56
|
* @returns promise
|
|
57
57
|
*/
|
|
58
|
-
public static createWithBlob<T>(blob
|
|
58
|
+
public static createWithBlob<T>(blob: Blob, data?: object): AxiosPromise<Response<T>> {
|
|
59
59
|
|
|
60
60
|
return Requests.uploadBlob(PostsRoute.routes.create.url, 'file', blob, data);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Create a new post with a file divided into chunks.
|
|
65
|
+
*
|
|
66
|
+
* @param file The file object to upload.
|
|
67
|
+
* @param chunkSize Size of each chunk in bytes. Default is 1MB.
|
|
68
|
+
* @param data Any additional data to pass along to the upload.
|
|
69
|
+
*
|
|
70
|
+
* @returns Promise
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* Create a new post with a file divided into chunks.
|
|
74
|
+
*
|
|
75
|
+
* @param file The file object to upload.
|
|
76
|
+
* @param chunkSize Size of each chunk in bytes. Default is 1MB.
|
|
77
|
+
* @param data Any additional data to pass along to the upload.
|
|
78
|
+
*
|
|
79
|
+
* @returns Promise
|
|
80
|
+
*/
|
|
81
|
+
public static async createWithFileInChunks<T>(file: File, chunkSize: number = 1 * 1024 * 1024, data: { [key: string]: any } = {}): Promise<AxiosPromise<Response<T>>> {
|
|
82
|
+
const totalChunks = Math.ceil(file.size / chunkSize);
|
|
83
|
+
let lastResponse: AxiosPromise<Response<T>> | undefined;
|
|
84
|
+
|
|
85
|
+
for (let i = 0; i < totalChunks; i++) {
|
|
86
|
+
const start = i * chunkSize;
|
|
87
|
+
const end = start + chunkSize;
|
|
88
|
+
const chunk = file.slice(start, end);
|
|
89
|
+
|
|
90
|
+
const formData = new FormData();
|
|
91
|
+
formData.append('file', chunk, `${i}-${file.name}`); // Naming chunks as index-filename for identification
|
|
92
|
+
formData.append('totalChunks', totalChunks.toString());
|
|
93
|
+
formData.append('currentChunk', i.toString());
|
|
94
|
+
|
|
95
|
+
// merge any other data if provided
|
|
96
|
+
for (let key in data) {
|
|
97
|
+
formData.append(key, data[key]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// If it's the last chunk, save the response
|
|
101
|
+
if (i === totalChunks - 1) {
|
|
102
|
+
await Requests.uploadFile(PostsRoute.routes.create.url, 'file', chunk, formData);
|
|
103
|
+
} else {
|
|
104
|
+
await Requests.uploadFile(PostsRoute.routes.create.url, 'file', chunk, formData);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!lastResponse) {
|
|
109
|
+
throw new Error("No response from the last chunk upload");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return lastResponse;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
63
118
|
|
|
64
119
|
/**
|
|
65
120
|
* Update a post.
|
|
@@ -71,9 +126,9 @@ class Posts {
|
|
|
71
126
|
*
|
|
72
127
|
* @returns promise
|
|
73
128
|
*/
|
|
74
|
-
public static update<T>(post_id
|
|
129
|
+
public static update<T>(post_id: string, data: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
75
130
|
|
|
76
|
-
return Requests.processRoute(PostsRoute.routes.update, data, {post_id
|
|
131
|
+
return Requests.processRoute(PostsRoute.routes.update, data, { post_id: post_id }, params);
|
|
77
132
|
}
|
|
78
133
|
|
|
79
134
|
/**
|
|
@@ -85,9 +140,9 @@ class Posts {
|
|
|
85
140
|
*
|
|
86
141
|
* @returns promise
|
|
87
142
|
*/
|
|
88
|
-
public static view<T>(post_id
|
|
143
|
+
public static view<T>(post_id: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
89
144
|
|
|
90
|
-
return Requests.processRoute(PostsRoute.routes.view, {}, {post_id
|
|
145
|
+
return Requests.processRoute(PostsRoute.routes.view, {}, { post_id: post_id }, params);
|
|
91
146
|
}
|
|
92
147
|
|
|
93
148
|
/**
|
|
@@ -98,9 +153,9 @@ class Posts {
|
|
|
98
153
|
* @param post_id The id of the post to delete.
|
|
99
154
|
* @returns promise
|
|
100
155
|
*/
|
|
101
|
-
public static delete<T>(post_id
|
|
156
|
+
public static delete<T>(post_id: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
102
157
|
|
|
103
|
-
return Requests.processRoute(PostsRoute.routes.delete, {}, {post_id
|
|
158
|
+
return Requests.processRoute(PostsRoute.routes.delete, {}, { post_id: post_id }, params);
|
|
104
159
|
}
|
|
105
160
|
|
|
106
161
|
/**
|
|
@@ -112,9 +167,9 @@ class Posts {
|
|
|
112
167
|
*
|
|
113
168
|
* @returns Promise
|
|
114
169
|
*/
|
|
115
|
-
public static toggleInteraction<T>(post_id
|
|
170
|
+
public static toggleInteraction<T>(post_id: string, data: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
116
171
|
|
|
117
|
-
return Requests.processRoute(PostsRoute.routes.toggleInteraction, data, {post_id
|
|
172
|
+
return Requests.processRoute(PostsRoute.routes.toggleInteraction, data, { post_id: post_id }, params);
|
|
118
173
|
}
|
|
119
174
|
|
|
120
175
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import SocialPostsRoute from "../routes/SocialPostsRoute";
|
|
2
|
+
import Requests from "../util/Requests";
|
|
3
|
+
import Response from "../util/Response";
|
|
4
|
+
import { AxiosPromise } from "axios";
|
|
5
|
+
|
|
6
|
+
class SocialPosts {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* List all the Posts.
|
|
10
|
+
*
|
|
11
|
+
* @see https://api.glitch.fun/api/documentation#/Post%20Route/resourcePostList
|
|
12
|
+
*
|
|
13
|
+
* @returns promise
|
|
14
|
+
*/
|
|
15
|
+
public static list<T>(params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
16
|
+
return Requests.processRoute(SocialPostsRoute.routes.getPosts, undefined, undefined, params);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Give a tip to another user
|
|
21
|
+
*
|
|
22
|
+
* @see https://api.glitch.fun/api/documentation#/Authentication%20Route/authLogin
|
|
23
|
+
*
|
|
24
|
+
* @returns A promise
|
|
25
|
+
*/
|
|
26
|
+
public static create<T>(data? : object, params?: Record<string, any>) : AxiosPromise<Response<T>> {
|
|
27
|
+
return Requests.processRoute(SocialPostsRoute.routes.create, data, {}, params);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Retrieve the information for a single post.
|
|
32
|
+
*
|
|
33
|
+
* @see https://api.glitch.fun/api/documentation#/Post%20Route/showPostStorage
|
|
34
|
+
*
|
|
35
|
+
* @param post_id The id fo the post to retrieve.
|
|
36
|
+
*
|
|
37
|
+
* @returns promise
|
|
38
|
+
*/
|
|
39
|
+
public static view<T>(post_id: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
40
|
+
|
|
41
|
+
return Requests.processRoute(SocialPostsRoute.routes.retrievePost, {}, { post_id: post_id }, params);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default SocialPosts;
|
package/src/api/Users.ts
CHANGED
|
@@ -231,6 +231,30 @@ class Users {
|
|
|
231
231
|
return Requests.processRoute(UserRoutes.routes.clearYoutubeAuth, {});
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Clear Reddit authentication information from the current user.
|
|
236
|
+
*
|
|
237
|
+
* @see https://api.glitch.fun/api/documentation#/Users%20Route/userCreateDonationPage
|
|
238
|
+
*
|
|
239
|
+
* @returns promise
|
|
240
|
+
*/
|
|
241
|
+
public static clearRedditAuth<T>(): AxiosPromise<Response<T>> {
|
|
242
|
+
|
|
243
|
+
return Requests.processRoute(UserRoutes.routes.clearRedditAuth, {});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Clear Twitter authentication information from the current user.
|
|
248
|
+
*
|
|
249
|
+
* @see https://api.glitch.fun/api/documentation#/Users%20Route/userCreateDonationPage
|
|
250
|
+
*
|
|
251
|
+
* @returns promise
|
|
252
|
+
*/
|
|
253
|
+
public static clearTwitterAuth<T>(): AxiosPromise<Response<T>> {
|
|
254
|
+
|
|
255
|
+
return Requests.processRoute(UserRoutes.routes.clearTwitterAuth, {});
|
|
256
|
+
}
|
|
257
|
+
|
|
234
258
|
/**
|
|
235
259
|
* Clear StreamElements authentication information from the current user.
|
|
236
260
|
*
|
package/src/api/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import Tips from "./Tips";
|
|
|
13
13
|
import TipEmojis from "./TipEmojis";
|
|
14
14
|
import TipPackages from "./TipPackages";
|
|
15
15
|
import TipPackagePurchases from "./TipPackagePurchases";
|
|
16
|
+
import SocialPosts from "./SocialPosts";
|
|
16
17
|
|
|
17
18
|
export {Auth};
|
|
18
19
|
export {Competitions};
|
|
@@ -28,4 +29,5 @@ export {Utility};
|
|
|
28
29
|
export {Tips};
|
|
29
30
|
export {TipEmojis};
|
|
30
31
|
export {TipPackages};
|
|
31
|
-
export {TipPackagePurchases}
|
|
32
|
+
export {TipPackagePurchases};
|
|
33
|
+
export {SocialPosts};
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Route from "./interface";
|
|
2
|
+
import HTTP_METHODS from "../constants/HttpMethods";
|
|
3
|
+
|
|
4
|
+
class SocialPostsRoute {
|
|
5
|
+
|
|
6
|
+
public static routes: { [key: string]: Route } = {
|
|
7
|
+
getPosts: { url: '/socialposts', method: HTTP_METHODS.GET },
|
|
8
|
+
createPost: { url: '/socialposts', method: HTTP_METHODS.POST },
|
|
9
|
+
retrievePost : { url: '/socialposts/{post_id}', method: HTTP_METHODS.GET },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default SocialPostsRoute;
|
package/src/routes/UserRoutes.ts
CHANGED
|
@@ -19,6 +19,8 @@ class UserRoutes {
|
|
|
19
19
|
clearStripeAuth : { url: '/users/clearStripeAuth', method: HTTP_METHODS.DELETE },
|
|
20
20
|
clearTikTokAuth : { url: '/users/clearTikTokAuth', method: HTTP_METHODS.DELETE },
|
|
21
21
|
clearYoutubeAuth : { url: '/users/clearYoutubeAuth', method: HTTP_METHODS.DELETE },
|
|
22
|
+
clearRedditAuth : { url: '/users/clearRedditAuth', method: HTTP_METHODS.DELETE },
|
|
23
|
+
clearTwitterAuth : { url: '/users/clearTwitterAuth', method: HTTP_METHODS.DELETE },
|
|
22
24
|
clearStreamElementsAuth : { url: '/users/clearStreamElementsAuth', method: HTTP_METHODS.DELETE },
|
|
23
25
|
getTipsReceivedForMonth : { url: '/users/getTipsReceivedForMonth', method: HTTP_METHODS.GET },
|
|
24
26
|
getTipsGivenForMonth : { url: '/users/getTipsGivenForMonth', method: HTTP_METHODS.GET },
|