itrm-tools 1.0.45 → 1.0.47

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.
Files changed (86) hide show
  1. package/dist/api/APIRequest.d.ts +67 -67
  2. package/dist/api/APIRequest.js +145 -145
  3. package/dist/api/APIRequest.js.map +1 -1
  4. package/dist/api/APIRequestBuilder.d.ts +20 -20
  5. package/dist/api/APIRequestBuilder.js +14 -14
  6. package/dist/api/APIRouter.d.ts +11 -11
  7. package/dist/api/APIRouter.js +21 -21
  8. package/dist/api/APIService.d.ts +42 -42
  9. package/dist/api/APIService.js +108 -108
  10. package/dist/api/APIService.js.map +1 -1
  11. package/dist/api/ExpressConfiguration.d.ts +4 -4
  12. package/dist/api/ExpressConfiguration.js +2 -2
  13. package/dist/api/HttpsAPIService.d.ts +10 -10
  14. package/dist/api/HttpsAPIService.js +47 -47
  15. package/dist/api/channel/ServerSentEventsManager.d.ts +8 -8
  16. package/dist/api/channel/ServerSentEventsManager.js +25 -25
  17. package/dist/api/check/APIChecker.d.ts +26 -26
  18. package/dist/api/check/APIChecker.js +40 -40
  19. package/dist/api/check/CheckableAPIRequest.d.ts +9 -9
  20. package/dist/api/check/CheckableAPIRequest.js +44 -44
  21. package/dist/api/check/CheckableAPIRouter.d.ts +11 -11
  22. package/dist/api/check/CheckableAPIRouter.js +48 -48
  23. package/dist/api/check/request/CheckableDeleteRequest.d.ts +8 -8
  24. package/dist/api/check/request/CheckableDeleteRequest.js +17 -17
  25. package/dist/api/check/request/CheckableFileUploadingPostRequest.d.ts +11 -11
  26. package/dist/api/check/request/CheckableFileUploadingPostRequest.js +22 -22
  27. package/dist/api/check/request/CheckableGetRequest.d.ts +8 -8
  28. package/dist/api/check/request/CheckableGetRequest.js +17 -17
  29. package/dist/api/check/request/CheckablePostRequest.d.ts +8 -8
  30. package/dist/api/check/request/CheckablePostRequest.js +17 -17
  31. package/dist/api/check/request/CheckablePutRequest.d.ts +8 -8
  32. package/dist/api/check/request/CheckablePutRequest.js +17 -17
  33. package/dist/api/check/route/SimpleCheckableAPIRouter.d.ts +7 -7
  34. package/dist/api/check/route/SimpleCheckableAPIRouter.js +25 -25
  35. package/dist/api/express/ExpressFileUploadingConfiguration.d.ts +6 -6
  36. package/dist/api/express/ExpressFileUploadingConfiguration.js +27 -27
  37. package/dist/api/express/ExpressStandardConfiguration.d.ts +11 -11
  38. package/dist/api/express/ExpressStandardConfiguration.js +29 -29
  39. package/dist/api/request/DeleteRequest.d.ts +7 -7
  40. package/dist/api/request/DeleteRequest.js +16 -16
  41. package/dist/api/request/GetRequest.d.ts +7 -7
  42. package/dist/api/request/GetRequest.js +16 -16
  43. package/dist/api/request/PostRequest.d.ts +7 -7
  44. package/dist/api/request/PostRequest.js +16 -16
  45. package/dist/api/request/PutRequest.d.ts +7 -7
  46. package/dist/api/request/PutRequest.js +16 -16
  47. package/dist/api/request/RequestAxiosCall.d.ts +7 -7
  48. package/dist/api/request/RequestAxiosCall.js +57 -57
  49. package/dist/api/request/crud/CrudManager.d.ts +8 -0
  50. package/dist/api/request/crud/CrudManager.js +3 -0
  51. package/dist/api/request/crud/CrudManager.js.map +1 -0
  52. package/dist/api/request/crud/CrudServiceManager.d.ts +19 -0
  53. package/dist/api/request/crud/CrudServiceManager.js +70 -0
  54. package/dist/api/request/crud/CrudServiceManager.js.map +1 -0
  55. package/dist/api/request/docs/DocumentationModels.d.ts +47 -47
  56. package/dist/api/request/docs/DocumentationModels.js +114 -114
  57. package/dist/api/request/docs/DocumentationRequest.d.ts +12 -12
  58. package/dist/api/request/docs/DocumentationRequest.js +126 -126
  59. package/dist/api/route/SimpleAPIRouter.d.ts +6 -6
  60. package/dist/api/route/SimpleAPIRouter.js +24 -24
  61. package/dist/database/mongoose/MongooseModelManager.d.ts +47 -43
  62. package/dist/database/mongoose/MongooseModelManager.js +65 -65
  63. package/dist/database/mongoose/MongooseModelManager.js.map +1 -1
  64. package/dist/database/redis/RedisConnection.d.ts +7 -7
  65. package/dist/database/redis/RedisConnection.js +17 -17
  66. package/dist/database/redis/RedisModelManager.d.ts +10 -10
  67. package/dist/database/redis/RedisModelManager.js +17 -17
  68. package/dist/database/sequelize/SequelizeConnection.d.ts +16 -16
  69. package/dist/database/sequelize/SequelizeConnection.js +22 -22
  70. package/dist/database/sequelize/SequelizeModelManager.d.ts +26 -26
  71. package/dist/database/sequelize/SequelizeModelManager.js +58 -58
  72. package/dist/index.d.ts +33 -31
  73. package/dist/index.js +69 -67
  74. package/dist/index.js.map +1 -1
  75. package/dist/log/Logger.d.ts +7 -7
  76. package/dist/log/Logger.js +28 -28
  77. package/dist/log/LoggerManager.d.ts +7 -7
  78. package/dist/log/LoggerManager.js +63 -63
  79. package/dist/log/LoggerWebSocket.d.ts +10 -10
  80. package/dist/log/LoggerWebSocket.js +15 -15
  81. package/dist/web3/Coin.d.ts +18 -18
  82. package/dist/web3/Coin.js +22 -22
  83. package/dist/web3/Coin.js.map +1 -1
  84. package/dist/web3/coingecko/CoingeckoPriceFinder.d.ts +10 -10
  85. package/dist/web3/coingecko/CoingeckoPriceFinder.js +88 -88
  86. package/package.json +25 -25
@@ -1,64 +1,64 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.LoggerManager = void 0;
13
- const LoggerWebSocket_1 = require("./LoggerWebSocket");
14
- class LoggerManager {
15
- constructor(url) {
16
- this.url = url;
17
- }
18
- connect() {
19
- return new Promise((resolve, reject) => {
20
- let client = new LoggerWebSocket_1.LoggerWebSocket(this.url);
21
- client.on('open', () => {
22
- console.log("> client connected");
23
- resolve(client);
24
- });
25
- client.on('message', function (data) {
26
- let message = data.toString();
27
- let datum = JSON.parse(message);
28
- if (datum.action === 'LOG') {
29
- delete datum.payload.log._id;
30
- if (datum.payload.log.timestamp >= client.from)
31
- client.transactions.push(datum.payload.log);
32
- }
33
- else if (datum.action === 'FINISHED') {
34
- console.log("> finished");
35
- client.resolve(client.transactions);
36
- }
37
- else if (datum.action === 'EMPTY_ID') {
38
- console.log("> EMPTY_ID: ", datum.payload.message);
39
- client.resolve([]);
40
- }
41
- else {
42
- console.log("> unrecognizeable message: ", message);
43
- client.resolve([]);
44
- }
45
- });
46
- });
47
- }
48
- requestNextLogs(client, executionId) {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- client.transactions = [];
51
- let logs = yield new Promise((resolve, reject) => {
52
- client.resolve = resolve;
53
- client.reject = reject;
54
- console.log("> requesting:", executionId);
55
- client.send(executionId);
56
- });
57
- logs.sort(function (a, b) { return a.timestamp - b.timestamp; });
58
- console.log("> logs:", logs.length);
59
- return logs;
60
- });
61
- }
62
- }
63
- exports.LoggerManager = LoggerManager;
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LoggerManager = void 0;
13
+ const LoggerWebSocket_1 = require("./LoggerWebSocket");
14
+ class LoggerManager {
15
+ constructor(url) {
16
+ this.url = url;
17
+ }
18
+ connect() {
19
+ return new Promise((resolve, reject) => {
20
+ let client = new LoggerWebSocket_1.LoggerWebSocket(this.url);
21
+ client.on('open', () => {
22
+ console.log("> client connected");
23
+ resolve(client);
24
+ });
25
+ client.on('message', function (data) {
26
+ let message = data.toString();
27
+ let datum = JSON.parse(message);
28
+ if (datum.action === 'LOG') {
29
+ delete datum.payload.log._id;
30
+ if (datum.payload.log.timestamp >= client.from)
31
+ client.transactions.push(datum.payload.log);
32
+ }
33
+ else if (datum.action === 'FINISHED') {
34
+ console.log("> finished");
35
+ client.resolve(client.transactions);
36
+ }
37
+ else if (datum.action === 'EMPTY_ID') {
38
+ console.log("> EMPTY_ID: ", datum.payload.message);
39
+ client.resolve([]);
40
+ }
41
+ else {
42
+ console.log("> unrecognizeable message: ", message);
43
+ client.resolve([]);
44
+ }
45
+ });
46
+ });
47
+ }
48
+ requestNextLogs(client, executionId) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ client.transactions = [];
51
+ let logs = yield new Promise((resolve, reject) => {
52
+ client.resolve = resolve;
53
+ client.reject = reject;
54
+ console.log("> requesting:", executionId);
55
+ client.send(executionId);
56
+ });
57
+ logs.sort(function (a, b) { return a.timestamp - b.timestamp; });
58
+ console.log("> logs:", logs.length);
59
+ return logs;
60
+ });
61
+ }
62
+ }
63
+ exports.LoggerManager = LoggerManager;
64
64
  //# sourceMappingURL=LoggerManager.js.map
@@ -1,10 +1,10 @@
1
- /// <reference types="node" />
2
- import { ClientRequestArgs } from 'http';
3
- import WebSocket from 'ws';
4
- export declare class LoggerWebSocket extends WebSocket {
5
- from: number;
6
- transactions: any[];
7
- resolve: any;
8
- reject: any;
9
- constructor(address: string, options?: WebSocket.ClientOptions | ClientRequestArgs | undefined);
10
- }
1
+ /// <reference types="node" />
2
+ import { ClientRequestArgs } from 'http';
3
+ import WebSocket from 'ws';
4
+ export declare class LoggerWebSocket extends WebSocket {
5
+ from: number;
6
+ transactions: any[];
7
+ resolve: any;
8
+ reject: any;
9
+ constructor(address: string, options?: WebSocket.ClientOptions | ClientRequestArgs | undefined);
10
+ }
@@ -1,16 +1,16 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.LoggerWebSocket = void 0;
7
- const ws_1 = __importDefault(require("ws"));
8
- class LoggerWebSocket extends ws_1.default {
9
- constructor(address, options) {
10
- super(address, options);
11
- this.from = 0;
12
- this.transactions = [];
13
- }
14
- }
15
- exports.LoggerWebSocket = LoggerWebSocket;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LoggerWebSocket = void 0;
7
+ const ws_1 = __importDefault(require("ws"));
8
+ class LoggerWebSocket extends ws_1.default {
9
+ constructor(address, options) {
10
+ super(address, options);
11
+ this.from = 0;
12
+ this.transactions = [];
13
+ }
14
+ }
15
+ exports.LoggerWebSocket = LoggerWebSocket;
16
16
  //# sourceMappingURL=LoggerWebSocket.js.map
@@ -1,18 +1,18 @@
1
- export declare enum Coin {
2
- APE = "APE",
3
- ARTX = "ARTX",
4
- ATRI = "ATRI",
5
- BTC = "BTC",
6
- CUBE = "CUBE",
7
- DAI = "DAI",
8
- ETH = "ETH",
9
- MANA = "MANA",
10
- MATIC = "MATIC",
11
- RARI = "RARI",
12
- SAND = "SAND",
13
- SCOTT = "SCOTT",
14
- USDC = "USDC",
15
- USDT = "USDT",
16
- WBTC = "WBTC",
17
- WETH = "WETH"
18
- }
1
+ export declare enum Coin {
2
+ APE = "APE",
3
+ ARTX = "ARTX",
4
+ ATRI = "ATRI",
5
+ BTC = "BTC",
6
+ CUBE = "CUBE",
7
+ DAI = "DAI",
8
+ ETH = "ETH",
9
+ MANA = "MANA",
10
+ MATIC = "MATIC",
11
+ RARI = "RARI",
12
+ SAND = "SAND",
13
+ SCOTT = "SCOTT",
14
+ USDC = "USDC",
15
+ USDT = "USDT",
16
+ WBTC = "WBTC",
17
+ WETH = "WETH"
18
+ }
package/dist/web3/Coin.js CHANGED
@@ -1,23 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Coin = void 0;
4
- var Coin;
5
- (function (Coin) {
6
- Coin["APE"] = "APE";
7
- Coin["ARTX"] = "ARTX";
8
- Coin["ATRI"] = "ATRI";
9
- Coin["BTC"] = "BTC";
10
- Coin["CUBE"] = "CUBE";
11
- Coin["DAI"] = "DAI";
12
- Coin["ETH"] = "ETH";
13
- Coin["MANA"] = "MANA";
14
- Coin["MATIC"] = "MATIC";
15
- Coin["RARI"] = "RARI";
16
- Coin["SAND"] = "SAND";
17
- Coin["SCOTT"] = "SCOTT";
18
- Coin["USDC"] = "USDC";
19
- Coin["USDT"] = "USDT";
20
- Coin["WBTC"] = "WBTC";
21
- Coin["WETH"] = "WETH";
22
- })(Coin = exports.Coin || (exports.Coin = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Coin = void 0;
4
+ var Coin;
5
+ (function (Coin) {
6
+ Coin["APE"] = "APE";
7
+ Coin["ARTX"] = "ARTX";
8
+ Coin["ATRI"] = "ATRI";
9
+ Coin["BTC"] = "BTC";
10
+ Coin["CUBE"] = "CUBE";
11
+ Coin["DAI"] = "DAI";
12
+ Coin["ETH"] = "ETH";
13
+ Coin["MANA"] = "MANA";
14
+ Coin["MATIC"] = "MATIC";
15
+ Coin["RARI"] = "RARI";
16
+ Coin["SAND"] = "SAND";
17
+ Coin["SCOTT"] = "SCOTT";
18
+ Coin["USDC"] = "USDC";
19
+ Coin["USDT"] = "USDT";
20
+ Coin["WBTC"] = "WBTC";
21
+ Coin["WETH"] = "WETH";
22
+ })(Coin || (exports.Coin = Coin = {}));
23
23
  //# sourceMappingURL=Coin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Coin.js","sourceRoot":"","sources":["../../src/web3/Coin.ts"],"names":[],"mappings":";;;AAAA,IAAY,IAiBX;AAjBD,WAAY,IAAI;IACZ,mBAAW,CAAA;IACX,qBAAa,CAAA;IACb,qBAAa,CAAA;IACb,mBAAW,CAAA;IACX,qBAAa,CAAA;IACb,mBAAW,CAAA;IACX,mBAAW,CAAA;IACX,qBAAa,CAAA;IACb,uBAAe,CAAA;IACf,qBAAa,CAAA;IACb,qBAAa,CAAA;IACb,uBAAe,CAAA;IACf,qBAAa,CAAA;IACb,qBAAa,CAAA;IACb,qBAAa,CAAA;IACb,qBAAa,CAAA;AACjB,CAAC,EAjBW,IAAI,GAAJ,YAAI,KAAJ,YAAI,QAiBf"}
1
+ {"version":3,"file":"Coin.js","sourceRoot":"","sources":["../../src/web3/Coin.ts"],"names":[],"mappings":";;;AAAA,IAAY,IAiBX;AAjBD,WAAY,IAAI;IACZ,mBAAW,CAAA;IACX,qBAAa,CAAA;IACb,qBAAa,CAAA;IACb,mBAAW,CAAA;IACX,qBAAa,CAAA;IACb,mBAAW,CAAA;IACX,mBAAW,CAAA;IACX,qBAAa,CAAA;IACb,uBAAe,CAAA;IACf,qBAAa,CAAA;IACb,qBAAa,CAAA;IACb,uBAAe,CAAA;IACf,qBAAa,CAAA;IACb,qBAAa,CAAA;IACb,qBAAa,CAAA;IACb,qBAAa,CAAA;AACjB,CAAC,EAjBW,IAAI,oBAAJ,IAAI,QAiBf"}
@@ -1,10 +1,10 @@
1
- import { Coin } from '../Coin';
2
- export declare class CoingeckoPriceFinder {
3
- private prices;
4
- private pair;
5
- constructor(pair?: string);
6
- getPrice(symbol: Coin, date?: Date): Promise<any>;
7
- private adjustDate;
8
- private findPrice;
9
- parseSymbolId(symbol: Coin): "apecoin" | "artx" | "atari" | "bitcoin" | "somnium-space-cubes" | "dai" | "decentraland" | "matic-network" | "rarible" | "the-sandbox" | "scotty-beam" | "usd-coin" | "tether" | "ethereum";
10
- }
1
+ import { Coin } from '../Coin';
2
+ export declare class CoingeckoPriceFinder {
3
+ private prices;
4
+ private pair;
5
+ constructor(pair?: string);
6
+ getPrice(symbol: Coin, date?: Date): Promise<any>;
7
+ private adjustDate;
8
+ private findPrice;
9
+ parseSymbolId(symbol: Coin): "apecoin" | "artx" | "atari" | "bitcoin" | "somnium-space-cubes" | "dai" | "decentraland" | "matic-network" | "rarible" | "the-sandbox" | "scotty-beam" | "usd-coin" | "tether" | "ethereum";
10
+ }
@@ -1,89 +1,89 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.CoingeckoPriceFinder = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
- const Coin_1 = require("../Coin");
18
- class CoingeckoPriceFinder {
19
- constructor(pair) {
20
- this.prices = {};
21
- this.pair = pair !== null && pair !== void 0 ? pair : "eth";
22
- }
23
- getPrice(symbol, date) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- date = date !== null && date !== void 0 ? date : new Date();
26
- let id = this.parseSymbolId(symbol);
27
- let key = (10000 * date.getFullYear()) + (100 * (date.getMonth() + 1)) + date.getDate();
28
- return yield this.findPrice(id, "" + this.adjustDate(symbol, key));
29
- });
30
- }
31
- adjustDate(symbol, date) {
32
- switch (symbol) {
33
- case Coin_1.Coin.APE: return Math.max(date, 20220317);
34
- case Coin_1.Coin.ARTX: return Math.max(date, 20210404);
35
- case Coin_1.Coin.ATRI: return Math.max(date, 20201102);
36
- case Coin_1.Coin.BTC: return Math.max(date, 20130428);
37
- case Coin_1.Coin.CUBE: return Math.max(date, 20200221);
38
- case Coin_1.Coin.DAI: return Math.max(date, 20191119);
39
- case Coin_1.Coin.MANA: return Math.max(date, 20171028);
40
- case Coin_1.Coin.MATIC: return Math.max(date, 20190427);
41
- case Coin_1.Coin.RARI: return Math.max(date, 20200717);
42
- case Coin_1.Coin.SAND: return Math.max(date, 20200814);
43
- case Coin_1.Coin.SCOTT: return Math.max(date, 20211220);
44
- case Coin_1.Coin.USDC: return Math.max(date, 20181005);
45
- case Coin_1.Coin.WBTC: return Math.max(date, 20130428);
46
- default: return Math.max(date, 20150807);
47
- }
48
- }
49
- findPrice(symbol, date) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- let key = symbol + "_" + date;
52
- if (!this.prices[key])
53
- return new Promise((resolve, reject) => {
54
- let url = "https://api.coingecko.com/api/v3/coins/" + symbol + "/history?date="
55
- + date.substring(6) + "-" + date.substring(4, 6) + "-" + date.substring(0, 4);
56
- console.log("> url:", url);
57
- axios_1.default.get(url, { headers: {
58
- 'Content-Type': 'application/json'
59
- } }).then(response => {
60
- if (response.data.market_data && response.data.market_data.current_price)
61
- this.prices[key] = response.data.market_data.current_price[this.pair];
62
- resolve(this.prices[key]);
63
- }).catch(err => { resolve(this.prices[key]); });
64
- });
65
- return this.prices[key];
66
- });
67
- }
68
- parseSymbolId(symbol) {
69
- switch (symbol) {
70
- case Coin_1.Coin.APE: return "apecoin";
71
- case Coin_1.Coin.ARTX: return "artx";
72
- case Coin_1.Coin.ATRI: return "atari";
73
- case Coin_1.Coin.BTC: return "bitcoin";
74
- case Coin_1.Coin.CUBE: return "somnium-space-cubes";
75
- case Coin_1.Coin.DAI: return "dai";
76
- case Coin_1.Coin.MANA: return "decentraland";
77
- case Coin_1.Coin.MATIC: return "matic-network";
78
- case Coin_1.Coin.RARI: return "rarible";
79
- case Coin_1.Coin.SAND: return "the-sandbox";
80
- case Coin_1.Coin.SCOTT: return "scotty-beam";
81
- case Coin_1.Coin.USDC: return "usd-coin";
82
- case Coin_1.Coin.USDT: return "tether";
83
- case Coin_1.Coin.WBTC: return "bitcoin";
84
- default: return "ethereum";
85
- }
86
- }
87
- }
88
- exports.CoingeckoPriceFinder = CoingeckoPriceFinder;
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CoingeckoPriceFinder = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const Coin_1 = require("../Coin");
18
+ class CoingeckoPriceFinder {
19
+ constructor(pair) {
20
+ this.prices = {};
21
+ this.pair = pair !== null && pair !== void 0 ? pair : "eth";
22
+ }
23
+ getPrice(symbol, date) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ date = date !== null && date !== void 0 ? date : new Date();
26
+ let id = this.parseSymbolId(symbol);
27
+ let key = (10000 * date.getFullYear()) + (100 * (date.getMonth() + 1)) + date.getDate();
28
+ return yield this.findPrice(id, "" + this.adjustDate(symbol, key));
29
+ });
30
+ }
31
+ adjustDate(symbol, date) {
32
+ switch (symbol) {
33
+ case Coin_1.Coin.APE: return Math.max(date, 20220317);
34
+ case Coin_1.Coin.ARTX: return Math.max(date, 20210404);
35
+ case Coin_1.Coin.ATRI: return Math.max(date, 20201102);
36
+ case Coin_1.Coin.BTC: return Math.max(date, 20130428);
37
+ case Coin_1.Coin.CUBE: return Math.max(date, 20200221);
38
+ case Coin_1.Coin.DAI: return Math.max(date, 20191119);
39
+ case Coin_1.Coin.MANA: return Math.max(date, 20171028);
40
+ case Coin_1.Coin.MATIC: return Math.max(date, 20190427);
41
+ case Coin_1.Coin.RARI: return Math.max(date, 20200717);
42
+ case Coin_1.Coin.SAND: return Math.max(date, 20200814);
43
+ case Coin_1.Coin.SCOTT: return Math.max(date, 20211220);
44
+ case Coin_1.Coin.USDC: return Math.max(date, 20181005);
45
+ case Coin_1.Coin.WBTC: return Math.max(date, 20130428);
46
+ default: return Math.max(date, 20150807);
47
+ }
48
+ }
49
+ findPrice(symbol, date) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ let key = symbol + "_" + date;
52
+ if (!this.prices[key])
53
+ return new Promise((resolve, reject) => {
54
+ let url = "https://api.coingecko.com/api/v3/coins/" + symbol + "/history?date="
55
+ + date.substring(6) + "-" + date.substring(4, 6) + "-" + date.substring(0, 4);
56
+ console.log("> url:", url);
57
+ axios_1.default.get(url, { headers: {
58
+ 'Content-Type': 'application/json'
59
+ } }).then(response => {
60
+ if (response.data.market_data && response.data.market_data.current_price)
61
+ this.prices[key] = response.data.market_data.current_price[this.pair];
62
+ resolve(this.prices[key]);
63
+ }).catch(err => { resolve(this.prices[key]); });
64
+ });
65
+ return this.prices[key];
66
+ });
67
+ }
68
+ parseSymbolId(symbol) {
69
+ switch (symbol) {
70
+ case Coin_1.Coin.APE: return "apecoin";
71
+ case Coin_1.Coin.ARTX: return "artx";
72
+ case Coin_1.Coin.ATRI: return "atari";
73
+ case Coin_1.Coin.BTC: return "bitcoin";
74
+ case Coin_1.Coin.CUBE: return "somnium-space-cubes";
75
+ case Coin_1.Coin.DAI: return "dai";
76
+ case Coin_1.Coin.MANA: return "decentraland";
77
+ case Coin_1.Coin.MATIC: return "matic-network";
78
+ case Coin_1.Coin.RARI: return "rarible";
79
+ case Coin_1.Coin.SAND: return "the-sandbox";
80
+ case Coin_1.Coin.SCOTT: return "scotty-beam";
81
+ case Coin_1.Coin.USDC: return "usd-coin";
82
+ case Coin_1.Coin.USDT: return "tether";
83
+ case Coin_1.Coin.WBTC: return "bitcoin";
84
+ default: return "ethereum";
85
+ }
86
+ }
87
+ }
88
+ exports.CoingeckoPriceFinder = CoingeckoPriceFinder;
89
89
  //# sourceMappingURL=CoingeckoPriceFinder.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itrm-tools",
3
- "version": "1.0.45",
3
+ "version": "1.0.47",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,39 +31,39 @@
31
31
  },
32
32
  "homepage": "https://github.com/ITRMachines/itrm-tools#readme",
33
33
  "devDependencies": {
34
- "@types/jest": "^29.2.5",
35
- "@types/multer": "^1.4.7",
36
- "@types/node": "^18.11.18",
37
- "@types/swagger-ui-express": "^4.1.3",
38
- "@types/uuid": "^9.0.0",
39
- "axios-mock-adapter": "^1.21.2",
40
- "jest": "^29.6.2",
41
- "jest-puppeteer": "^9.0.0",
42
- "mongodb-memory-server": "^8.11.1",
43
- "puppeteer": "^20.9.0",
44
- "rimraf": "^3.0.2",
45
- "sqlite3": "^5.1.4",
46
- "ts-jest": "^29.0.3",
47
- "typescript": "^4.9.4",
48
- "uuid": "^9.0.0"
34
+ "@types/jest": "^29.5.6",
35
+ "@types/multer": "^1.4.9",
36
+ "@types/node": "^20.8.7",
37
+ "@types/swagger-ui-express": "^4.1.5",
38
+ "@types/uuid": "^9.0.6",
39
+ "axios-mock-adapter": "^1.22.0",
40
+ "jest": "^29.7.0",
41
+ "jest-puppeteer": "^9.0.1",
42
+ "mongodb-memory-server": "^9.0.1",
43
+ "puppeteer": "^21.4.0",
44
+ "rimraf": "^5.0.5",
45
+ "sqlite3": "^5.1.6",
46
+ "ts-jest": "^29.1.1",
47
+ "typescript": "^5.2.2",
48
+ "uuid": "^9.0.1"
49
49
  },
50
50
  "dependencies": {
51
51
  "@sequelize/core": "^7.0.0-alpha.10",
52
- "@types/cors": "^2.8.13",
53
- "@types/express": "^4.17.15",
54
- "@types/ws": "^8.5.4",
55
- "axios": "^1.2.2",
56
- "axios-retry": "^3.4.0",
52
+ "@types/cors": "^2.8.15",
53
+ "@types/express": "^4.17.20",
54
+ "@types/ws": "^8.5.8",
55
+ "axios": "^1.5.1",
56
+ "axios-retry": "^3.8.0",
57
57
  "body-parser": "^1.20.2",
58
58
  "cors": "^2.8.5",
59
59
  "express": "^4.18.2",
60
60
  "https": "^1.0.0",
61
- "mongoose": "^6.9.1",
61
+ "mongoose": "^7.6.3",
62
62
  "multer": "^1.4.5-lts.1",
63
- "pg": "^8.8.0",
63
+ "pg": "^8.11.3",
64
64
  "pg-hstore": "^2.3.4",
65
- "redis": "^4.5.1",
65
+ "redis": "^4.6.10",
66
66
  "swagger-ui-express": "^5.0.0",
67
- "ws": "^8.12.0"
67
+ "ws": "^8.14.2"
68
68
  }
69
69
  }