@riocrypto/common-server 1.0.915 → 1.0.916

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.
@@ -77,7 +77,7 @@ class AiPriseClient {
77
77
  const buildAiPriseClient = () => __awaiter(void 0, void 0, void 0, function* () {
78
78
  const AIPRISE_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("AIPRISE_API_KEY");
79
79
  if (!AIPRISE_API_KEY) {
80
- throw new Error("Unable to get AIPRISE_API_KEY");
80
+ throw new common_1.SecretManagerError();
81
81
  }
82
82
  // Create FixerClient instance and return
83
83
  return new AiPriseClient(AIPRISE_API_KEY);
@@ -40,6 +40,7 @@ const axios_1 = __importDefault(require("axios"));
40
40
  const crypto = __importStar(require("crypto"));
41
41
  const uuid = __importStar(require("uuid"));
42
42
  const secret_manager_client_1 = require("./secret-manager-client");
43
+ const common_1 = require("@riocrypto/common");
43
44
  class BitstampClient {
44
45
  constructor(apiKey, apiSecret) {
45
46
  this.apiKey = apiKey;
@@ -75,7 +76,7 @@ class BitstampClient {
75
76
  const headers = yield this.getHeaders(payload);
76
77
  const response = yield axios_1.default.post("https://www.bitstamp.net/api/v2/crypto-transactions/", payload_string, { headers });
77
78
  if (response.status !== 200) {
78
- throw new Error("Status code not 200");
79
+ throw new common_1.GenericInternalError("Status code not 200");
79
80
  }
80
81
  return response.data;
81
82
  });
@@ -84,11 +85,11 @@ class BitstampClient {
84
85
  const buildBitstampClient = () => __awaiter(void 0, void 0, void 0, function* () {
85
86
  const BITSTAMP_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("BITSTAMP_API_KEY");
86
87
  if (!BITSTAMP_API_KEY) {
87
- throw new Error("Unable to get BITSTAMP_API_KEY");
88
+ throw new common_1.SecretManagerError();
88
89
  }
89
90
  const BITSTAMP_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("BITSTAMP_SECRET");
90
91
  if (!BITSTAMP_SECRET) {
91
- throw new Error("Unable to get BITSTAMP_SECRET");
92
+ throw new common_1.SecretManagerError();
92
93
  }
93
94
  const bitstampClient = new BitstampClient(BITSTAMP_API_KEY, BITSTAMP_SECRET);
94
95
  return bitstampClient;
@@ -173,7 +173,7 @@ const buildBridgeClient = () => __awaiter(void 0, void 0, void 0, function* () {
173
173
  // Retrieve secrets asynchronously
174
174
  const BRIDGE_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("BRIDGE_API_KEY");
175
175
  if (!BRIDGE_API_KEY) {
176
- throw new Error("Unable to get BRIDGE_API_KEY");
176
+ throw new common_1.SecretManagerError();
177
177
  }
178
178
  // Create GuenoClient instance and return
179
179
  return new BridgeClient(BRIDGE_API_KEY);
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.buildCurrencyAPIClient = void 0;
16
+ const common_1 = require("@riocrypto/common");
16
17
  const axios_1 = __importDefault(require("axios"));
17
18
  const secret_manager_client_1 = require("./secret-manager-client");
18
19
  const node_cache_1 = __importDefault(require("node-cache"));
@@ -38,12 +39,12 @@ class CurrencyAPIClient {
38
39
  catch (e) {
39
40
  const cachedResponse = cache.get(`v3/latest?apikey=${this.apiKey}&base_currency=${from}&currencies=${to}`);
40
41
  if (!cachedResponse) {
41
- throw new Error(`Unable to get exchange rate from currencyAPI for ${from} to ${to}`);
42
+ throw new common_1.GenericInternalError(`Unable to get exchange rate from currencyAPI for ${from} to ${to}`);
42
43
  }
43
44
  const exchangeRate = cachedResponse.data[to].value;
44
45
  }
45
46
  if (!exchangeRate) {
46
- throw new Error("Unable to get exchange rate");
47
+ throw new common_1.GenericInternalError("Unable to get exchange rate");
47
48
  }
48
49
  return exchangeRate;
49
50
  });
@@ -66,7 +67,7 @@ class CurrencyAPIClient {
66
67
  catch (e) {
67
68
  const cachedResponse = cache.get(`v3/range?apikey=${this.apiKey}&datetime_start=${start}&datetime_end=${end}&accuracy=minute&currencies=${to}&base_currency=${from}`);
68
69
  if (!cachedResponse) {
69
- throw new Error(`Unable to get hsitorical exchange rates from currencyAPI for ${from} to ${to}`);
70
+ throw new common_1.GenericInternalError(`Unable to get hsitorical exchange rates from currencyAPI for ${from} to ${to}`);
70
71
  }
71
72
  const exchangeRates = cachedResponse.data;
72
73
  return exchangeRates;
@@ -77,7 +78,7 @@ class CurrencyAPIClient {
77
78
  const buildCurrencyAPIClient = () => __awaiter(void 0, void 0, void 0, function* () {
78
79
  const CURRENCY_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("CURRENCY_API_KEY");
79
80
  if (!CURRENCY_API_KEY) {
80
- throw new Error("Unable to get CURRENCY_API_KEY");
81
+ throw new common_1.SecretManagerError();
81
82
  }
82
83
  // Create FixerClient instance and return
83
84
  return new CurrencyAPIClient(CURRENCY_API_KEY);
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.EtherscanClient = void 0;
13
+ const common_1 = require("@riocrypto/common");
13
14
  const secret_manager_client_1 = require("./secret-manager-client");
14
15
  class EtherscanClient {
15
16
  constructor(axios) {
@@ -19,7 +20,7 @@ class EtherscanClient {
19
20
  return __awaiter(this, void 0, void 0, function* () {
20
21
  const ETHERSCAN_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("ETHERSCAN_API_KEY");
21
22
  if (!ETHERSCAN_API_KEY) {
22
- throw new Error("Unable to get ETHERSCAN_API_KEY");
23
+ throw new common_1.SecretManagerError();
23
24
  }
24
25
  const { data } = yield this.axios.get(`https://api.etherscan.io/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&page=${page}&offset=${offset}&sort=asc&apikey=${ETHERSCAN_API_KEY}`);
25
26
  return data.result;
@@ -20,7 +20,7 @@ const getNetworkFees = (crypto, conversionRateToUSD) => __awaiter(void 0, void 0
20
20
  const fireblocksClient = yield (0, fireblocks_client_1.buildFireblocksClient)();
21
21
  const withdrawFee = yield fireblocksClient.estimateWithdrawFee(crypto, address, 100);
22
22
  if (!withdrawFee) {
23
- throw new Error("Withdraw fee not set");
23
+ throw new common_1.GenericInternalError();
24
24
  }
25
25
  const withdrawFeeUSDResponse = yield ccxt_client_1.ccxtWrapper.getSellQuote(new common_1.CryptoAsset(crypto).getGasSymbol(), common_1.Fiat.USD, undefined, Number(withdrawFee));
26
26
  const withdrawFeeInBaseCrypto = withdrawFeeUSDResponse.amountFiat;
@@ -28,11 +28,11 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
28
28
  throw new common_1.RioSettingsNotFoundError();
29
29
  }
30
30
  if (discount && markup) {
31
- throw new Error("Cannot specify markup and discount");
31
+ throw new common_1.GenericInputError("Cannot specify markup and discount");
32
32
  }
33
33
  amountUSD = amountFiat * conversionRateToUSD;
34
34
  if (!amountUSD) {
35
- throw new Error("Could not convert amount to USD");
35
+ throw new common_1.GenericInternalError("Could not convert amount to USD");
36
36
  }
37
37
  if (partnerId) {
38
38
  const Partner = (0, partner_1.buildPartner)(mongoose);
@@ -44,7 +44,7 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
44
44
  feesComped = true;
45
45
  }
46
46
  if (discount && discount > partner.platformFee) {
47
- throw new Error("Discount cannot be greater than platform fee");
47
+ throw new common_1.GenericInputError("Discount cannot be greater than platform fee");
48
48
  }
49
49
  let netPlatformFee = partner.platformFee;
50
50
  if (discount) {
@@ -60,7 +60,7 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
60
60
  const User = (0, user_1.buildUser)(mongoose);
61
61
  const broker = yield User.findById(brokerId);
62
62
  if (!broker) {
63
- throw new Error("Broker customer not found");
63
+ throw new common_1.NotFoundError("Broker customer");
64
64
  }
65
65
  let volume;
66
66
  if ((_a = broker.attributes) === null || _a === void 0 ? void 0 : _a.includes(common_1.UserAttribute.summedVolumeFees)) {
@@ -75,7 +75,7 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
75
75
  if (range.min <= Number(volume) && range.max >= Number(volume)) {
76
76
  if (discount) {
77
77
  if (discount > range.fee) {
78
- throw new Error("Discount cannot be greater than platform fee");
78
+ throw new common_1.GenericInputError("Discount cannot be greater than platform fee");
79
79
  }
80
80
  else {
81
81
  const netFee = range.fee - discount;
@@ -103,7 +103,7 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
103
103
  netPlatformFee += markup;
104
104
  }
105
105
  if (netPlatformFee < 0) {
106
- throw new Error("Discount cannot be greater than platform fee");
106
+ throw new common_1.GenericInputError("Discount cannot be greater than platform fee");
107
107
  }
108
108
  platformFeeFiat = amountFiat * netPlatformFee;
109
109
  }
@@ -122,7 +122,7 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
122
122
  if (range.min <= Number(volume) && range.max >= Number(volume)) {
123
123
  if (discount) {
124
124
  if (discount > range.fee) {
125
- throw new Error("Discount cannot be greater than platform fee");
125
+ throw new common_1.GenericInputError("Discount cannot be greater than platform fee");
126
126
  }
127
127
  else if (markup) {
128
128
  const netFee = range.fee + markup;
@@ -149,7 +149,7 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
149
149
  netPlatformFee += markup;
150
150
  }
151
151
  if (netPlatformFee < 0) {
152
- throw new Error("Discount cannot be greater than platform fee");
152
+ throw new common_1.GenericInputError("Discount cannot be greater than platform fee");
153
153
  }
154
154
  platformFeeFiat = amountFiat * netPlatformFee;
155
155
  }
@@ -164,7 +164,7 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
164
164
  netPlatformFee += markup;
165
165
  }
166
166
  if (netPlatformFee < 0) {
167
- throw new Error("Discount cannot be greater than platform fee");
167
+ throw new common_1.GenericInputError("Discount cannot be greater than platform fee");
168
168
  }
169
169
  platformFeeFiat = amountFiat * netPlatformFee;
170
170
  partnerFeeFiat = 0;
@@ -28,7 +28,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
28
28
  let apiKey = req.header("x-api-key");
29
29
  const ADMIN_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("ADMIN_API_KEY");
30
30
  if (!ADMIN_API_KEY) {
31
- throw new Error("Unable to get ADMIN_API_KEY");
31
+ throw new common_1.SecretManagerError();
32
32
  }
33
33
  if (apiKey === ADMIN_API_KEY) {
34
34
  req.validAdminApiKey = true;
@@ -71,7 +71,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
71
71
  try {
72
72
  const ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ACCESS_TOKEN_SECRET");
73
73
  if (!ACCESS_TOKEN_SECRET) {
74
- throw new Error("Unable to get ACCESS_TOKEN_SECRET");
74
+ throw new common_1.SecretManagerError();
75
75
  }
76
76
  const payload = jsonwebtoken_1.default.verify(req.cookies.accessToken, ACCESS_TOKEN_SECRET);
77
77
  req.currentAuth = payload;
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.currentAdminAuth = void 0;
16
16
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
17
17
  const secret_manager_client_1 = require("../clients/secret-manager-client");
18
+ const common_1 = require("@riocrypto/common");
18
19
  const currentAdminAuth = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
19
20
  var _a;
20
21
  if (!((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.adminAccesToken)) {
@@ -23,7 +24,7 @@ const currentAdminAuth = (req, res, next) => __awaiter(void 0, void 0, void 0, f
23
24
  try {
24
25
  const ADMIN_ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ADMIN_ACCESS_TOKEN_SECRET");
25
26
  if (!ADMIN_ACCESS_TOKEN_SECRET) {
26
- throw new Error("ADMIN_ACCESS_TOKEN_SECRET");
27
+ throw new common_1.SecretManagerError();
27
28
  }
28
29
  const payload = jsonwebtoken_1.default.verify(req.cookies.adminAccesToken, ADMIN_ACCESS_TOKEN_SECRET);
29
30
  req.currentAdminAuth = payload;
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.currentAuth = void 0;
16
16
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
17
17
  const secret_manager_client_1 = require("../clients/secret-manager-client");
18
+ const common_1 = require("@riocrypto/common");
18
19
  const currentAuth = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
19
20
  var _a;
20
21
  if (!((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.accessToken)) {
@@ -23,7 +24,7 @@ const currentAuth = (req, res, next) => __awaiter(void 0, void 0, void 0, functi
23
24
  try {
24
25
  const ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ACCESS_TOKEN_SECRET");
25
26
  if (!ACCESS_TOKEN_SECRET) {
26
- throw new Error("Unable to get ACCESS_TOKEN_SECRET");
27
+ throw new common_1.SecretManagerError();
27
28
  }
28
29
  const payload = jsonwebtoken_1.default.verify(req.cookies.accessToken, ACCESS_TOKEN_SECRET);
29
30
  req.currentAuth = payload;
@@ -28,7 +28,7 @@ const getOrder = (req, res, next, mongoose, onlyBankOrders) => __awaiter(void 0,
28
28
  const Order = yield (0, order_1.buildOrder)(mongoose);
29
29
  const order = yield Order.findById(orderId);
30
30
  if (!order) {
31
- throw new Error();
31
+ throw new common_1.NotFoundError("Order");
32
32
  }
33
33
  if (onlyBankOrders) {
34
34
  if ([
@@ -17,12 +17,13 @@ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
17
17
  const partner_1 = require("../models/partner");
18
18
  const apiKey_1 = require("../services/apiKey");
19
19
  const secret_manager_client_1 = require("../clients/secret-manager-client");
20
+ const common_1 = require("@riocrypto/common");
20
21
  const getPartner = (req, res, next, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
21
22
  try {
22
23
  if (!req.headers["x-api-key"]) {
23
24
  const PARTNER_ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("PARTNER_ACCESS_TOKEN_SECRET");
24
25
  if (!PARTNER_ACCESS_TOKEN_SECRET) {
25
- throw new Error("Unable to get PARTNER_ACCESS_TOKEN_SECRET");
26
+ throw new common_1.SecretManagerError();
26
27
  }
27
28
  const payload = jsonwebtoken_1.default.verify(req.cookies.partnerAuthJwt, PARTNER_ACCESS_TOKEN_SECRET);
28
29
  req.partnerId = payload.partnerId;
@@ -11,11 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.verifyAdminApiKey = void 0;
13
13
  const secret_manager_client_1 = require("../clients/secret-manager-client");
14
+ const common_1 = require("@riocrypto/common");
14
15
  const verifyAdminApiKey = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
15
16
  let apiKey = req.header("x-api-key");
16
17
  const ADMIN_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("ADMIN_API_KEY");
17
18
  if (!ADMIN_API_KEY) {
18
- throw new Error("Unable to get ADMIN_API_KEY");
19
+ throw new common_1.SecretManagerError();
19
20
  }
20
21
  if (apiKey === ADMIN_API_KEY) {
21
22
  req.validAdminApiKey = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.915",
3
+ "version": "1.0.916",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "@aws-sdk/client-s3": "^3.297.0",
25
25
  "@everapi/currencyapi-js": "^1.0.6",
26
26
  "@google-cloud/storage": "^6.9.5",
27
- "@riocrypto/common": "^1.0.785",
27
+ "@riocrypto/common": "^1.0.787",
28
28
  "@types/express": "^4.17.13",
29
29
  "axios": "^0.27.2",
30
30
  "ccxt": "^3.0.30",