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.
@@ -0,0 +1,51 @@
1
+ import Response from "../util/Response";
2
+ import { AxiosPromise } from "axios";
3
+ declare class Feedback {
4
+ /**
5
+ * List all the feedback that been left by users.
6
+ *
7
+ * @see https://api.glitch.fun/api/documentation#/Feedback/listFeedback
8
+ *
9
+ * @returns promise
10
+ */
11
+ static listFeedback<T>(params?: Record<string, any>): AxiosPromise<Response<T>>;
12
+ /**
13
+ * View a particular item of feedback.
14
+ *
15
+ * @see https://api.glitch.fun/api/documentation#/Feedback/getFeedbackById
16
+ *
17
+ * @returns promise
18
+ */
19
+ static viewFeedback<T>(feedback_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
20
+ /**
21
+ * Submit feedback.
22
+ *
23
+ * @see https://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
24
+ *
25
+ * @returns A promise
26
+ */
27
+ static sendFeedback<T>(data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
28
+ /**
29
+ * Submit feedback with the log file as a file.
30
+ *
31
+ * @see https://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
32
+ *
33
+ * @param file The file object to upload.
34
+ * @param data Any additional data to pass along to the upload.
35
+ *
36
+ * @returns promise
37
+ */
38
+ static sendFeedbackWithFile<T>(file: File, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
39
+ /**
40
+ * Submit feedback with the log file as a blob.
41
+ *
42
+ * @see hhttps://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
43
+ *
44
+ * @param blob The blob to upload.
45
+ * @param data Any additional data to pass along to the upload
46
+ *
47
+ * @returns promise
48
+ */
49
+ static sendFeedbackWithBlob<T>(blob: Blob, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
50
+ }
51
+ export default Feedback;
@@ -12,5 +12,6 @@ declare class Social {
12
12
  static postVideoToTikTokBlob<T>(blob: Blob, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
13
13
  static postVideoToFacebookGroupFile<T>(file: File, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
14
14
  static postVideoToFacebookGroupBlob<T>(blob: Blob, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
15
+ static postVideoToTwitter<T>(file: File, data?: object, onProgress?: (totalSize: number, amountUploaded: number) => void, params?: Record<string, any>): Promise<void>;
15
16
  }
16
17
  export default Social;
@@ -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
  export { Auth };
22
23
  export { Competitions };
23
24
  export { Communities };
@@ -38,3 +39,4 @@ export { Titles };
38
39
  export { Campaigns };
39
40
  export { Subscriptions };
40
41
  export { Messages };
42
+ export { Feedback };
@@ -18,6 +18,7 @@ import { Titles } from "./api";
18
18
  import { Campaigns } from "./api";
19
19
  import { Subscriptions } from "./api";
20
20
  import { Messages } from "./api";
21
+ import { Feedback } from "./api";
21
22
  import Requests from "./util/Requests";
22
23
  import Parser from "./util/Parser";
23
24
  import Session from "./util/Session";
@@ -43,6 +44,7 @@ declare class Glitch {
43
44
  Communities: typeof Communities;
44
45
  Users: typeof Users;
45
46
  Events: typeof Events;
47
+ Feedback: typeof Feedback;
46
48
  Teams: typeof Teams;
47
49
  Posts: typeof Posts;
48
50
  Messages: typeof Messages;
package/dist/esm/index.js CHANGED
@@ -5450,6 +5450,67 @@ var Requests = /** @class */ (function () {
5450
5450
  }
5451
5451
  return Requests.request('POST', url, data, formData);
5452
5452
  };
5453
+ // Method adapted for browser environments
5454
+ Requests.uploadFileInChunks = function (file, uploadUrl, onProgress, data, chunkSize) {
5455
+ return __awaiter(this, void 0, void 0, function () {
5456
+ var fileSize, totalChunks, currentChunkIndex, totalUploaded, array, identifier, start, end, chunk, formData, key, fullUploadUrl, headers;
5457
+ return __generator(this, function (_a) {
5458
+ switch (_a.label) {
5459
+ case 0:
5460
+ if (!chunkSize) {
5461
+ chunkSize = 1024 * 1024;
5462
+ }
5463
+ fileSize = file.size;
5464
+ totalChunks = Math.ceil(fileSize / chunkSize);
5465
+ currentChunkIndex = 0;
5466
+ totalUploaded = 0;
5467
+ array = new Uint32Array(4);
5468
+ window.crypto.getRandomValues(array);
5469
+ identifier = Array.from(array, function (dec) { return ('0' + dec.toString(16)).substr(-2); }).join('');
5470
+ _a.label = 1;
5471
+ case 1:
5472
+ if (!(currentChunkIndex < totalChunks)) return [3 /*break*/, 3];
5473
+ start = currentChunkIndex * chunkSize;
5474
+ end = Math.min(start + chunkSize, fileSize);
5475
+ chunk = file.slice(start, end);
5476
+ formData = new FormData();
5477
+ formData.append('video', chunk, file.name);
5478
+ formData.append('chunkIndex', currentChunkIndex.toString());
5479
+ formData.append('totalChunks', totalChunks.toString());
5480
+ formData.append('identifier', identifier);
5481
+ // If there's additional data, append each key-value pair to the formData
5482
+ if (data) {
5483
+ for (key in data) {
5484
+ formData.append(key, data[key]);
5485
+ }
5486
+ }
5487
+ fullUploadUrl = "".concat(Requests.baseUrl).concat(uploadUrl);
5488
+ headers = {};
5489
+ if (Requests.authToken) {
5490
+ headers['Authorization'] = "Bearer ".concat(Requests.authToken);
5491
+ }
5492
+ // Perform the upload
5493
+ return [4 /*yield*/, axios$1.post(fullUploadUrl, formData, {
5494
+ headers: headers,
5495
+ onUploadProgress: function (progressEvent) {
5496
+ var currentChunkProgress = progressEvent.loaded; // Bytes uploaded of the current chunk
5497
+ // Calculate the total uploaded size including previous chunks and the current chunk's progress
5498
+ var totalProgress = totalUploaded + currentChunkProgress;
5499
+ if (onProgress) {
5500
+ onProgress(fileSize, totalProgress);
5501
+ }
5502
+ }
5503
+ })];
5504
+ case 2:
5505
+ // Perform the upload
5506
+ _a.sent();
5507
+ currentChunkIndex++;
5508
+ return [3 /*break*/, 1];
5509
+ case 3: return [2 /*return*/];
5510
+ }
5511
+ });
5512
+ });
5513
+ };
5453
5514
  Requests.processRoute = function (route, data, routeReplace, params) {
5454
5515
  var url = route.url;
5455
5516
  if (routeReplace) {
@@ -8112,6 +8173,7 @@ var SocialRoute = /** @class */ (function () {
8112
8173
  SocialRoute.routes = {
8113
8174
  postVideoToTikTok: { url: '/social/postVideoToTikTok', method: HTTP_METHODS.POST },
8114
8175
  postVideoToFacebookGroup: { url: '/social/postVideoToFacebookGroup', method: HTTP_METHODS.POST },
8176
+ postVideoToTwitter: { url: '/social/postVideoToTwitter', method: HTTP_METHODS.POST },
8115
8177
  };
8116
8178
  return SocialRoute;
8117
8179
  }());
@@ -8142,6 +8204,10 @@ var Social = /** @class */ (function () {
8142
8204
  var url = SocialRoute.routes.postVideoToFacebookGroup.url;
8143
8205
  return Requests.uploadBlob(url, 'video', blob, data);
8144
8206
  };
8207
+ Social.postVideoToTwitter = function (file, data, onProgress, params) {
8208
+ var url = SocialRoute.routes.postVideoToTwitter.url;
8209
+ return Requests.uploadFileInChunks(file, url, onProgress, data);
8210
+ };
8145
8211
  return Social;
8146
8212
  }());
8147
8213
 
@@ -9090,8 +9156,8 @@ var MessagesRoute = /** @class */ (function () {
9090
9156
  }
9091
9157
  MessagesRoute.routes = {
9092
9158
  listMessageThreads: { url: '/messages', method: HTTP_METHODS.GET },
9093
- sendMessage: { url: '/message', method: HTTP_METHODS.POST },
9094
- deleteMessage: { url: '/message/{message_id}', method: HTTP_METHODS.DELETE },
9159
+ sendMessage: { url: '/messages', method: HTTP_METHODS.POST },
9160
+ deleteMessage: { url: '/messages/{message_id}', method: HTTP_METHODS.DELETE },
9095
9161
  createOrGetThread: { url: '/messages/makeThread', method: HTTP_METHODS.POST },
9096
9162
  };
9097
9163
  return MessagesRoute;
@@ -9144,6 +9210,81 @@ var Messages = /** @class */ (function () {
9144
9210
  return Messages;
9145
9211
  }());
9146
9212
 
9213
+ var FeedbackRoute = /** @class */ (function () {
9214
+ function FeedbackRoute() {
9215
+ }
9216
+ FeedbackRoute.routes = {
9217
+ listFeedback: { url: '/feedback', method: HTTP_METHODS.GET },
9218
+ sendFeedback: { url: '/feedback', method: HTTP_METHODS.POST },
9219
+ viewFeedback: { url: '/feedback/{feedback_id}', method: HTTP_METHODS.GET },
9220
+ };
9221
+ return FeedbackRoute;
9222
+ }());
9223
+
9224
+ var Feedback = /** @class */ (function () {
9225
+ function Feedback() {
9226
+ }
9227
+ /**
9228
+ * List all the feedback that been left by users.
9229
+ *
9230
+ * @see https://api.glitch.fun/api/documentation#/Feedback/listFeedback
9231
+ *
9232
+ * @returns promise
9233
+ */
9234
+ Feedback.listFeedback = function (params) {
9235
+ return Requests.processRoute(FeedbackRoute.routes.listFeedback, undefined, undefined, params);
9236
+ };
9237
+ /**
9238
+ * View a particular item of feedback.
9239
+ *
9240
+ * @see https://api.glitch.fun/api/documentation#/Feedback/getFeedbackById
9241
+ *
9242
+ * @returns promise
9243
+ */
9244
+ Feedback.viewFeedback = function (feedback_id, params) {
9245
+ return Requests.processRoute(FeedbackRoute.routes.viewFeedback, undefined, { feedback_id: feedback_id }, params);
9246
+ };
9247
+ /**
9248
+ * Submit feedback.
9249
+ *
9250
+ * @see https://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
9251
+ *
9252
+ * @returns A promise
9253
+ */
9254
+ Feedback.sendFeedback = function (data, params) {
9255
+ return Requests.processRoute(FeedbackRoute.routes.sendFeedback, data, {}, params);
9256
+ };
9257
+ /**
9258
+ * Submit feedback with the log file as a file.
9259
+ *
9260
+ * @see https://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
9261
+ *
9262
+ * @param file The file object to upload.
9263
+ * @param data Any additional data to pass along to the upload.
9264
+ *
9265
+ * @returns promise
9266
+ */
9267
+ Feedback.sendFeedbackWithFile = function (file, data, params) {
9268
+ var url = FeedbackRoute.routes.sendFeedback.url;
9269
+ return Requests.uploadFile(url, 'image', file, data);
9270
+ };
9271
+ /**
9272
+ * Submit feedback with the log file as a blob.
9273
+ *
9274
+ * @see hhttps://api.glitch.fun/api/documentation#/Feedback/a64fe3d6f90ed1af5bbd5311a795c134
9275
+ *
9276
+ * @param blob The blob to upload.
9277
+ * @param data Any additional data to pass along to the upload
9278
+ *
9279
+ * @returns promise
9280
+ */
9281
+ Feedback.sendFeedbackWithBlob = function (blob, data, params) {
9282
+ var url = FeedbackRoute.routes.sendFeedback.url;
9283
+ return Requests.uploadBlob(url, 'image', blob, data);
9284
+ };
9285
+ return Feedback;
9286
+ }());
9287
+
9147
9288
  var Parser = /** @class */ (function () {
9148
9289
  function Parser() {
9149
9290
  }
@@ -9547,6 +9688,7 @@ var Glitch = /** @class */ (function () {
9547
9688
  Communities: Communities,
9548
9689
  Users: Users,
9549
9690
  Events: Events,
9691
+ Feedback: Feedback,
9550
9692
  Teams: Teams,
9551
9693
  Posts: Posts,
9552
9694
  Messages: Messages,