glitch-javascript-sdk 0.0.1 → 0.0.2
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 +132 -127
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/Auth.d.ts +34 -2
- package/dist/esm/api/Competitions.d.ts +50 -5
- package/dist/esm/index.js +470 -447
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/util/Requests.d.ts +27 -5
- package/dist/index.d.ts +82 -7
- package/package.json +1 -1
- package/src/api/Auth.ts +38 -3
- package/src/api/Competitions.ts +50 -5
- package/src/util/Requests.ts +46 -31
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
|
|
15666
|
-
|
|
15667
|
-
|
|
15668
|
-
|
|
15669
|
-
|
|
15670
|
-
|
|
15671
|
-
|
|
15672
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
15738
|
-
|
|
15739
|
-
|
|
15740
|
-
url =
|
|
15741
|
-
|
|
15742
|
-
|
|
15743
|
-
|
|
15744
|
-
|
|
15745
|
-
|
|
15746
|
-
|
|
15747
|
-
|
|
15748
|
-
|
|
15749
|
-
|
|
15750
|
-
|
|
15751
|
-
|
|
15752
|
-
|
|
15753
|
-
|
|
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
|
}());
|
|
@@ -15798,9 +15728,41 @@ var AuthRoutes = /** @class */ (function () {
|
|
|
15798
15728
|
var Auth = /** @class */ (function () {
|
|
15799
15729
|
function Auth() {
|
|
15800
15730
|
}
|
|
15801
|
-
|
|
15802
|
-
|
|
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 });
|
|
15803
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
|
+
*/
|
|
15804
15766
|
Auth.register = function (data) {
|
|
15805
15767
|
return Requests.processRoute(AuthRoutes.routes.register, data);
|
|
15806
15768
|
};
|
|
@@ -15823,18 +15785,61 @@ var CompetitionRoutes = /** @class */ (function () {
|
|
|
15823
15785
|
var Competitions = /** @class */ (function () {
|
|
15824
15786
|
function Competitions() {
|
|
15825
15787
|
}
|
|
15788
|
+
/**
|
|
15789
|
+
* List all the competitions
|
|
15790
|
+
*
|
|
15791
|
+
* @see https://api.glitch.fun/api/documentation#/Competitions%20Route/resourceList
|
|
15792
|
+
*
|
|
15793
|
+
* @returns promise
|
|
15794
|
+
*/
|
|
15826
15795
|
Competitions.list = function () {
|
|
15827
15796
|
return Requests.processRoute(CompetitionRoutes.routes.list);
|
|
15828
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
|
+
*/
|
|
15829
15807
|
Competitions.create = function (data) {
|
|
15830
15808
|
return Requests.processRoute(CompetitionRoutes.routes.create, data);
|
|
15831
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
|
+
*/
|
|
15832
15820
|
Competitions.update = function (competition_id, data) {
|
|
15833
15821
|
return Requests.processRoute(CompetitionRoutes.routes.create, data, { competition_id: competition_id });
|
|
15834
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
|
+
*/
|
|
15835
15832
|
Competitions.view = function (competition_id) {
|
|
15836
15833
|
return Requests.processRoute(CompetitionRoutes.routes.view, {}, { competition_id: competition_id });
|
|
15837
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
|
+
*/
|
|
15838
15843
|
Competitions.delete = function (competition_id) {
|
|
15839
15844
|
return Requests.processRoute(CompetitionRoutes.routes.delete, {}, { competition_id: competition_id });
|
|
15840
15845
|
};
|