glitch-javascript-sdk 3.10.8 → 4.0.0

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.
@@ -226,7 +226,8 @@ class Requests {
226
226
  file: File | Blob,
227
227
  data?: any,
228
228
  params?: Record<string, any>,
229
- onUploadProgress?: (progressEvent: AxiosProgressEvent) => void
229
+ onUploadProgress?: (progressEvent: AxiosProgressEvent) => void,
230
+ options?: Pick<AxiosRequestConfig, 'signal' | 'timeout'> & { excludeCommunityContext?: boolean }
230
231
  ): AxiosPromise<Response<T>> {
231
232
  // Process URL and params
232
233
  if (params && Object.keys(params).length > 0) {
@@ -240,7 +241,7 @@ class Requests {
240
241
  const formData = new FormData();
241
242
  formData.append(filename, file);
242
243
 
243
- if (Requests.community_id) {
244
+ if (Requests.community_id && !options?.excludeCommunityContext) {
244
245
  data = {
245
246
  ...data,
246
247
  communities: [Requests.community_id],
@@ -268,6 +269,8 @@ class Requests {
268
269
  data: formData,
269
270
  headers,
270
271
  onUploadProgress,
272
+ signal: options?.signal,
273
+ timeout: options?.timeout,
271
274
  });
272
275
  }
273
276
 
@@ -435,7 +438,7 @@ class Requests {
435
438
 
436
439
 
437
440
 
438
- public static processRoute<T>(route: Route, data?: object, routeReplace?: { [key: string]: any }, params?: Record<string, any>): AxiosPromise<Response<T>> {
441
+ public static processRoute<T>(route: Route, data?: object, routeReplace?: { [key: string]: any }, params?: Record<string, any>, options?: Pick<AxiosRequestConfig, 'signal' | 'timeout' | 'headers'> & { excludeCommunityContext?: boolean }): AxiosPromise<Response<T>> {
439
442
  let url = route.url;
440
443
 
441
444
  if (routeReplace) {
@@ -444,6 +447,15 @@ class Requests {
444
447
  }
445
448
  }
446
449
 
450
+ if (options) {
451
+ const query = { ...params, ...(Requests.community_id && !options.excludeCommunityContext ? { community_id: Requests.community_id } : {}) };
452
+ return axios({
453
+ method: route.method, url: Requests.buildUrl(url, query), data,
454
+ headers: { 'Content-Type': 'application/json', ...(Requests.authToken ? { Authorization: `Bearer ${Requests.authToken}` } : {}), ...options.headers },
455
+ signal: options.signal, timeout: options.timeout,
456
+ });
457
+ }
458
+
447
459
  if (route.method == HTTP_METHODS.GET) {
448
460
  return Requests.get(url, params);
449
461
  } else if (route.method == HTTP_METHODS.POST) {
@@ -1,5 +1,6 @@
1
1
  import { Config } from "../config";
2
2
  import Storage from "./Storage";
3
+ import CryptoJS from 'crypto-js';
3
4
 
4
5
  // Type declarations for crypto functionality
5
6
  interface HmacInterface {
@@ -16,7 +17,7 @@ class BrowserCrypto implements CryptoInterface {
16
17
  private CryptoJS: any;
17
18
 
18
19
  constructor() {
19
- this.CryptoJS = require('crypto-js');
20
+ this.CryptoJS = CryptoJS;
20
21
  }
21
22
 
22
23
  createHmac(algorithm: string, secret: string): HmacInterface {
@@ -188,4 +189,4 @@ class Session {
188
189
  }
189
190
  }
190
191
 
191
- export default Session;
192
+ export default Session;