glitch-javascript-sdk 0.0.2 → 0.0.4

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/cjs/index.js CHANGED
@@ -15623,15 +15623,21 @@ var Requests = /** @class */ (function () {
15623
15623
  Requests.setAuthToken = function (token) {
15624
15624
  this.authToken = token;
15625
15625
  };
15626
- Requests.request = function (method, url, data) {
15626
+ Requests.request = function (method, url, data, fileData) {
15627
+ var headers = {
15628
+ 'Content-Type': 'application/json',
15629
+ };
15630
+ if (this.authToken) {
15631
+ headers['Authorization'] = "Bearer ".concat(this.authToken);
15632
+ }
15633
+ if (fileData) {
15634
+ headers['Content-Type'] = 'multipart/form-data';
15635
+ }
15627
15636
  var axiosPromise = axios({
15628
15637
  method: method,
15629
15638
  url: "".concat(this.baseUrl).concat(url),
15630
- data: data,
15631
- headers: {
15632
- Authorization: "Bearer ".concat(this.authToken),
15633
- 'Content-Type': 'application/json',
15634
- },
15639
+ data: fileData || data,
15640
+ headers: headers,
15635
15641
  });
15636
15642
  return axiosPromise;
15637
15643
  };
@@ -15653,6 +15659,22 @@ var Requests = /** @class */ (function () {
15653
15659
  Requests.delete = function (url) {
15654
15660
  return this.request('DELETE', url);
15655
15661
  };
15662
+ Requests.uploadFile = function (url, filename, file, data) {
15663
+ var formData = new FormData();
15664
+ formData.append(filename, file);
15665
+ for (var key in data) {
15666
+ formData.append(key, data[key]);
15667
+ }
15668
+ return this.request('POST', url, data, formData);
15669
+ };
15670
+ Requests.uploadBlob = function (url, filename, blob, data) {
15671
+ var formData = new FormData();
15672
+ formData.append(filename, blob);
15673
+ for (var key in data) {
15674
+ formData.append(key, data[key]);
15675
+ }
15676
+ return this.request('POST', url, data, formData);
15677
+ };
15656
15678
  /**
15657
15679
  * The Route class contains the method and url, thereforce items can be
15658
15680
  * automatically routed depending on the configuration.
@@ -15712,147 +15734,11 @@ var Config = /** @class */ (function () {
15712
15734
  return Config;
15713
15735
  }());
15714
15736
 
15715
- var AuthRoutes = /** @class */ (function () {
15716
- function AuthRoutes() {
15717
- }
15718
- AuthRoutes.routes = {
15719
- login: { url: '/auth/login', method: HTTP_METHODS.POST },
15720
- register: { url: '/auth/register', method: HTTP_METHODS.POST },
15721
- one_time_login: { url: '/auth/oneTimeLoginWithToken', method: HTTP_METHODS.POST },
15722
- forgot_password: { url: '/auth/forgotpassword', method: HTTP_METHODS.POST },
15723
- reset_password: { url: '/auth/resetpassword', method: HTTP_METHODS.POST },
15724
- };
15725
- return AuthRoutes;
15726
- }());
15727
-
15728
- var Auth = /** @class */ (function () {
15729
- function Auth() {
15730
- }
15731
- /**
15732
- * Attempts to authenticate a user using their email address.
15733
- *
15734
- * @see https://api.glitch.fun/api/documentation#/Authentication%20Route/authLogin
15735
- *
15736
- * @param email The email address of the user
15737
- * @param password The password of the user
15738
- *
15739
- * @returns A promise
15740
- */
15741
- Auth.loginWithEmail = function (email, password) {
15742
- return Requests.post(AuthRoutes.routes.login.url, { email: email, password: password });
15743
- };
15744
- /**
15745
- * Attempts to authenticate a user using their username.
15746
- *
15747
- * @see https://api.glitch.fun/api/documentation#/Authentication%20Route/authLogin
15748
- *
15749
- * @param username The username of the user
15750
- * @param password The password of the user
15751
- *
15752
- * @returns A promise
15753
- */
15754
- Auth.loginWithUsername = function (username, password) {
15755
- return Requests.post(AuthRoutes.routes.login.url, { username: username, password: password });
15756
- };
15757
- /**
15758
- * Attempts to register a user.
15759
- *
15760
- * @see https://api.glitch.fun/api/documentation#/Authentication%20Route/authRegister
15761
- *
15762
- * @param data The data the user can register with.
15763
- *
15764
- * @returns A promise
15765
- */
15766
- Auth.register = function (data) {
15767
- return Requests.processRoute(AuthRoutes.routes.register, data);
15768
- };
15769
- return Auth;
15770
- }());
15771
-
15772
- var CompetitionRoutes = /** @class */ (function () {
15773
- function CompetitionRoutes() {
15774
- }
15775
- CompetitionRoutes.routes = {
15776
- list: { url: '/competitions', method: HTTP_METHODS.GET },
15777
- create: { url: '/competitions', method: HTTP_METHODS.POST },
15778
- view: { url: '/competitions/{competition_id}', method: HTTP_METHODS.GET },
15779
- update: { url: '/competitions/{competition_id}', method: HTTP_METHODS.PUT },
15780
- delete: { url: '/competitions/{competition_id}', method: HTTP_METHODS.DELETE },
15781
- };
15782
- return CompetitionRoutes;
15783
- }());
15784
-
15785
- var Competitions = /** @class */ (function () {
15786
- function Competitions() {
15787
- }
15788
- /**
15789
- * List all the competitions
15790
- *
15791
- * @see https://api.glitch.fun/api/documentation#/Competitions%20Route/resourceList
15792
- *
15793
- * @returns promise
15794
- */
15795
- Competitions.list = function () {
15796
- return Requests.processRoute(CompetitionRoutes.routes.list);
15797
- };
15798
- /**
15799
- * Create a new competition
15800
- *
15801
- * @see https://api.glitch.fun/api/documentation#/Competitions%20Route/newResourceStorage
15802
- *
15803
- * @param data The date to be passed when creating a competiton.
15804
- *
15805
- * @returns Promise
15806
- */
15807
- Competitions.create = function (data) {
15808
- return Requests.processRoute(CompetitionRoutes.routes.create, data);
15809
- };
15810
- /**
15811
- * Update a competition
15812
- *
15813
- * @see https://api.glitch.fun/api/documentation#/Competitions%20Route/updateStorage
15814
- *
15815
- * @param competition_id The id of the competition to update.
15816
- * @param data The data to update.
15817
- *
15818
- * @returns promise
15819
- */
15820
- Competitions.update = function (competition_id, data) {
15821
- return Requests.processRoute(CompetitionRoutes.routes.create, data, { competition_id: competition_id });
15822
- };
15823
- /**
15824
- * Retrieve the information for a single competition.
15825
- *
15826
- * @see https://api.glitch.fun/api/documentation#/Competitions%20Route/showStorage
15827
- *
15828
- * @param competition_id The id fo the competition to retrieve.
15829
- *
15830
- * @returns promise
15831
- */
15832
- Competitions.view = function (competition_id) {
15833
- return Requests.processRoute(CompetitionRoutes.routes.view, {}, { competition_id: competition_id });
15834
- };
15835
- /**
15836
- * Deletes a competition.
15837
- *
15838
- * @see https://api.glitch.fun/api/documentation#/Competitions%20Route/destoryStorage
15839
- *
15840
- * @param competition_id The id of the competition to delete.
15841
- * @returns promise
15842
- */
15843
- Competitions.delete = function (competition_id) {
15844
- return Requests.processRoute(CompetitionRoutes.routes.delete, {}, { competition_id: competition_id });
15845
- };
15846
- return Competitions;
15847
- }());
15848
-
15849
15737
  //Configuration
15850
15738
  var Glitch = /** @class */ (function () {
15851
15739
  function Glitch() {
15852
15740
  }
15853
15741
  Glitch.config = Config;
15854
- Glitch.auth = Auth;
15855
- Glitch.competitions = Competitions;
15856
15742
  return Glitch;
15857
15743
  }());
15858
15744