glitch-javascript-sdk 0.4.4 → 0.4.6

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