glitch-javascript-sdk 0.7.7 → 0.7.9
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 +144 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/Feedback.d.ts +51 -0
- package/dist/esm/api/Social.d.ts +1 -0
- package/dist/esm/api/index.d.ts +2 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +144 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/routes/FeedbackRoute.d.ts +7 -0
- package/dist/esm/util/Requests.d.ts +1 -0
- package/dist/index.d.ts +52 -0
- package/package.json +2 -1
- package/src/api/Feedback.ts +80 -0
- package/src/api/Social.ts +9 -0
- package/src/api/index.ts +3 -1
- package/src/index.ts +2 -0
- package/src/routes/FeedbackRoute.ts +14 -0
- package/src/routes/MessagesRoute.ts +2 -2
- package/src/routes/SocialRoute.ts +1 -0
- package/src/util/Requests.ts +72 -0
|
@@ -18,6 +18,7 @@ declare class Requests {
|
|
|
18
18
|
static delete<T>(url: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
19
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
|
+
static uploadFileInChunks<T>(file: File, uploadUrl: string, onProgress?: (totalSize: number, amountUploaded: number) => void, data?: any, chunkSize?: number): Promise<void>;
|
|
21
22
|
static processRoute<T>(route: Route, data?: object, routeReplace?: {
|
|
22
23
|
[key: string]: any;
|
|
23
24
|
}, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1823,6 +1823,7 @@ declare class Social {
|
|
|
1823
1823
|
static postVideoToTikTokBlob<T>(blob: Blob, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
1824
1824
|
static postVideoToFacebookGroupFile<T>(file: File, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
1825
1825
|
static postVideoToFacebookGroupBlob<T>(blob: Blob, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
1826
|
+
static postVideoToTwitter<T>(file: File, data?: object, onProgress?: (totalSize: number, amountUploaded: number) => void, params?: Record<string, any>): Promise<void>;
|
|
1826
1827
|
}
|
|
1827
1828
|
|
|
1828
1829
|
declare class Templates {
|
|
@@ -2495,6 +2496,55 @@ declare class Messages {
|
|
|
2495
2496
|
static createOrGetThread<T>(data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2496
2497
|
}
|
|
2497
2498
|
|
|
2499
|
+
declare class Feedback {
|
|
2500
|
+
/**
|
|
2501
|
+
* List all the feedback that been left by users.
|
|
2502
|
+
*
|
|
2503
|
+
* @see https://api.glitch.fun/api/documentation#/Feedback/listFeedback
|
|
2504
|
+
*
|
|
2505
|
+
* @returns promise
|
|
2506
|
+
*/
|
|
2507
|
+
static listFeedback<T>(params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2508
|
+
/**
|
|
2509
|
+
* View a particular item of feedback.
|
|
2510
|
+
*
|
|
2511
|
+
* @see https://api.glitch.fun/api/documentation#/Feedback/getFeedbackById
|
|
2512
|
+
*
|
|
2513
|
+
* @returns promise
|
|
2514
|
+
*/
|
|
2515
|
+
static viewFeedback<T>(feedback_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2516
|
+
/**
|
|
2517
|
+
* Submit feedback.
|
|
2518
|
+
*
|
|
2519
|
+
* @see https://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
|
|
2520
|
+
*
|
|
2521
|
+
* @returns A promise
|
|
2522
|
+
*/
|
|
2523
|
+
static sendFeedback<T>(data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2524
|
+
/**
|
|
2525
|
+
* Submit feedback with the log file as a file.
|
|
2526
|
+
*
|
|
2527
|
+
* @see https://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
|
|
2528
|
+
*
|
|
2529
|
+
* @param file The file object to upload.
|
|
2530
|
+
* @param data Any additional data to pass along to the upload.
|
|
2531
|
+
*
|
|
2532
|
+
* @returns promise
|
|
2533
|
+
*/
|
|
2534
|
+
static sendFeedbackWithFile<T>(file: File, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2535
|
+
/**
|
|
2536
|
+
* Submit feedback with the log file as a blob.
|
|
2537
|
+
*
|
|
2538
|
+
* @see hhttps://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
|
|
2539
|
+
*
|
|
2540
|
+
* @param blob The blob to upload.
|
|
2541
|
+
* @param data Any additional data to pass along to the upload
|
|
2542
|
+
*
|
|
2543
|
+
* @returns promise
|
|
2544
|
+
*/
|
|
2545
|
+
static sendFeedbackWithBlob<T>(blob: Blob, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2546
|
+
}
|
|
2547
|
+
|
|
2498
2548
|
interface Route {
|
|
2499
2549
|
url: string;
|
|
2500
2550
|
method: string;
|
|
@@ -2516,6 +2566,7 @@ declare class Requests {
|
|
|
2516
2566
|
static delete<T>(url: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2517
2567
|
static uploadFile<T>(url: string, filename: string, file: File | Blob, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2518
2568
|
static uploadBlob<T>(url: string, filename: string, blob: Blob, data?: any, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
2569
|
+
static uploadFileInChunks<T>(file: File, uploadUrl: string, onProgress?: (totalSize: number, amountUploaded: number) => void, data?: any, chunkSize?: number): Promise<void>;
|
|
2519
2570
|
static processRoute<T>(route: Route, data?: object, routeReplace?: {
|
|
2520
2571
|
[key: string]: any;
|
|
2521
2572
|
}, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
@@ -2799,6 +2850,7 @@ declare class Glitch {
|
|
|
2799
2850
|
Communities: typeof Communities;
|
|
2800
2851
|
Users: typeof Users;
|
|
2801
2852
|
Events: typeof Events;
|
|
2853
|
+
Feedback: typeof Feedback;
|
|
2802
2854
|
Teams: typeof Teams;
|
|
2803
2855
|
Posts: typeof Posts;
|
|
2804
2856
|
Messages: typeof Messages;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glitch-javascript-sdk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.9",
|
|
4
4
|
"description": "Javascript SDK for Glitch",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"axios": "^1.6.2",
|
|
39
39
|
"buffer": "^6.0.3",
|
|
40
|
+
"crypto-js": "^4.2.0",
|
|
40
41
|
"fast-text-encoding": "^1.0.6",
|
|
41
42
|
"fetch-blob": "^4.0.0",
|
|
42
43
|
"isomorphic-form-data": "^2.0.0",
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import FeedbackRoute from "../routes/FeedbackRoute";
|
|
2
|
+
import Requests from "../util/Requests";
|
|
3
|
+
import Response from "../util/Response";
|
|
4
|
+
import { AxiosPromise } from "axios";
|
|
5
|
+
|
|
6
|
+
class Feedback {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* List all the feedback that been left by users.
|
|
10
|
+
*
|
|
11
|
+
* @see https://api.glitch.fun/api/documentation#/Feedback/listFeedback
|
|
12
|
+
*
|
|
13
|
+
* @returns promise
|
|
14
|
+
*/
|
|
15
|
+
public static listFeedback<T>(params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
16
|
+
return Requests.processRoute(FeedbackRoute.routes.listFeedback, undefined, undefined, params);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* View a particular item of feedback.
|
|
21
|
+
*
|
|
22
|
+
* @see https://api.glitch.fun/api/documentation#/Feedback/getFeedbackById
|
|
23
|
+
*
|
|
24
|
+
* @returns promise
|
|
25
|
+
*/
|
|
26
|
+
public static viewFeedback<T>(feedback_id: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
27
|
+
return Requests.processRoute(FeedbackRoute.routes.viewFeedback, undefined, { feedback_id: feedback_id }, params);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Submit feedback.
|
|
32
|
+
*
|
|
33
|
+
* @see https://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
|
|
34
|
+
*
|
|
35
|
+
* @returns A promise
|
|
36
|
+
*/
|
|
37
|
+
public static sendFeedback<T>(data?: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
38
|
+
return Requests.processRoute(FeedbackRoute.routes.sendFeedback, data, {}, params);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Submit feedback with the log file as a file.
|
|
45
|
+
*
|
|
46
|
+
* @see https://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
|
|
47
|
+
*
|
|
48
|
+
* @param file The file object to upload.
|
|
49
|
+
* @param data Any additional data to pass along to the upload.
|
|
50
|
+
*
|
|
51
|
+
* @returns promise
|
|
52
|
+
*/
|
|
53
|
+
public static sendFeedbackWithFile<T>(file: File, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
54
|
+
|
|
55
|
+
let url = FeedbackRoute.routes.sendFeedback.url;
|
|
56
|
+
|
|
57
|
+
return Requests.uploadFile(url, 'image', file, data);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Submit feedback with the log file as a blob.
|
|
62
|
+
*
|
|
63
|
+
* @see hhttps://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
|
|
64
|
+
*
|
|
65
|
+
* @param blob The blob to upload.
|
|
66
|
+
* @param data Any additional data to pass along to the upload
|
|
67
|
+
*
|
|
68
|
+
* @returns promise
|
|
69
|
+
*/
|
|
70
|
+
public static sendFeedbackWithBlob<T>(blob: Blob, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
71
|
+
|
|
72
|
+
let url = FeedbackRoute.routes.sendFeedback.url;
|
|
73
|
+
|
|
74
|
+
return Requests.uploadBlob(url, 'image', blob, data);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default Feedback;
|
package/src/api/Social.ts
CHANGED
|
@@ -41,7 +41,16 @@ class Social {
|
|
|
41
41
|
return Requests.uploadBlob(url, 'video', blob, data);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
public static postVideoToTwitter<T>(file: File, data? : object, onProgress ?: (totalSize: number, amountUploaded: number) => void, params?: Record<string, any>) : Promise<void> {
|
|
44
45
|
|
|
46
|
+
let url = SocialRoute.routes.postVideoToTwitter.url;
|
|
47
|
+
|
|
48
|
+
return Requests.uploadFileInChunks(file, url, onProgress, data);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
45
54
|
|
|
46
55
|
}
|
|
47
56
|
|
package/src/api/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ import Titles from "./Titles";
|
|
|
18
18
|
import Campaigns from "./Campaigns";
|
|
19
19
|
import Subscriptions from "./Subscriptions";
|
|
20
20
|
import Messages from "./Messages";
|
|
21
|
+
import Feedback from "./Feedback";
|
|
21
22
|
|
|
22
23
|
export {Auth};
|
|
23
24
|
export {Competitions};
|
|
@@ -38,4 +39,5 @@ export {SocialPosts};
|
|
|
38
39
|
export {Titles};
|
|
39
40
|
export {Campaigns};
|
|
40
41
|
export {Subscriptions};
|
|
41
|
-
export {Messages};
|
|
42
|
+
export {Messages};
|
|
43
|
+
export {Feedback};
|
package/src/index.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {Titles} from "./api";
|
|
|
22
22
|
import {Campaigns} from "./api";
|
|
23
23
|
import {Subscriptions} from "./api";
|
|
24
24
|
import {Messages} from "./api";
|
|
25
|
+
import {Feedback} from "./api";
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
|
|
@@ -61,6 +62,7 @@ class Glitch {
|
|
|
61
62
|
Communities : Communities,
|
|
62
63
|
Users: Users,
|
|
63
64
|
Events: Events,
|
|
65
|
+
Feedback : Feedback,
|
|
64
66
|
Teams: Teams,
|
|
65
67
|
Posts: Posts,
|
|
66
68
|
Messages : Messages,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Route from "./interface";
|
|
2
|
+
import HTTP_METHODS from "../constants/HttpMethods";
|
|
3
|
+
|
|
4
|
+
class FeedbackRoute {
|
|
5
|
+
|
|
6
|
+
public static routes: { [key: string]: Route } = {
|
|
7
|
+
listFeedback: { url: '/feedback', method: HTTP_METHODS.GET },
|
|
8
|
+
sendFeedback: { url: '/feedback', method: HTTP_METHODS.POST },
|
|
9
|
+
viewFeedback: { url: '/feedback/{feedback_id}', method: HTTP_METHODS.GET },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default FeedbackRoute;
|
|
@@ -5,8 +5,8 @@ class MessagesRoute {
|
|
|
5
5
|
|
|
6
6
|
public static routes: { [key: string]: Route } = {
|
|
7
7
|
listMessageThreads: { url: '/messages', method: HTTP_METHODS.GET },
|
|
8
|
-
sendMessage: { url: '/
|
|
9
|
-
deleteMessage: { url: '/
|
|
8
|
+
sendMessage: { url: '/messages', method: HTTP_METHODS.POST },
|
|
9
|
+
deleteMessage: { url: '/messages/{message_id}', method: HTTP_METHODS.DELETE },
|
|
10
10
|
createOrGetThread: { url: '/messages/makeThread', method: HTTP_METHODS.POST },
|
|
11
11
|
};
|
|
12
12
|
|
|
@@ -6,6 +6,7 @@ class SocialRoute {
|
|
|
6
6
|
public static routes: { [key: string]: Route } = {
|
|
7
7
|
postVideoToTikTok: { url: '/social/postVideoToTikTok', method: HTTP_METHODS.POST },
|
|
8
8
|
postVideoToFacebookGroup: { url: '/social/postVideoToFacebookGroup', method: HTTP_METHODS.POST },
|
|
9
|
+
postVideoToTwitter: { url: '/social/postVideoToTwitter', method: HTTP_METHODS.POST },
|
|
9
10
|
};
|
|
10
11
|
|
|
11
12
|
}
|
package/src/util/Requests.ts
CHANGED
|
@@ -3,6 +3,8 @@ 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 * as crypto from 'crypto';
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
class Requests {
|
|
8
10
|
private static config: Config;
|
|
@@ -197,6 +199,76 @@ class Requests {
|
|
|
197
199
|
return Requests.request<T>('POST', url, data, formData);
|
|
198
200
|
}
|
|
199
201
|
|
|
202
|
+
// Method adapted for browser environments
|
|
203
|
+
|
|
204
|
+
public static async uploadFileInChunks<T>(
|
|
205
|
+
file: File,
|
|
206
|
+
uploadUrl: string,
|
|
207
|
+
onProgress?: (totalSize: number, amountUploaded: number) => void,
|
|
208
|
+
data?: any,
|
|
209
|
+
chunkSize ?: number, // Default chunk size of 1MB
|
|
210
|
+
): Promise<void> {
|
|
211
|
+
|
|
212
|
+
if(!chunkSize) {
|
|
213
|
+
chunkSize = 1024 * 1024
|
|
214
|
+
}
|
|
215
|
+
const fileSize = file.size;
|
|
216
|
+
const totalChunks = Math.ceil(fileSize / chunkSize);
|
|
217
|
+
let currentChunkIndex = 0;
|
|
218
|
+
let totalUploaded = 0; // Keep track of the total uploaded bytes
|
|
219
|
+
|
|
220
|
+
// Generate a unique identifier for this upload session using the Web Cryptography API
|
|
221
|
+
const array = new Uint32Array(4);
|
|
222
|
+
window.crypto.getRandomValues(array);
|
|
223
|
+
const identifier = Array.from(array, dec => ('0' + dec.toString(16)).substr(-2)).join('');
|
|
224
|
+
|
|
225
|
+
while (currentChunkIndex < totalChunks) {
|
|
226
|
+
const start = currentChunkIndex * chunkSize;
|
|
227
|
+
const end = Math.min(start + chunkSize, fileSize);
|
|
228
|
+
const chunk = file.slice(start, end);
|
|
229
|
+
|
|
230
|
+
const formData = new FormData();
|
|
231
|
+
formData.append('video', chunk, file.name);
|
|
232
|
+
formData.append('chunkIndex', currentChunkIndex.toString());
|
|
233
|
+
formData.append('totalChunks', totalChunks.toString());
|
|
234
|
+
formData.append('identifier', identifier);
|
|
235
|
+
|
|
236
|
+
// If there's additional data, append each key-value pair to the formData
|
|
237
|
+
if (data) {
|
|
238
|
+
for (const key in data) {
|
|
239
|
+
formData.append(key, data[key]);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Construct the full URL if necessary or use a method to determine the base URL
|
|
244
|
+
const fullUploadUrl = `${Requests.baseUrl}${uploadUrl}`;
|
|
245
|
+
|
|
246
|
+
// Make sure the authorization token is included if required
|
|
247
|
+
const headers: { [key: string]: string } = {};
|
|
248
|
+
if (Requests.authToken) {
|
|
249
|
+
headers['Authorization'] = `Bearer ${Requests.authToken}`;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Perform the upload
|
|
253
|
+
await axios.post(fullUploadUrl, formData, {
|
|
254
|
+
headers,
|
|
255
|
+
onUploadProgress: (progressEvent) => {
|
|
256
|
+
const currentChunkProgress = progressEvent.loaded; // Bytes uploaded of the current chunk
|
|
257
|
+
// Calculate the total uploaded size including previous chunks and the current chunk's progress
|
|
258
|
+
const totalProgress = totalUploaded + currentChunkProgress;
|
|
259
|
+
|
|
260
|
+
if(onProgress){
|
|
261
|
+
onProgress(fileSize, totalProgress);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
currentChunkIndex++;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
200
272
|
public static processRoute<T>(route: Route, data?: object, routeReplace?: { [key: string]: any }, params?: Record<string, any>): AxiosPromise<Response<T>> {
|
|
201
273
|
let url = route.url;
|
|
202
274
|
|