glitch-javascript-sdk 0.0.1 → 0.0.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/cjs/index.js CHANGED
@@ -10,59 +10,6 @@ var require$$1$1 = require('util');
10
10
  var require$$1$2 = require('path');
11
11
  var require$$6 = require('fs');
12
12
 
13
- /******************************************************************************
14
- Copyright (c) Microsoft Corporation.
15
-
16
- Permission to use, copy, modify, and/or distribute this software for any
17
- purpose with or without fee is hereby granted.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
- PERFORMANCE OF THIS SOFTWARE.
26
- ***************************************************************************** */
27
-
28
- function __awaiter(thisArg, _arguments, P, generator) {
29
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
- return new (P || (P = Promise))(function (resolve, reject) {
31
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
- step((generator = generator.apply(thisArg, _arguments || [])).next());
35
- });
36
- }
37
-
38
- function __generator(thisArg, body) {
39
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
40
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
41
- function verb(n) { return function (v) { return step([n, v]); }; }
42
- function step(op) {
43
- if (f) throw new TypeError("Generator is already executing.");
44
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
45
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
46
- if (y = 0, t) op = [op[0] & 2, t.value];
47
- switch (op[0]) {
48
- case 0: case 1: t = op; break;
49
- case 4: _.label++; return { value: op[1], done: false };
50
- case 5: _.label++; y = op[1]; op = [0]; continue;
51
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
52
- default:
53
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
54
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
55
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
56
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
57
- if (t[2]) _.ops.pop();
58
- _.trys.pop(); continue;
59
- }
60
- op = body.call(thisArg, _);
61
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
62
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
63
- }
64
- }
65
-
66
13
  function getDefaultExportFromCjs (x) {
67
14
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
68
15
  }
@@ -15651,79 +15598,60 @@ var Requests = /** @class */ (function () {
15651
15598
  function Requests(config) {
15652
15599
  this.config = config;
15653
15600
  }
15601
+ /**
15602
+ * Sets the configuration of the system.
15603
+ *
15604
+ * @param config Config The config class.
15605
+ */
15654
15606
  Requests.setConfig = function (config) {
15655
15607
  this.baseUrl = config.baseUrl;
15656
15608
  this.authToken = config.authToken;
15657
15609
  };
15610
+ /**
15611
+ * Sets the base url of the API.
15612
+ *
15613
+ * @param url The url to of the API.
15614
+ */
15658
15615
  Requests.setBaseUrl = function (url) {
15659
15616
  this.baseUrl = url;
15660
15617
  };
15618
+ /**
15619
+ * Sets the JSON Web token
15620
+ *
15621
+ * @param token
15622
+ */
15661
15623
  Requests.setAuthToken = function (token) {
15662
15624
  this.authToken = token;
15663
15625
  };
15664
15626
  Requests.request = function (method, url, data) {
15665
- var _a, _b;
15666
- return __awaiter(this, void 0, void 0, function () {
15667
- var response, error_1, message;
15668
- return __generator(this, function (_c) {
15669
- switch (_c.label) {
15670
- case 0:
15671
- _c.trys.push([0, 2, , 3]);
15672
- return [4 /*yield*/, axios({
15673
- method: method,
15674
- url: "".concat(this.baseUrl).concat(url),
15675
- data: data,
15676
- headers: {
15677
- Authorization: "Bearer ".concat(this.authToken),
15678
- 'Content-Type': 'application/json',
15679
- },
15680
- })];
15681
- case 1:
15682
- response = _c.sent();
15683
- return [2 /*return*/, {
15684
- data: response.data,
15685
- success: true,
15686
- }];
15687
- case 2:
15688
- error_1 = _c.sent();
15689
- message = ((_b = (_a = error_1.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) || 'An error occurred';
15690
- return [2 /*return*/, {
15691
- data: null,
15692
- success: false,
15693
- message: message,
15694
- }];
15695
- case 3: return [2 /*return*/];
15696
- }
15697
- });
15627
+ var axiosPromise = axios({
15628
+ method: method,
15629
+ url: "".concat(this.baseUrl).concat(url),
15630
+ data: data,
15631
+ headers: {
15632
+ Authorization: "Bearer ".concat(this.authToken),
15633
+ 'Content-Type': 'application/json',
15634
+ },
15698
15635
  });
15636
+ return axiosPromise;
15699
15637
  };
15638
+ /**
15639
+ * Calls a GET request to the url endpoint.
15640
+ *
15641
+ * @param url
15642
+ * @returns
15643
+ */
15700
15644
  Requests.get = function (url) {
15701
- return __awaiter(this, void 0, void 0, function () {
15702
- return __generator(this, function (_a) {
15703
- return [2 /*return*/, this.request('GET', url)];
15704
- });
15705
- });
15645
+ return this.request('GET', url);
15706
15646
  };
15707
15647
  Requests.post = function (url, data) {
15708
- return __awaiter(this, void 0, void 0, function () {
15709
- return __generator(this, function (_a) {
15710
- return [2 /*return*/, this.request('POST', url, data)];
15711
- });
15712
- });
15648
+ return this.request('POST', url, data);
15713
15649
  };
15714
15650
  Requests.put = function (url, data) {
15715
- return __awaiter(this, void 0, void 0, function () {
15716
- return __generator(this, function (_a) {
15717
- return [2 /*return*/, this.request('PUT', url, data)];
15718
- });
15719
- });
15651
+ return this.request('PUT', url, data);
15720
15652
  };
15721
15653
  Requests.delete = function (url) {
15722
- return __awaiter(this, void 0, void 0, function () {
15723
- return __generator(this, function (_a) {
15724
- return [2 /*return*/, this.request('DELETE', url)];
15725
- });
15726
- });
15654
+ return this.request('DELETE', url);
15727
15655
  };
15728
15656
  /**
15729
15657
  * The Route class contains the method and url, thereforce items can be
@@ -15734,27 +15662,29 @@ var Requests = /** @class */ (function () {
15734
15662
  * @returns
15735
15663
  */
15736
15664
  Requests.processRoute = function (route, data, routeReplace) {
15737
- return __awaiter(this, void 0, void 0, function () {
15738
- var url;
15739
- return __generator(this, function (_a) {
15740
- url = route.url;
15741
- if (route.method == HTTP_METHODS.GET) {
15742
- return [2 /*return*/, this.get(url)];
15743
- }
15744
- else if (route.method == HTTP_METHODS.POST) {
15745
- return [2 /*return*/, this.post(url, data)];
15746
- }
15747
- else if (route.method == HTTP_METHODS.PUT) {
15748
- return [2 /*return*/, this.put(url, data)];
15749
- }
15750
- else if (route.method == HTTP_METHODS.DELETE) {
15751
- return [2 /*return*/, this.delete(url)];
15752
- }
15753
- return [2 /*return*/];
15754
- });
15755
- });
15665
+ var url = route.url;
15666
+ if (routeReplace) {
15667
+ for (var key in routeReplace) {
15668
+ url = url.replace("{" + key + "}", routeReplace[key]);
15669
+ }
15670
+ }
15671
+ if (route.method == HTTP_METHODS.GET) {
15672
+ return this.get(url);
15673
+ }
15674
+ else if (route.method == HTTP_METHODS.POST) {
15675
+ return this.post(url, data);
15676
+ }
15677
+ else if (route.method == HTTP_METHODS.PUT) {
15678
+ return this.put(url, data);
15679
+ }
15680
+ else if (route.method == HTTP_METHODS.DELETE) {
15681
+ return this.delete(url);
15682
+ }
15683
+ return this.get(url);
15756
15684
  };
15685
+ //The base url of the API.
15757
15686
  Requests.baseUrl = "";
15687
+ //The Json Web Token to send in the header
15758
15688
  Requests.authToken = "";
15759
15689
  return Requests;
15760
15690
  }());
@@ -15782,72 +15712,11 @@ var Config = /** @class */ (function () {
15782
15712
  return Config;
15783
15713
  }());
15784
15714
 
15785
- var AuthRoutes = /** @class */ (function () {
15786
- function AuthRoutes() {
15787
- }
15788
- AuthRoutes.routes = {
15789
- login: { url: '/auth/login', method: HTTP_METHODS.POST },
15790
- register: { url: '/auth/register', method: HTTP_METHODS.POST },
15791
- one_time_login: { url: '/auth/oneTimeLoginWithToken', method: HTTP_METHODS.POST },
15792
- forgot_password: { url: '/auth/forgotpassword', method: HTTP_METHODS.POST },
15793
- reset_password: { url: '/auth/resetpassword', method: HTTP_METHODS.POST },
15794
- };
15795
- return AuthRoutes;
15796
- }());
15797
-
15798
- var Auth = /** @class */ (function () {
15799
- function Auth() {
15800
- }
15801
- Auth.login = function (login, password) {
15802
- return Requests.post(AuthRoutes.routes.login.url, { email: login, password: password });
15803
- };
15804
- Auth.register = function (data) {
15805
- return Requests.processRoute(AuthRoutes.routes.register, data);
15806
- };
15807
- return Auth;
15808
- }());
15809
-
15810
- var CompetitionRoutes = /** @class */ (function () {
15811
- function CompetitionRoutes() {
15812
- }
15813
- CompetitionRoutes.routes = {
15814
- list: { url: '/competitions', method: HTTP_METHODS.GET },
15815
- create: { url: '/competitions', method: HTTP_METHODS.POST },
15816
- view: { url: '/competitions/{competition_id}', method: HTTP_METHODS.GET },
15817
- update: { url: '/competitions/{competition_id}', method: HTTP_METHODS.PUT },
15818
- delete: { url: '/competitions/{competition_id}', method: HTTP_METHODS.DELETE },
15819
- };
15820
- return CompetitionRoutes;
15821
- }());
15822
-
15823
- var Competitions = /** @class */ (function () {
15824
- function Competitions() {
15825
- }
15826
- Competitions.list = function () {
15827
- return Requests.processRoute(CompetitionRoutes.routes.list);
15828
- };
15829
- Competitions.create = function (data) {
15830
- return Requests.processRoute(CompetitionRoutes.routes.create, data);
15831
- };
15832
- Competitions.update = function (competition_id, data) {
15833
- return Requests.processRoute(CompetitionRoutes.routes.create, data, { competition_id: competition_id });
15834
- };
15835
- Competitions.view = function (competition_id) {
15836
- return Requests.processRoute(CompetitionRoutes.routes.view, {}, { competition_id: competition_id });
15837
- };
15838
- Competitions.delete = function (competition_id) {
15839
- return Requests.processRoute(CompetitionRoutes.routes.delete, {}, { competition_id: competition_id });
15840
- };
15841
- return Competitions;
15842
- }());
15843
-
15844
15715
  //Configuration
15845
15716
  var Glitch = /** @class */ (function () {
15846
15717
  function Glitch() {
15847
15718
  }
15848
15719
  Glitch.config = Config;
15849
- Glitch.auth = Auth;
15850
- Glitch.competitions = Competitions;
15851
15720
  return Glitch;
15852
15721
  }());
15853
15722