glitch-javascript-sdk 1.4.1 → 1.4.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/index.d.ts CHANGED
@@ -2657,6 +2657,14 @@ declare class SocialPosts {
2657
2657
  * @returns promise
2658
2658
  */
2659
2659
  static reschedule<T>(post_id: string, data?: object, params?: Record<string, any>): AxiosPromise<Response<T>>;
2660
+ /**
2661
+ * Get the reports for a social media post
2662
+ *
2663
+ * @see https://api.glitch.fun/api/documentation#/Post%20Route/resourcePostList
2664
+ *
2665
+ * @returns promise
2666
+ */
2667
+ static reports<T>(params?: Record<string, any>): AxiosPromise<Response<T>>;
2660
2668
  }
2661
2669
 
2662
2670
  declare class Titles {
@@ -4193,6 +4201,22 @@ declare class Scheduler {
4193
4201
  * @returns promise
4194
4202
  */
4195
4203
  static getDiscordChannels<T>(scheduler_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
4204
+ /**
4205
+ * Get aggregated reports for a promotion schedule.
4206
+ *
4207
+ * @param scheduler_id The ID of the promotion schedule.
4208
+ * @param params Query parameters (e.g., social_platform, start_date, end_date)
4209
+ * @returns promise
4210
+ */
4211
+ static getSchedulerReports<T>(scheduler_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
4212
+ /**
4213
+ * Get progression data for social media posts over time.
4214
+ *
4215
+ * @param scheduler_id The ID of the promotion schedule.
4216
+ * @param params Query parameters (e.g., social_platform, start_date, end_date)
4217
+ * @returns promise
4218
+ */
4219
+ static getSchedulerProgression<T>(scheduler_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
4196
4220
  }
4197
4221
 
4198
4222
  declare class Funnel {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glitch-javascript-sdk",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "Javascript SDK for Glitch",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -356,6 +356,28 @@ class Scheduler {
356
356
  return Requests.processRoute(SchedulerRoute.routes.getDiscordChannels, {}, { scheduler_id }, params);
357
357
  }
358
358
 
359
+ /**
360
+ * Get aggregated reports for a promotion schedule.
361
+ *
362
+ * @param scheduler_id The ID of the promotion schedule.
363
+ * @param params Query parameters (e.g., social_platform, start_date, end_date)
364
+ * @returns promise
365
+ */
366
+ public static getSchedulerReports<T>(scheduler_id: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
367
+ return Requests.processRoute(SchedulerRoute.routes.getSchedulerReports, {}, { scheduler_id }, params);
368
+ }
369
+
370
+ /**
371
+ * Get progression data for social media posts over time.
372
+ *
373
+ * @param scheduler_id The ID of the promotion schedule.
374
+ * @param params Query parameters (e.g., social_platform, start_date, end_date)
375
+ * @returns promise
376
+ */
377
+ public static getSchedulerProgression<T>(scheduler_id: string, params?: Record<string, any>): AxiosPromise<Response<T>> {
378
+ return Requests.processRoute(SchedulerRoute.routes.getSchedulerProgression, {}, { scheduler_id }, params);
379
+ }
380
+
359
381
  }
360
382
 
361
383
  export default Scheduler;
@@ -126,6 +126,17 @@ class SocialPosts {
126
126
  return Requests.processRoute(SocialPostsRoute.routes.reschedule, data, { post_id: post_id }, params);
127
127
  }
128
128
 
129
+ /**
130
+ * Get the reports for a social media post
131
+ *
132
+ * @see https://api.glitch.fun/api/documentation#/Post%20Route/resourcePostList
133
+ *
134
+ * @returns promise
135
+ */
136
+ public static reports<T>(params?: Record<string, any>): AxiosPromise<Response<T>> {
137
+ return Requests.processRoute(SocialPostsRoute.routes.reports, undefined, undefined, params);
138
+ }
139
+
129
140
  }
130
141
 
131
142
  export default SocialPosts;
@@ -19,6 +19,8 @@ class SchedulerRoute {
19
19
  deleteUpdate: { url: '/schedulers/{scheduler_id}/updates/{update_id}', method: HTTP_METHODS.DELETE },
20
20
 
21
21
  testTone: { url: '/schedulers/{scheduler_id}/tone', method: HTTP_METHODS.POST },
22
+ getSchedulerReports: { url: '/schedulers/{scheduler_id}/reports', method: HTTP_METHODS.GET },
23
+ getSchedulerProgression: { url: '/schedulers/{scheduler_id}/progression', method: HTTP_METHODS.GET },
22
24
 
23
25
  // Clear OAuth Routes
24
26
  clearTwitterAuth: { url: '/schedulers/{scheduler_id}/clearTwitterAuth', method: HTTP_METHODS.DELETE },
@@ -13,6 +13,8 @@ class SocialPostsRoute {
13
13
  addMedia: { url: '/socialposts/{post_id}/addMedia', method: HTTP_METHODS.POST },
14
14
  removeMedia: { url: '/socialposts/{post_id}/removeMedia/{media_id}', method: HTTP_METHODS.DELETE },
15
15
  reschedule: { url: '/socialposts/{post_id}/reschedule', method: HTTP_METHODS.POST },
16
+ reports: { url: '/socialposts/{post_id}/reports', method: HTTP_METHODS.GET },
17
+
16
18
  };
17
19
 
18
20
  }
@@ -141,87 +141,109 @@ class Requests {
141
141
  file: File | Blob,
142
142
  data?: any,
143
143
  params?: Record<string, any>,
144
- onUploadProgress?: (progressEvent: AxiosProgressEvent) => void // Correct type here
144
+ onUploadProgress?: (progressEvent: AxiosProgressEvent) => void
145
145
  ): AxiosPromise<Response<T>> {
146
+ // Process URL and params
146
147
  if (params && Object.keys(params).length > 0) {
147
148
  const queryString = Object.entries(params)
148
149
  .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
149
150
  .join('&');
150
151
  url = `${url}?${queryString}`;
151
152
  }
152
-
153
+
154
+ // Prepare FormData
153
155
  const formData = new FormData();
154
156
  formData.append(filename, file);
155
-
157
+
156
158
  if (Requests.community_id) {
157
159
  data = {
158
160
  ...data,
159
161
  communities: [Requests.community_id],
160
162
  };
161
163
  }
162
-
164
+
163
165
  for (let key in data) {
164
166
  formData.append(key, data[key]);
165
167
  }
166
-
167
- const config: AxiosRequestConfig = {
168
+
169
+ // Prepare headers
170
+ let headers: { [key: string]: string } = {
171
+ 'Content-Type': 'multipart/form-data',
172
+ };
173
+
174
+ if (Requests.authToken) {
175
+ headers['Authorization'] = `Bearer ${Requests.authToken}`;
176
+ }
177
+
178
+ // Format URL
179
+ url = url.replace(/\/\//g, '/');
180
+ const uri = `${Requests.baseUrl}${url}`.replace(/\/\//g, '/');
181
+
182
+ // Make the request
183
+ return axios({
168
184
  method: 'POST',
169
- url,
185
+ url: uri,
170
186
  data: formData,
171
- headers: {
172
- 'Content-Type': 'multipart/form-data',
173
- ...(Requests.authToken && { Authorization: `Bearer ${Requests.authToken}` }),
174
- },
175
- onUploadProgress, // Pass directly, as the type now matches
176
- };
177
-
178
- return axios(config);
187
+ headers,
188
+ onUploadProgress,
189
+ });
179
190
  }
180
191
 
181
- // Modify uploadBlob method
182
192
  public static uploadBlob<T>(
183
193
  url: string,
184
194
  filename: string,
185
195
  blob: Blob,
186
196
  data?: any,
187
197
  params?: Record<string, any>,
188
- onUploadProgress?: (progressEvent: AxiosProgressEvent) => void // Corrected type
198
+ onUploadProgress?: (progressEvent: AxiosProgressEvent) => void
189
199
  ): AxiosPromise<Response<T>> {
200
+ // Process URL and params
190
201
  if (params && Object.keys(params).length > 0) {
191
202
  const queryString = Object.entries(params)
192
203
  .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
193
204
  .join('&');
194
205
  url = `${url}?${queryString}`;
195
206
  }
196
-
207
+
208
+ // Prepare FormData
197
209
  const formData = new FormData();
198
210
  formData.append(filename, blob);
199
-
211
+
200
212
  if (Requests.community_id) {
201
213
  data = {
202
214
  ...data,
203
215
  communities: [Requests.community_id],
204
216
  };
205
217
  }
206
-
218
+
207
219
  for (let key in data) {
208
220
  formData.append(key, data[key]);
209
221
  }
210
-
211
- const config: AxiosRequestConfig = {
222
+
223
+ // Prepare headers
224
+ let headers: { [key: string]: string } = {
225
+ 'Content-Type': 'multipart/form-data',
226
+ };
227
+
228
+ if (Requests.authToken) {
229
+ headers['Authorization'] = `Bearer ${Requests.authToken}`;
230
+ }
231
+
232
+ // Format URL
233
+ url = url.replace(/\/\//g, '/');
234
+ const uri = `${Requests.baseUrl}${url}`.replace(/\/\//g, '/');
235
+
236
+ // Make the request
237
+ return axios({
212
238
  method: 'POST',
213
- url,
239
+ url: uri,
214
240
  data: formData,
215
- headers: {
216
- 'Content-Type': 'multipart/form-data',
217
- ...(Requests.authToken && { Authorization: `Bearer ${Requests.authToken}` }),
218
- },
219
- onUploadProgress, // Pass directly
220
- };
221
-
222
- return axios(config);
241
+ headers,
242
+ onUploadProgress,
243
+ });
223
244
  }
224
-
245
+
246
+
225
247
  // Method adapted for browser environments
226
248
 
227
249
  public static async uploadFileInChunks<T>(
@@ -229,27 +251,27 @@ class Requests {
229
251
  uploadUrl: string,
230
252
  onProgress?: (totalSize: number, amountUploaded: number) => void,
231
253
  data?: any,
232
- chunkSize ?: number, // Default chunk size of 1MB
254
+ chunkSize?: number, // Default chunk size of 1MB
233
255
  ): Promise<void> {
234
256
 
235
- if(!chunkSize) {
257
+ if (!chunkSize) {
236
258
  chunkSize = 1024 * 1024
237
259
  }
238
260
  const fileSize = file.size;
239
261
  const totalChunks = Math.ceil(fileSize / chunkSize);
240
262
  let currentChunkIndex = 0;
241
263
  let totalUploaded = 0; // Keep track of the total uploaded bytes
242
-
264
+
243
265
  // Generate a unique identifier for this upload session using the Web Cryptography API
244
266
  const array = new Uint32Array(4);
245
267
  window.crypto.getRandomValues(array);
246
268
  const identifier = Array.from(array, dec => ('0' + dec.toString(16)).substr(-2)).join('');
247
-
269
+
248
270
  while (currentChunkIndex <= totalChunks) {
249
271
  const start = currentChunkIndex * chunkSize;
250
272
  const end = Math.min(start + chunkSize, fileSize);
251
273
  const chunk = file.slice(start, end);
252
-
274
+
253
275
  const formData = new FormData();
254
276
  formData.append('video', chunk, file.name);
255
277
  formData.append('chunkIndex', currentChunkIndex.toString());
@@ -262,30 +284,30 @@ class Requests {
262
284
  formData.append(key, data[key]);
263
285
  }
264
286
  }
265
-
287
+
266
288
  // Construct the full URL if necessary or use a method to determine the base URL
267
289
  const fullUploadUrl = `${Requests.baseUrl}${uploadUrl}`;
268
-
290
+
269
291
  // Make sure the authorization token is included if required
270
292
  const headers: { [key: string]: string } = {};
271
293
  if (Requests.authToken) {
272
294
  headers['Authorization'] = `Bearer ${Requests.authToken}`;
273
295
  }
274
-
296
+
275
297
  // Perform the upload
276
- await axios.post(fullUploadUrl, formData, {
298
+ await axios.post(fullUploadUrl, formData, {
277
299
  headers,
278
300
  onUploadProgress: (progressEvent) => {
279
301
  const currentChunkProgress = progressEvent.loaded; // Bytes uploaded of the current chunk
280
302
  // Calculate the total uploaded size including previous chunks and the current chunk's progress
281
303
  const totalProgress = totalUploaded + currentChunkProgress;
282
304
 
283
- if(onProgress){
305
+ if (onProgress) {
284
306
  onProgress(fileSize, end);
285
307
  }
286
- }
308
+ }
287
309
  });
288
-
310
+
289
311
  currentChunkIndex++;
290
312
  }
291
313
  }