@riocrypto/common-server 1.0.1896 → 1.0.1898
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/build/clients/bridge-client.js +0 -1
- package/build/clients/currency-api-client.js +3 -2
- package/build/clients/fireblocks-client.js +0 -3
- package/build/clients/slack-client.js +3 -1
- package/build/helpers/get-network-fees.js +0 -31
- package/build/middlewares/authorize.js +1 -3
- package/build/services/logger.d.ts +1 -3
- package/build/services/logger.js +35 -89
- package/package.json +1 -1
|
@@ -179,7 +179,6 @@ class BridgeClient {
|
|
|
179
179
|
}
|
|
180
180
|
getExternalAccount(bridgeCustomerId, externalAccountId) {
|
|
181
181
|
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
-
console.log("getting external account", `${this.baseUrl}/v0/customers/${bridgeCustomerId}/external_accounts/${externalAccountId}`);
|
|
183
182
|
const { data } = yield axios_with_logging_1.default.get(`${this.baseUrl}/v0/customers/${bridgeCustomerId}/external_accounts/${externalAccountId}`, {
|
|
184
183
|
headers: {
|
|
185
184
|
"Api-Key": this.apiKey,
|
|
@@ -17,12 +17,14 @@ const common_1 = require("@riocrypto/common");
|
|
|
17
17
|
const axios_with_logging_1 = __importDefault(require("./axios-with-logging"));
|
|
18
18
|
const secret_manager_client_1 = require("./secret-manager-client");
|
|
19
19
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
20
|
+
const logger_1 = __importDefault(require("../services/logger"));
|
|
20
21
|
const cache = new node_cache_1.default({ stdTTL: 10 });
|
|
21
22
|
class CurrencyAPIClient {
|
|
22
23
|
constructor(apiKey) {
|
|
23
24
|
this.apiKey = apiKey;
|
|
24
25
|
}
|
|
25
26
|
convert(from, to) {
|
|
27
|
+
var _a;
|
|
26
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
29
|
let exchangeRate = 0;
|
|
28
30
|
try {
|
|
@@ -44,7 +46,7 @@ class CurrencyAPIClient {
|
|
|
44
46
|
const exchangeRate = cachedResponse.data[to].value;
|
|
45
47
|
}
|
|
46
48
|
if (!exchangeRate) {
|
|
47
|
-
|
|
49
|
+
(_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.error("Unable to get exchange rate");
|
|
48
50
|
throw new common_1.GenericInternalError("Unable to get exchange rate");
|
|
49
51
|
}
|
|
50
52
|
return exchangeRate;
|
|
@@ -68,7 +70,6 @@ class CurrencyAPIClient {
|
|
|
68
70
|
catch (e) {
|
|
69
71
|
const cachedResponse = cache.get(`v3/range?apikey=${this.apiKey}&datetime_start=${start}&datetime_end=${end}&accuracy=minute¤cies=${to}&base_currency=${from}`);
|
|
70
72
|
if (!cachedResponse) {
|
|
71
|
-
console.log(`Unable to get hsitorical exchange rates from currencyAPI for ${from} to ${to}`);
|
|
72
73
|
throw new common_1.GenericInternalError(`Unable to get hsitorical exchange rates from currencyAPI for ${from} to ${to}`);
|
|
73
74
|
}
|
|
74
75
|
const exchangeRates = cachedResponse.data;
|
|
@@ -224,14 +224,11 @@ class FireblocksClient {
|
|
|
224
224
|
common_1.Crypto.USDTTron,
|
|
225
225
|
];
|
|
226
226
|
if (filterList.includes(asset.id)) {
|
|
227
|
-
console.log(asset.id);
|
|
228
|
-
console.log(asset.available);
|
|
229
227
|
balance += Number(asset.available);
|
|
230
228
|
}
|
|
231
229
|
});
|
|
232
230
|
}
|
|
233
231
|
});
|
|
234
|
-
console.log(assets);
|
|
235
232
|
return balance;
|
|
236
233
|
});
|
|
237
234
|
}
|
|
@@ -13,10 +13,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.slackClient = void 0;
|
|
16
|
+
const logger_1 = __importDefault(require("../services/logger"));
|
|
16
17
|
const axios_with_logging_1 = __importDefault(require("./axios-with-logging"));
|
|
17
18
|
class SlackClient {
|
|
18
19
|
constructor() { }
|
|
19
20
|
sendMessageWithWebhook(message, webhookUrl) {
|
|
21
|
+
var _a;
|
|
20
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
23
|
try {
|
|
22
24
|
yield axios_with_logging_1.default.post(webhookUrl, {
|
|
@@ -24,7 +26,7 @@ class SlackClient {
|
|
|
24
26
|
});
|
|
25
27
|
}
|
|
26
28
|
catch (error) {
|
|
27
|
-
|
|
29
|
+
(_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.error(error);
|
|
28
30
|
}
|
|
29
31
|
});
|
|
30
32
|
}
|
|
@@ -3,37 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getNetworkFees = void 0;
|
|
4
4
|
const common_1 = require("@riocrypto/common");
|
|
5
5
|
const getNetworkFees = (crypto, conversionRateToUSD) => {
|
|
6
|
-
// const address =
|
|
7
|
-
// crypto === Crypto.USDCSolana
|
|
8
|
-
// ? "HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH"
|
|
9
|
-
// : "0x66ECBd38905CC32249ddd6f4f0B4A3DdDDCbd608";
|
|
10
|
-
// const fireblocksClient = await buildFireblocksClient();
|
|
11
|
-
// // Hacky way bc ccxt doesn't support TRON, so quote in MATIC
|
|
12
|
-
// const cryptoToWithdraw =
|
|
13
|
-
// crypto === Crypto.USDTTron ? Crypto.USDCPolygon : crypto;
|
|
14
|
-
// const withdrawFee = await fireblocksClient.estimateWithdrawFee(
|
|
15
|
-
// cryptoToWithdraw,
|
|
16
|
-
// address,
|
|
17
|
-
// 100
|
|
18
|
-
// );
|
|
19
|
-
// if (!withdrawFee) {
|
|
20
|
-
// console.log("No withdraw fee");
|
|
21
|
-
// throw new GenericInternalError();
|
|
22
|
-
// }
|
|
23
|
-
// // Hacky way bc ccxt doesn't support TRON, so quote in MATIC
|
|
24
|
-
// const gasSymbol =
|
|
25
|
-
// crypto === Crypto.USDTTron
|
|
26
|
-
// ? "MATIC"
|
|
27
|
-
// : new CryptoAsset(crypto).getGasSymbol();
|
|
28
|
-
// const withdrawFeeUSDResponse = await ccxtWrapper.getSellQuote(
|
|
29
|
-
// gasSymbol as Crypto,
|
|
30
|
-
// Fiat.USD,
|
|
31
|
-
// undefined,
|
|
32
|
-
// Number(withdrawFee)
|
|
33
|
-
// );
|
|
34
|
-
// const withdrawFeeInBaseCrypto = withdrawFeeUSDResponse.amountFiat;
|
|
35
|
-
// const withdrawFeeInBaseFiat =
|
|
36
|
-
// Number(withdrawFeeUSDResponse.amountFiat) * (1 / conversionRateToUSD);
|
|
37
6
|
let withdrawFeeInUSD = 0;
|
|
38
7
|
if (crypto === common_1.Crypto.USDTTron) {
|
|
39
8
|
withdrawFeeInUSD = 3;
|
|
@@ -55,9 +55,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
55
55
|
req.adminAuth = adminAuth;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
catch (err) {
|
|
59
|
-
console.log(err);
|
|
60
|
-
}
|
|
58
|
+
catch (err) { }
|
|
61
59
|
}
|
|
62
60
|
else if ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.adminAccessToken) {
|
|
63
61
|
try {
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { Logger } from "winston";
|
|
2
2
|
declare class LoggerService {
|
|
3
|
-
private static instance;
|
|
4
3
|
private logger;
|
|
5
|
-
|
|
4
|
+
constructor();
|
|
6
5
|
private maskValue;
|
|
7
6
|
private maskSensitiveData;
|
|
8
7
|
private requestMethodFilter;
|
|
9
8
|
getLogger(): Logger;
|
|
10
|
-
static getInstance(): LoggerService;
|
|
11
9
|
initLogger(): Promise<void>;
|
|
12
10
|
}
|
|
13
11
|
declare const loggerService: LoggerService;
|
package/build/services/logger.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -31,25 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
9
|
});
|
|
33
10
|
};
|
|
34
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
35
|
-
var t = {};
|
|
36
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
37
|
-
t[p] = s[p];
|
|
38
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
39
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
40
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
41
|
-
t[p[i]] = s[p[i]];
|
|
42
|
-
}
|
|
43
|
-
return t;
|
|
44
|
-
};
|
|
45
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const common_1 = require("@riocrypto/common");
|
|
46
13
|
const winston_1 = require("winston");
|
|
47
14
|
class LoggerService {
|
|
48
15
|
constructor() {
|
|
49
16
|
this.maskSensitiveData = (0, winston_1.format)((info) => {
|
|
50
|
-
var _a, _b, _c, _d, _e, _f;
|
|
51
17
|
// Mask sensitive headers
|
|
52
|
-
if (
|
|
18
|
+
if (info.meta && info.meta.req && info.meta.req.headers) {
|
|
53
19
|
const headers = info.meta.req.headers;
|
|
54
20
|
const headerKeysToMask = [
|
|
55
21
|
"x-api-key",
|
|
@@ -58,7 +24,7 @@ class LoggerService {
|
|
|
58
24
|
];
|
|
59
25
|
headerKeysToMask.forEach((key) => {
|
|
60
26
|
if (headers[key]) {
|
|
61
|
-
headers[key] = this.maskValue(headers[key]);
|
|
27
|
+
headers[key] = this.maskValue(headers[key]); // Use maskValue function
|
|
62
28
|
}
|
|
63
29
|
});
|
|
64
30
|
// Mask cookies specifically
|
|
@@ -67,23 +33,20 @@ class LoggerService {
|
|
|
67
33
|
.split("; ")
|
|
68
34
|
.map((cookie) => {
|
|
69
35
|
const [key, value] = cookie.split("=");
|
|
70
|
-
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
|
|
76
|
-
];
|
|
77
|
-
if (sensitiveCookies.includes(key)) {
|
|
78
|
-
return `${key}=${this.maskValue(value)}`;
|
|
36
|
+
if (key === "accessToken" ||
|
|
37
|
+
key === "adminAccessToken" ||
|
|
38
|
+
key === "refreshToken" ||
|
|
39
|
+
key === "adminRefreshToken" ||
|
|
40
|
+
key === "phoneVerifiedJWT") {
|
|
41
|
+
return `${key}=${this.maskValue(value)}`; // Mask the sensitive cookie
|
|
79
42
|
}
|
|
80
|
-
return cookie;
|
|
43
|
+
return cookie; // Return unmodified if not sensitive
|
|
81
44
|
})
|
|
82
45
|
.join("; ");
|
|
83
46
|
}
|
|
84
47
|
}
|
|
85
48
|
// Mask sensitive request body fields
|
|
86
|
-
if (
|
|
49
|
+
if (info.meta && info.meta.req && info.meta.req.body) {
|
|
87
50
|
const requestBodyFieldsToMask = [
|
|
88
51
|
"password",
|
|
89
52
|
"newPassword",
|
|
@@ -93,29 +56,26 @@ class LoggerService {
|
|
|
93
56
|
];
|
|
94
57
|
requestBodyFieldsToMask.forEach((field) => {
|
|
95
58
|
if (info.meta.req.body.hasOwnProperty(field)) {
|
|
96
|
-
info.meta.req.body[field] = this.maskValue(info.meta.req.body[field]);
|
|
59
|
+
info.meta.req.body[field] = this.maskValue(info.meta.req.body[field]); // Use maskValue function
|
|
97
60
|
}
|
|
98
61
|
});
|
|
99
62
|
}
|
|
100
63
|
// Mask sensitive response body fields
|
|
101
|
-
if (
|
|
102
|
-
const responseBodyFieldsToMask = ["secret", "
|
|
64
|
+
if (info.meta && info.meta.res && info.meta.res.body) {
|
|
65
|
+
const responseBodyFieldsToMask = ["secret", "value"];
|
|
103
66
|
responseBodyFieldsToMask.forEach((field) => {
|
|
104
67
|
if (info.meta.res.body.hasOwnProperty(field)) {
|
|
105
|
-
info.meta.res.body[field] = this.maskValue(info.meta.res.body[field]);
|
|
68
|
+
info.meta.res.body[field] = this.maskValue(info.meta.res.body[field]); // Use maskValue function
|
|
106
69
|
}
|
|
107
70
|
});
|
|
108
71
|
}
|
|
109
72
|
return info;
|
|
110
73
|
});
|
|
111
74
|
this.requestMethodFilter = (0, winston_1.format)((info) => {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
"DELETE",
|
|
117
|
-
];
|
|
118
|
-
if (((_b = info.meta) === null || _b === void 0 ? void 0 : _b.req) && allowedMethods.includes(info.meta.req.method)) {
|
|
75
|
+
const allowedMethods = ["POST", "PATCH", "DELETE"];
|
|
76
|
+
if (info.meta &&
|
|
77
|
+
info.meta.req &&
|
|
78
|
+
allowedMethods.includes(info.meta.req.method)) {
|
|
119
79
|
return info;
|
|
120
80
|
}
|
|
121
81
|
return false; // Filter out logs for other methods
|
|
@@ -129,43 +89,29 @@ class LoggerService {
|
|
|
129
89
|
}
|
|
130
90
|
getLogger() {
|
|
131
91
|
if (!this.logger) {
|
|
132
|
-
|
|
92
|
+
return null;
|
|
133
93
|
}
|
|
134
94
|
return this.logger;
|
|
135
95
|
}
|
|
136
|
-
static getInstance() {
|
|
137
|
-
if (!LoggerService.instance) {
|
|
138
|
-
LoggerService.instance = new LoggerService();
|
|
139
|
-
}
|
|
140
|
-
return LoggerService.instance;
|
|
141
|
-
}
|
|
142
96
|
initLogger() {
|
|
143
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
})),
|
|
153
|
-
transports: [
|
|
154
|
-
new winston_1.transports.Console(),
|
|
155
|
-
// @ts-ignore
|
|
156
|
-
HyperDX.getWinstonTransport("info", {
|
|
157
|
-
// Send logs info and above
|
|
158
|
-
detectResources: true,
|
|
159
|
-
}),
|
|
160
|
-
],
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
console.error("Failed to initialize logger:", error);
|
|
165
|
-
// Handle the error as needed
|
|
98
|
+
const logLevel = "info";
|
|
99
|
+
const transportsArray = [new winston_1.transports.Console()];
|
|
100
|
+
const { getWinsonTransport } = yield require("@hyperdx/node-opentelemetry");
|
|
101
|
+
if (process.env.RIO_ENV !== common_1.RioEnv.Local) {
|
|
102
|
+
transportsArray.push(getWinsonTransport("info", {
|
|
103
|
+
apiKey: process.env.HYPERDX_API_KEY,
|
|
104
|
+
service: process.env.OTEL_SERVICE_NAME,
|
|
105
|
+
}));
|
|
166
106
|
}
|
|
107
|
+
this.logger = (0, winston_1.createLogger)({
|
|
108
|
+
level: logLevel,
|
|
109
|
+
format: winston_1.format.combine(winston_1.format.timestamp(), this.maskSensitiveData(), this.requestMethodFilter(), // Add the request method filter
|
|
110
|
+
winston_1.format.json(), winston_1.format.prettyPrint()),
|
|
111
|
+
transports: transportsArray,
|
|
112
|
+
});
|
|
167
113
|
});
|
|
168
114
|
}
|
|
169
115
|
}
|
|
170
|
-
const loggerService = LoggerService
|
|
116
|
+
const loggerService = new LoggerService();
|
|
171
117
|
exports.default = loggerService;
|