glitch-javascript-sdk 0.1.2 → 0.1.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.
@@ -0,0 +1,11 @@
1
+ declare class Parser {
2
+ /**
3
+ * To be used inside a catch close, this function will parse out any JSON in a error response from the api.
4
+ *
5
+ * @param error The Error object from the catch clause
6
+ *
7
+ * @returns Either returns a JSON object or false.
8
+ */
9
+ static parseJSONFromError(error: Error): object | boolean;
10
+ }
11
+ export default Parser;
package/dist/index.d.ts CHANGED
@@ -1129,6 +1129,65 @@ declare class Waitlists {
1129
1129
  static delete<T>(waitlist_id: string): AxiosPromise<Response<T>>;
1130
1130
  }
1131
1131
 
1132
+ interface Route {
1133
+ url: string;
1134
+ method: string;
1135
+ }
1136
+
1137
+ declare class Requests {
1138
+ config: Config;
1139
+ private static baseUrl;
1140
+ private static authToken;
1141
+ constructor(config: Config);
1142
+ /**
1143
+ * Sets the base url of the API.
1144
+ *
1145
+ * @param url The url to of the API.
1146
+ */
1147
+ static setBaseUrl(url: string): void;
1148
+ /**
1149
+ * Sets the JSON Web token
1150
+ *
1151
+ * @param token
1152
+ */
1153
+ static setAuthToken(token: string): void;
1154
+ private static request;
1155
+ /**
1156
+ * Calls a GET request to the url endpoint.
1157
+ *
1158
+ * @param url
1159
+ * @returns
1160
+ */
1161
+ static get<T>(url: string): AxiosPromise<Response<T>>;
1162
+ static post<T>(url: string, data: any): AxiosPromise<Response<T>>;
1163
+ static put<T>(url: string, data: any): AxiosPromise<Response<T>>;
1164
+ static delete<T>(url: string): AxiosPromise<Response<T>>;
1165
+ static uploadFile<T>(url: string, filename: string, file: File, data?: any): AxiosPromise<Response<T>>;
1166
+ static uploadBlob<T>(url: string, filename: string, blob: Blob, data?: any): AxiosPromise<Response<T>>;
1167
+ /**
1168
+ * The Route class contains the method and url, thereforce items can be
1169
+ * automatically routed depending on the configuration.
1170
+ *
1171
+ * @param route
1172
+ * @param data
1173
+ * @returns
1174
+ */
1175
+ static processRoute<T>(route: Route, data?: object, routeReplace?: {
1176
+ [key: string]: any;
1177
+ }): AxiosPromise<Response<T>>;
1178
+ }
1179
+
1180
+ declare class Parser {
1181
+ /**
1182
+ * To be used inside a catch close, this function will parse out any JSON in a error response from the api.
1183
+ *
1184
+ * @param error The Error object from the catch clause
1185
+ *
1186
+ * @returns Either returns a JSON object or false.
1187
+ */
1188
+ static parseJSONFromError(error: Error): object | boolean;
1189
+ }
1190
+
1132
1191
  declare class Glitch {
1133
1192
  static config: {
1134
1193
  Config: typeof Config;
@@ -1141,6 +1200,10 @@ declare class Glitch {
1141
1200
  Teams: typeof Teams;
1142
1201
  Waitlists: typeof Waitlists;
1143
1202
  };
1203
+ static util: {
1204
+ Requests: typeof Requests;
1205
+ Parser: typeof Parser;
1206
+ };
1144
1207
  }
1145
1208
 
1146
1209
  export { Glitch as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glitch-javascript-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Javascrip SDK for GLitch",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
package/src/index.ts CHANGED
@@ -10,6 +10,9 @@ import { Events } from "./api";
10
10
  import { Teams } from "./api";
11
11
  import { Waitlists } from "./api";
12
12
 
13
+ import Requests from "./util/Requests";
14
+ import Parser from "./util/Parser";
15
+
13
16
  class Glitch {
14
17
 
15
18
  public static config = {
@@ -25,6 +28,11 @@ class Glitch {
25
28
  Waitlists: Waitlists
26
29
  }
27
30
 
31
+ public static util = {
32
+ Requests : Requests,
33
+ Parser : Parser
34
+ }
35
+
28
36
 
29
37
  }
30
38
 
@@ -0,0 +1,24 @@
1
+ class Parser {
2
+
3
+ /**
4
+ * To be used inside a catch close, this function will parse out any JSON in a error response from the api.
5
+ *
6
+ * @param error The Error object from the catch clause
7
+ *
8
+ * @returns Either returns a JSON object or false.
9
+ */
10
+ public static parseJSONFromError(error: Error): object | boolean {
11
+
12
+ let errorString = error.toString();
13
+
14
+ errorString = errorString.replace('Error: ', '');
15
+
16
+ try {
17
+ return JSON.parse(errorString);
18
+ } catch (e) {
19
+ return false;
20
+ }
21
+ }
22
+ }
23
+
24
+ export default Parser;