@riocrypto/common-server 1.0.613 → 1.0.614

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.
@@ -16,7 +16,7 @@ exports.buildCurrencyAPIClient = void 0;
16
16
  const axios_1 = __importDefault(require("axios"));
17
17
  const secret_manager_client_1 = require("./secret-manager-client");
18
18
  const node_cache_1 = __importDefault(require("node-cache"));
19
- const cache = new node_cache_1.default();
19
+ const cache = new node_cache_1.default({ stdTTL: 60 });
20
20
  class CurrencyAPIClient {
21
21
  constructor(apiKey) {
22
22
  this.apiKey = apiKey;
@@ -24,18 +24,25 @@ class CurrencyAPIClient {
24
24
  convert(from, to) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
26
  try {
27
- const currencyAPIResponse = yield axios_1.default.get(`https://api.currencyapi.com/v3/latest?apikey=${this.apiKey}&base_currency=${from}&currencies=${to}`);
28
- const exchangeRate = currencyAPIResponse.data.data[to].value * 0.9987;
29
- cache.set(`v3/latest?apikey=${this.apiKey}&base_currency=${from}&currencies=${to}`, currencyAPIResponse.data);
30
- return exchangeRate;
27
+ let exchangeRate;
28
+ const cachedResponse = cache.get(`v3/latest?apikey=${this.apiKey}&base_currency=${from}&currencies=${to}`);
29
+ if (cachedResponse) {
30
+ exchangeRate = cachedResponse.data[to].value;
31
+ }
32
+ else {
33
+ const currencyAPIResponse = yield axios_1.default.get(`https://api.currencyapi.com/v3/latest?apikey=${this.apiKey}&base_currency=${from}&currencies=${to}`);
34
+ exchangeRate = currencyAPIResponse.data.data[to].value;
35
+ cache.set(`v3/latest?apikey=${this.apiKey}&base_currency=${from}&currencies=${to}`, currencyAPIResponse.data);
36
+ }
37
+ return exchangeRate * 0.9987;
31
38
  }
32
39
  catch (e) {
33
40
  const cachedResponse = cache.get(`v3/latest?apikey=${this.apiKey}&base_currency=${from}&currencies=${to}`);
34
41
  if (!cachedResponse) {
35
42
  throw new Error(`Unable to get exchange rate from currencyAPI for ${from} to ${to}`);
36
43
  }
37
- const exchangeRate = cachedResponse.data[to].value * 0.9987;
38
- return exchangeRate;
44
+ const exchangeRate = cachedResponse.data[to].value;
45
+ return exchangeRate * 0.9987;
39
46
  }
40
47
  });
41
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.613",
3
+ "version": "1.0.614",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",