@reyaxyz/api-sdk 0.50.0 → 0.52.0
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/clients/api-client.js +16 -0
- package/dist/clients/api-client.js.map +1 -1
- package/dist/clients/helpers/constants.js +4 -5
- package/dist/clients/helpers/constants.js.map +1 -1
- package/dist/clients/modules/account/index.js +2 -5
- package/dist/clients/modules/account/index.js.map +1 -1
- package/dist/clients/modules/depth-chart.simulation/index.js +132 -0
- package/dist/clients/modules/depth-chart.simulation/index.js.map +1 -0
- package/dist/clients/modules/depth-chart.simulation/types.js +3 -0
- package/dist/clients/modules/depth-chart.simulation/types.js.map +1 -0
- package/dist/clients/modules/lp/index.js +13 -5
- package/dist/clients/modules/lp/index.js.map +1 -1
- package/dist/clients/modules/lp/types.js.map +1 -1
- package/dist/clients/modules/markets/index.js +2 -5
- package/dist/clients/modules/markets/index.js.map +1 -1
- package/dist/clients/modules/owner/index.js +2 -5
- package/dist/clients/modules/owner/index.js.map +1 -1
- package/dist/clients/modules/tokens/index.js +2 -5
- package/dist/clients/modules/tokens/index.js.map +1 -1
- package/dist/types/clients/api-client.d.ts +10 -0
- package/dist/types/clients/api-client.d.ts.map +1 -1
- package/dist/types/clients/helpers/constants.d.ts +0 -1
- package/dist/types/clients/helpers/constants.d.ts.map +1 -1
- package/dist/types/clients/modules/account/index.d.ts +1 -3
- package/dist/types/clients/modules/account/index.d.ts.map +1 -1
- package/dist/types/clients/modules/depth-chart.simulation/index.d.ts +15 -0
- package/dist/types/clients/modules/depth-chart.simulation/index.d.ts.map +1 -0
- package/dist/types/clients/modules/depth-chart.simulation/types.d.ts +16 -0
- package/dist/types/clients/modules/depth-chart.simulation/types.d.ts.map +1 -0
- package/dist/types/clients/modules/lp/index.d.ts +3 -3
- package/dist/types/clients/modules/lp/index.d.ts.map +1 -1
- package/dist/types/clients/modules/lp/types.d.ts +5 -1
- package/dist/types/clients/modules/lp/types.d.ts.map +1 -1
- package/dist/types/clients/modules/markets/index.d.ts +1 -2
- package/dist/types/clients/modules/markets/index.d.ts.map +1 -1
- package/dist/types/clients/modules/owner/index.d.ts +1 -1
- package/dist/types/clients/modules/owner/index.d.ts.map +1 -1
- package/dist/types/clients/modules/tokens/index.d.ts +1 -1
- package/dist/types/clients/modules/tokens/index.d.ts.map +1 -1
- package/package.json +3 -4
- package/src/clients/api-client.ts +15 -0
- package/src/clients/helpers/constants.ts +1 -3
- package/src/clients/modules/account/index.ts +2 -2
- package/src/clients/modules/depth-chart.simulation/index.ts +102 -0
- package/src/clients/modules/depth-chart.simulation/types.ts +18 -0
- package/src/clients/modules/lp/index.ts +13 -3
- package/src/clients/modules/lp/types.ts +6 -0
- package/src/clients/modules/markets/index.ts +1 -2
- package/src/clients/modules/owner/index.ts +1 -1
- package/src/clients/modules/tokens/index.ts +1 -1
- package/dist/clients/helpers/query-helper.js +0 -21
- package/dist/clients/helpers/query-helper.js.map +0 -1
- package/dist/clients/lib/axios.js +0 -26
- package/dist/clients/lib/axios.js.map +0 -1
- package/dist/clients/modules/rest/index.js +0 -117
- package/dist/clients/modules/rest/index.js.map +0 -1
- package/dist/types/clients/helpers/query-helper.d.ts +0 -2
- package/dist/types/clients/helpers/query-helper.d.ts.map +0 -1
- package/dist/types/clients/lib/axios.d.ts +0 -13
- package/dist/types/clients/lib/axios.d.ts.map +0 -1
- package/dist/types/clients/modules/rest/index.d.ts +0 -10
- package/dist/types/clients/modules/rest/index.d.ts.map +0 -1
- package/src/clients/helpers/query-helper.ts +0 -17
- package/src/clients/lib/axios.ts +0 -28
- package/src/clients/modules/rest/index.ts +0 -69
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var constants_1 = require("../../helpers/constants");
|
|
40
|
-
var query_helper_1 = require("../../helpers/query-helper");
|
|
41
|
-
var axios_1 = require("../../lib/axios");
|
|
42
|
-
var RestClient = /** @class */ (function () {
|
|
43
|
-
function RestClient(host, apiTimeout) {
|
|
44
|
-
this.host = host;
|
|
45
|
-
this.apiTimeout = apiTimeout || constants_1.API_TIMEOUT;
|
|
46
|
-
}
|
|
47
|
-
RestClient.prototype.get = function (requestPath, params) {
|
|
48
|
-
if (params === void 0) { params = {}; }
|
|
49
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
50
|
-
var url, response;
|
|
51
|
-
return __generator(this, function (_a) {
|
|
52
|
-
switch (_a.label) {
|
|
53
|
-
case 0:
|
|
54
|
-
url = "".concat(this.host).concat((0, query_helper_1.generateQueryPath)(requestPath, params));
|
|
55
|
-
return [4 /*yield*/, (0, axios_1.request)(url)];
|
|
56
|
-
case 1:
|
|
57
|
-
response = _a.sent();
|
|
58
|
-
return [2 /*return*/, response.data];
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
RestClient.prototype.post = function (requestPath, params, body, headers) {
|
|
64
|
-
if (params === void 0) { params = {}; }
|
|
65
|
-
if (headers === void 0) { headers = {}; }
|
|
66
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
-
var url, response;
|
|
68
|
-
return __generator(this, function (_a) {
|
|
69
|
-
switch (_a.label) {
|
|
70
|
-
case 0:
|
|
71
|
-
url = "".concat(this.host).concat((0, query_helper_1.generateQueryPath)(requestPath, params));
|
|
72
|
-
return [4 /*yield*/, (0, axios_1.request)(url, axios_1.RequestMethod.POST, body, headers)];
|
|
73
|
-
case 1:
|
|
74
|
-
response = _a.sent();
|
|
75
|
-
return [2 /*return*/, response.data];
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
RestClient.prototype.put = function (requestPath, params, body, headers) {
|
|
81
|
-
if (params === void 0) { params = {}; }
|
|
82
|
-
if (headers === void 0) { headers = {}; }
|
|
83
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
-
var url, response;
|
|
85
|
-
return __generator(this, function (_a) {
|
|
86
|
-
switch (_a.label) {
|
|
87
|
-
case 0:
|
|
88
|
-
url = "".concat(this.host).concat((0, query_helper_1.generateQueryPath)(requestPath, params));
|
|
89
|
-
return [4 /*yield*/, (0, axios_1.request)(url, axios_1.RequestMethod.PUT, body, headers)];
|
|
90
|
-
case 1:
|
|
91
|
-
response = _a.sent();
|
|
92
|
-
return [2 /*return*/, response.data];
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
RestClient.prototype.delete = function (requestPath, params, body, headers) {
|
|
98
|
-
if (params === void 0) { params = {}; }
|
|
99
|
-
if (headers === void 0) { headers = {}; }
|
|
100
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
-
var url, response;
|
|
102
|
-
return __generator(this, function (_a) {
|
|
103
|
-
switch (_a.label) {
|
|
104
|
-
case 0:
|
|
105
|
-
url = "".concat(this.host).concat((0, query_helper_1.generateQueryPath)(requestPath, params));
|
|
106
|
-
return [4 /*yield*/, (0, axios_1.request)(url, axios_1.RequestMethod.DELETE, body, headers)];
|
|
107
|
-
case 1:
|
|
108
|
-
response = _a.sent();
|
|
109
|
-
return [2 /*return*/, response.data];
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
return RestClient;
|
|
115
|
-
}());
|
|
116
|
-
exports.default = RestClient;
|
|
117
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/rest/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAsD;AACtD,2DAA+D;AAC/D,yCAAyD;AACzD;IAIE,oBAAY,IAAY,EAAE,UAA0B;QAClD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI,uBAAW,CAAC;IAC9C,CAAC;IAEK,wBAAG,GAAT,UACE,WAAmB,EACnB,MAAiC;QAAjC,uBAAA,EAAA,WAAiC;;;;;;wBAE3B,GAAG,GAAG,UAAG,IAAI,CAAC,IAAI,SAAG,IAAA,gCAAiB,EAAC,WAAW,EAAE,MAAM,CAAC,CAAE,CAAC;wBACnD,qBAAM,IAAA,eAAO,EAAW,GAAG,CAAC,EAAA;;wBAAvC,QAAQ,GAAG,SAA4B;wBAC7C,sBAAO,QAAQ,CAAC,IAAI,EAAC;;;;KACtB;IAEK,yBAAI,GAAV,UACE,WAAmB,EACnB,MAAiC,EACjC,IAAqB,EACrB,OAAkC;QAFlC,uBAAA,EAAA,WAAiC;QAEjC,wBAAA,EAAA,YAAkC;;;;;;wBAE5B,GAAG,GAAG,UAAG,IAAI,CAAC,IAAI,SAAG,IAAA,gCAAiB,EAAC,WAAW,EAAE,MAAM,CAAC,CAAE,CAAC;wBACnD,qBAAM,IAAA,eAAO,EAC5B,GAAG,EACH,qBAAa,CAAC,IAAI,EAClB,IAAI,EACJ,OAAO,CACR,EAAA;;wBALK,QAAQ,GAAG,SAKhB;wBACD,sBAAO,QAAQ,CAAC,IAAI,EAAC;;;;KACtB;IAEK,wBAAG,GAAT,UACE,WAAmB,EACnB,MAAiC,EACjC,IAAqB,EACrB,OAAkC;QAFlC,uBAAA,EAAA,WAAiC;QAEjC,wBAAA,EAAA,YAAkC;;;;;;wBAE5B,GAAG,GAAG,UAAG,IAAI,CAAC,IAAI,SAAG,IAAA,gCAAiB,EAAC,WAAW,EAAE,MAAM,CAAC,CAAE,CAAC;wBACnD,qBAAM,IAAA,eAAO,EAC5B,GAAG,EACH,qBAAa,CAAC,GAAG,EACjB,IAAI,EACJ,OAAO,CACR,EAAA;;wBALK,QAAQ,GAAG,SAKhB;wBACD,sBAAO,QAAQ,CAAC,IAAI,EAAC;;;;KACtB;IAEK,2BAAM,GAAZ,UACE,WAAmB,EACnB,MAAiC,EACjC,IAAqB,EACrB,OAAkC;QAFlC,uBAAA,EAAA,WAAiC;QAEjC,wBAAA,EAAA,YAAkC;;;;;;wBAE5B,GAAG,GAAG,UAAG,IAAI,CAAC,IAAI,SAAG,IAAA,gCAAiB,EAAC,WAAW,EAAE,MAAM,CAAC,CAAE,CAAC;wBACnD,qBAAM,IAAA,eAAO,EAC5B,GAAG,EACH,qBAAa,CAAC,MAAM,EACpB,IAAI,EACJ,OAAO,CACR,EAAA;;wBALK,QAAQ,GAAG,SAKhB;wBACD,sBAAO,QAAQ,CAAC,IAAI,EAAC;;;;KACtB;IACH,iBAAC;AAAD,CAAC,AAjED,IAiEC","sourcesContent":["import { API_TIMEOUT } from '../../helpers/constants';\nimport { generateQueryPath } from '../../helpers/query-helper';\nimport { RequestMethod, request } from '../../lib/axios';\nexport default class RestClient {\n readonly host: string;\n readonly apiTimeout: number;\n\n constructor(host: string, apiTimeout?: number | null) {\n this.host = host;\n this.apiTimeout = apiTimeout || API_TIMEOUT;\n }\n\n async get<Response>(\n requestPath: string,\n params: NonNullable<unknown> = {},\n ): Promise<Response> {\n const url = `${this.host}${generateQueryPath(requestPath, params)}`;\n const response = await request<Response>(url);\n return response.data;\n }\n\n async post<Response>(\n requestPath: string,\n params: NonNullable<unknown> = {},\n body?: unknown | null,\n headers: NonNullable<unknown> = {},\n ): Promise<Response> {\n const url = `${this.host}${generateQueryPath(requestPath, params)}`;\n const response = await request<Response>(\n url,\n RequestMethod.POST,\n body,\n headers,\n );\n return response.data;\n }\n\n async put<Response>(\n requestPath: string,\n params: NonNullable<unknown> = {},\n body?: unknown | null,\n headers: NonNullable<unknown> = {},\n ): Promise<Response> {\n const url = `${this.host}${generateQueryPath(requestPath, params)}`;\n const response = await request<Response>(\n url,\n RequestMethod.PUT,\n body,\n headers,\n );\n return response.data;\n }\n\n async delete<Response>(\n requestPath: string,\n params: NonNullable<unknown> = {},\n body?: unknown | null,\n headers: NonNullable<unknown> = {},\n ): Promise<Response> {\n const url = `${this.host}${generateQueryPath(requestPath, params)}`;\n const response = await request<Response>(\n url,\n RequestMethod.DELETE,\n body,\n headers,\n );\n return response.data;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query-helper.d.ts","sourceRoot":"/","sources":["clients/helpers/query-helper.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAC3B,MAAM,CAaR"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare enum RequestMethod {
|
|
2
|
-
POST = "POST",
|
|
3
|
-
PUT = "PUT",
|
|
4
|
-
GET = "GET",
|
|
5
|
-
DELETE = "DELETE"
|
|
6
|
-
}
|
|
7
|
-
export type ApiResponse<Data> = {
|
|
8
|
-
status: number;
|
|
9
|
-
data: Data;
|
|
10
|
-
headers: NonNullable<unknown>;
|
|
11
|
-
};
|
|
12
|
-
export declare function request<ResponseData>(url: string, method?: RequestMethod, body?: unknown | null, headers?: NonNullable<unknown>): Promise<ApiResponse<ResponseData>>;
|
|
13
|
-
//# sourceMappingURL=axios.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"axios.d.ts","sourceRoot":"/","sources":["clients/lib/axios.ts"],"names":[],"mappings":"AAEA,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,WAAW,CAAC,IAAI,IAAI;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CAC/B,CAAC;AAEF,wBAAgB,OAAO,CAAC,YAAY,EAClC,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,aAAiC,EACzC,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,EACrB,OAAO,GAAE,WAAW,CAAC,OAAO,CAAM,GACjC,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAOpC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default class RestClient {
|
|
2
|
-
readonly host: string;
|
|
3
|
-
readonly apiTimeout: number;
|
|
4
|
-
constructor(host: string, apiTimeout?: number | null);
|
|
5
|
-
get<Response>(requestPath: string, params?: NonNullable<unknown>): Promise<Response>;
|
|
6
|
-
post<Response>(requestPath: string, params?: NonNullable<unknown>, body?: unknown | null, headers?: NonNullable<unknown>): Promise<Response>;
|
|
7
|
-
put<Response>(requestPath: string, params?: NonNullable<unknown>, body?: unknown | null, headers?: NonNullable<unknown>): Promise<Response>;
|
|
8
|
-
delete<Response>(requestPath: string, params?: NonNullable<unknown>, body?: unknown | null, headers?: NonNullable<unknown>): Promise<Response>;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/rest/index.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAK9C,GAAG,CAAC,QAAQ,EAChB,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,WAAW,CAAC,OAAO,CAAM,GAChC,OAAO,CAAC,QAAQ,CAAC;IAMd,IAAI,CAAC,QAAQ,EACjB,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,WAAW,CAAC,OAAO,CAAM,EACjC,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,EACrB,OAAO,GAAE,WAAW,CAAC,OAAO,CAAM,GACjC,OAAO,CAAC,QAAQ,CAAC;IAWd,GAAG,CAAC,QAAQ,EAChB,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,WAAW,CAAC,OAAO,CAAM,EACjC,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,EACrB,OAAO,GAAE,WAAW,CAAC,OAAO,CAAM,GACjC,OAAO,CAAC,QAAQ,CAAC;IAWd,MAAM,CAAC,QAAQ,EACnB,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,WAAW,CAAC,OAAO,CAAM,EACjC,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,EACrB,OAAO,GAAE,WAAW,CAAC,OAAO,CAAM,GACjC,OAAO,CAAC,QAAQ,CAAC;CAUrB"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export function generateQueryPath(
|
|
2
|
-
url: string,
|
|
3
|
-
params: NonNullable<unknown>,
|
|
4
|
-
): string {
|
|
5
|
-
const definedEntries = Object.entries(params).filter(
|
|
6
|
-
([, value]: [string, unknown]) => value !== undefined,
|
|
7
|
-
);
|
|
8
|
-
|
|
9
|
-
if (!definedEntries.length) {
|
|
10
|
-
return url;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const paramsString = definedEntries
|
|
14
|
-
.map(([key, value]: [string, unknown]) => `${key}=${value}`)
|
|
15
|
-
.join('&');
|
|
16
|
-
return `${url}?${paramsString}`;
|
|
17
|
-
}
|
package/src/clients/lib/axios.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
export enum RequestMethod {
|
|
4
|
-
POST = 'POST',
|
|
5
|
-
PUT = 'PUT',
|
|
6
|
-
GET = 'GET',
|
|
7
|
-
DELETE = 'DELETE',
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type ApiResponse<Data> = {
|
|
11
|
-
status: number;
|
|
12
|
-
data: Data;
|
|
13
|
-
headers: NonNullable<unknown>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export function request<ResponseData>(
|
|
17
|
-
url: string,
|
|
18
|
-
method: RequestMethod = RequestMethod.GET,
|
|
19
|
-
body?: unknown | null,
|
|
20
|
-
headers: NonNullable<unknown> = {},
|
|
21
|
-
): Promise<ApiResponse<ResponseData>> {
|
|
22
|
-
return axios<never, ApiResponse<ResponseData>>({
|
|
23
|
-
url,
|
|
24
|
-
method,
|
|
25
|
-
data: body,
|
|
26
|
-
headers,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { API_TIMEOUT } from '../../helpers/constants';
|
|
2
|
-
import { generateQueryPath } from '../../helpers/query-helper';
|
|
3
|
-
import { RequestMethod, request } from '../../lib/axios';
|
|
4
|
-
export default class RestClient {
|
|
5
|
-
readonly host: string;
|
|
6
|
-
readonly apiTimeout: number;
|
|
7
|
-
|
|
8
|
-
constructor(host: string, apiTimeout?: number | null) {
|
|
9
|
-
this.host = host;
|
|
10
|
-
this.apiTimeout = apiTimeout || API_TIMEOUT;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async get<Response>(
|
|
14
|
-
requestPath: string,
|
|
15
|
-
params: NonNullable<unknown> = {},
|
|
16
|
-
): Promise<Response> {
|
|
17
|
-
const url = `${this.host}${generateQueryPath(requestPath, params)}`;
|
|
18
|
-
const response = await request<Response>(url);
|
|
19
|
-
return response.data;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async post<Response>(
|
|
23
|
-
requestPath: string,
|
|
24
|
-
params: NonNullable<unknown> = {},
|
|
25
|
-
body?: unknown | null,
|
|
26
|
-
headers: NonNullable<unknown> = {},
|
|
27
|
-
): Promise<Response> {
|
|
28
|
-
const url = `${this.host}${generateQueryPath(requestPath, params)}`;
|
|
29
|
-
const response = await request<Response>(
|
|
30
|
-
url,
|
|
31
|
-
RequestMethod.POST,
|
|
32
|
-
body,
|
|
33
|
-
headers,
|
|
34
|
-
);
|
|
35
|
-
return response.data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async put<Response>(
|
|
39
|
-
requestPath: string,
|
|
40
|
-
params: NonNullable<unknown> = {},
|
|
41
|
-
body?: unknown | null,
|
|
42
|
-
headers: NonNullable<unknown> = {},
|
|
43
|
-
): Promise<Response> {
|
|
44
|
-
const url = `${this.host}${generateQueryPath(requestPath, params)}`;
|
|
45
|
-
const response = await request<Response>(
|
|
46
|
-
url,
|
|
47
|
-
RequestMethod.PUT,
|
|
48
|
-
body,
|
|
49
|
-
headers,
|
|
50
|
-
);
|
|
51
|
-
return response.data;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async delete<Response>(
|
|
55
|
-
requestPath: string,
|
|
56
|
-
params: NonNullable<unknown> = {},
|
|
57
|
-
body?: unknown | null,
|
|
58
|
-
headers: NonNullable<unknown> = {},
|
|
59
|
-
): Promise<Response> {
|
|
60
|
-
const url = `${this.host}${generateQueryPath(requestPath, params)}`;
|
|
61
|
-
const response = await request<Response>(
|
|
62
|
-
url,
|
|
63
|
-
RequestMethod.DELETE,
|
|
64
|
-
body,
|
|
65
|
-
headers,
|
|
66
|
-
);
|
|
67
|
-
return response.data;
|
|
68
|
-
}
|
|
69
|
-
}
|