glitch-javascript-sdk 0.4.5 → 0.4.7

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/esm/index.js CHANGED
@@ -29872,60 +29872,44 @@ var HTTP_METHODS = {
29872
29872
 
29873
29873
  var Requests = /** @class */ (function () {
29874
29874
  function Requests(config) {
29875
- this.config = config;
29875
+ Requests.config = config;
29876
+ Requests.axiosInstance = axios.create({
29877
+ baseURL: Requests.baseUrl,
29878
+ headers: { 'Content-Type': 'application/json' },
29879
+ });
29876
29880
  }
29877
- /**
29878
- * Sets the base url of the API.
29879
- *
29880
- * @param url The url to of the API.
29881
- */
29882
29881
  Requests.setBaseUrl = function (url) {
29883
- this.baseUrl = url;
29882
+ Requests.baseUrl = url;
29883
+ if (Requests.axiosInstance && Requests.axiosInstance.defaults) {
29884
+ Requests.axiosInstance.defaults.baseURL = url;
29885
+ }
29884
29886
  };
29885
- /**
29886
- * Sets the JSON Web token
29887
- *
29888
- * @param token
29889
- */
29890
29887
  Requests.setAuthToken = function (token) {
29891
- this.authToken = token;
29888
+ Requests.authToken = token;
29892
29889
  };
29893
- /**
29894
- * Sets the community id that will be associated with all requests
29895
- *
29896
- * @param token
29897
- */
29898
29890
  Requests.setCommunityID = function (community_id) {
29899
- this.community_id = community_id;
29891
+ Requests.community_id = community_id;
29900
29892
  };
29901
29893
  Requests.request = function (method, url, data, fileData) {
29902
29894
  var headers = {
29903
29895
  'Content-Type': 'application/json',
29904
29896
  };
29905
- if (this.authToken) {
29906
- headers['Authorization'] = "Bearer ".concat(this.authToken);
29897
+ if (Requests.authToken) {
29898
+ headers['Authorization'] = "Bearer ".concat(Requests.authToken);
29907
29899
  }
29908
29900
  if (fileData) {
29909
29901
  headers['Content-Type'] = 'multipart/form-data';
29910
29902
  }
29911
- //Remove double slashes
29912
29903
  url = url.replace(/\/\//g, '/');
29913
- var uri = "".concat(this.baseUrl).concat(url);
29914
- var axiosPromise = axios({
29904
+ var uri = "".concat(Requests.baseUrl).concat(url);
29905
+ var axiosPromise = Requests.axiosInstance({
29915
29906
  method: method,
29916
29907
  url: uri,
29917
- baseURL: this.baseUrl,
29918
29908
  data: fileData || data,
29919
29909
  headers: headers,
29920
29910
  });
29921
29911
  return axiosPromise;
29922
29912
  };
29923
- /**
29924
- * Calls a GET request to the url endpoint.
29925
- *
29926
- * @param url
29927
- * @returns
29928
- */
29929
29913
  Requests.get = function (url, params) {
29930
29914
  if (params && Object.keys(params).length > 0) {
29931
29915
  var queryString = Object.entries(params)
@@ -29939,13 +29923,11 @@ var Requests = /** @class */ (function () {
29939
29923
  .join('&');
29940
29924
  url = "".concat(url, "?").concat(queryString);
29941
29925
  }
29942
- if (this.community_id) {
29943
- // Check if the URL already contains query parameters
29926
+ if (Requests.community_id) {
29944
29927
  var separator = url.includes('?') ? '&' : '?';
29945
- // Append the community_id query parameter
29946
- url = "".concat(url).concat(separator, "community_id=").concat(this.community_id);
29928
+ url = "".concat(url).concat(separator, "community_id=").concat(Requests.community_id);
29947
29929
  }
29948
- return this.request('GET', url);
29930
+ return Requests.request('GET', url);
29949
29931
  };
29950
29932
  Requests.post = function (url, data, params) {
29951
29933
  if (params && Object.keys(params).length > 0) {
@@ -29957,11 +29939,10 @@ var Requests = /** @class */ (function () {
29957
29939
  .join('&');
29958
29940
  url = "".concat(url, "?").concat(queryString);
29959
29941
  }
29960
- if (this.community_id) {
29961
- // Add the community_id to the request body
29962
- data = __assign(__assign({}, data), { communities: [this.community_id] });
29942
+ if (Requests.community_id) {
29943
+ data = __assign(__assign({}, data), { communities: [Requests.community_id] });
29963
29944
  }
29964
- return this.request('POST', url, data);
29945
+ return Requests.request('POST', url, data);
29965
29946
  };
29966
29947
  Requests.put = function (url, data, params) {
29967
29948
  if (params && Object.keys(params).length > 0) {
@@ -29973,11 +29954,10 @@ var Requests = /** @class */ (function () {
29973
29954
  .join('&');
29974
29955
  url = "".concat(url, "?").concat(queryString);
29975
29956
  }
29976
- if (this.community_id) {
29977
- // Add the community_id to the request body
29978
- data = __assign(__assign({}, data), { community_id: this.community_id });
29957
+ if (Requests.community_id) {
29958
+ data = __assign(__assign({}, data), { community_id: Requests.community_id });
29979
29959
  }
29980
- return this.request('PUT', url, data);
29960
+ return Requests.request('PUT', url, data);
29981
29961
  };
29982
29962
  Requests.delete = function (url, params) {
29983
29963
  if (params && Object.keys(params).length > 0) {
@@ -29989,13 +29969,11 @@ var Requests = /** @class */ (function () {
29989
29969
  .join('&');
29990
29970
  url = "".concat(url, "?").concat(queryString);
29991
29971
  }
29992
- if (this.community_id) {
29993
- // Check if the URL already contains query parameters
29972
+ if (Requests.community_id) {
29994
29973
  var separator = url.includes('?') ? '&' : '?';
29995
- // Append the community_id query parameter
29996
- url = "".concat(url).concat(separator, "community_id=").concat(this.community_id);
29974
+ url = "".concat(url).concat(separator, "community_id=").concat(Requests.community_id);
29997
29975
  }
29998
- return this.request('DELETE', url);
29976
+ return Requests.request('DELETE', url);
29999
29977
  };
30000
29978
  Requests.uploadFile = function (url, filename, file, data, params) {
30001
29979
  if (params && Object.keys(params).length > 0) {
@@ -30009,14 +29987,13 @@ var Requests = /** @class */ (function () {
30009
29987
  }
30010
29988
  var formData = new FormData();
30011
29989
  formData.append(filename, file);
30012
- if (this.community_id) {
30013
- // Add the community_id to the request body
30014
- data = __assign(__assign({}, data), { communities: [this.community_id] });
29990
+ if (Requests.community_id) {
29991
+ data = __assign(__assign({}, data), { communities: [Requests.community_id] });
30015
29992
  }
30016
29993
  for (var key in data) {
30017
29994
  formData.append(key, data[key]);
30018
29995
  }
30019
- return this.request('POST', url, data, formData);
29996
+ return Requests.request('POST', url, data, formData);
30020
29997
  };
30021
29998
  Requests.uploadBlob = function (url, filename, blob, data, params) {
30022
29999
  if (params && Object.keys(params).length > 0) {
@@ -30030,23 +30007,14 @@ var Requests = /** @class */ (function () {
30030
30007
  }
30031
30008
  var formData = new FormData();
30032
30009
  formData.append(filename, blob);
30033
- if (this.community_id) {
30034
- // Add the community_id to the request body
30035
- data = __assign(__assign({}, data), { communities: [this.community_id] });
30010
+ if (Requests.community_id) {
30011
+ data = __assign(__assign({}, data), { communities: [Requests.community_id] });
30036
30012
  }
30037
30013
  for (var key in data) {
30038
30014
  formData.append(key, data[key]);
30039
30015
  }
30040
- return this.request('POST', url, data, formData);
30016
+ return Requests.request('POST', url, data, formData);
30041
30017
  };
30042
- /**
30043
- * The Route class contains the method and url, thereforce items can be
30044
- * automatically routed depending on the configuration.
30045
- *
30046
- * @param route
30047
- * @param data
30048
- * @returns
30049
- */
30050
30018
  Requests.processRoute = function (route, data, routeReplace, params) {
30051
30019
  var url = route.url;
30052
30020
  if (routeReplace) {
@@ -30055,24 +30023,21 @@ var Requests = /** @class */ (function () {
30055
30023
  }
30056
30024
  }
30057
30025
  if (route.method == HTTP_METHODS.GET) {
30058
- return this.get(url, params);
30026
+ return Requests.get(url, params);
30059
30027
  }
30060
30028
  else if (route.method == HTTP_METHODS.POST) {
30061
- return this.post(url, data, params);
30029
+ return Requests.post(url, data, params);
30062
30030
  }
30063
30031
  else if (route.method == HTTP_METHODS.PUT) {
30064
- return this.put(url, data, params);
30032
+ return Requests.put(url, data, params);
30065
30033
  }
30066
30034
  else if (route.method == HTTP_METHODS.DELETE) {
30067
- return this.delete(url, params);
30035
+ return Requests.delete(url, params);
30068
30036
  }
30069
- return this.get(url);
30037
+ return Requests.get(url);
30070
30038
  };
30071
- //The base url of the API.
30072
30039
  Requests.baseUrl = "";
30073
- //The Json Web Token to send in the header
30074
30040
  Requests.authToken = "";
30075
- //The ID of the community that will be added to request
30076
30041
  Requests.community_id = "";
30077
30042
  return Requests;
30078
30043
  }());