@riocrypto/common-server 1.0.611 → 1.0.612
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.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Fiat } from "@riocrypto/common";
|
|
2
|
+
declare class CurrencyAPIClient {
|
|
3
|
+
private apiKey;
|
|
4
|
+
currencyApi: any;
|
|
5
|
+
constructor(apiKey: string);
|
|
6
|
+
convert(from: Fiat, to: Fiat): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
export declare const buildCurrencyAPIClient: () => Promise<CurrencyAPIClient>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
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.buildCurrencyAPIClient = void 0;
|
|
16
|
+
const secret_manager_client_1 = require("./secret-manager-client");
|
|
17
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
const currencyapi_js_1 = __importDefault(require("@everapi/currencyapi-js"));
|
|
20
|
+
const cache = new node_cache_1.default();
|
|
21
|
+
class CurrencyAPIClient {
|
|
22
|
+
constructor(apiKey) {
|
|
23
|
+
this.apiKey = apiKey;
|
|
24
|
+
this.currencyApi = new currencyapi_js_1.default(apiKey);
|
|
25
|
+
}
|
|
26
|
+
convert(from, to) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
try {
|
|
29
|
+
const response = yield this.currencyApi.latest({
|
|
30
|
+
base_currency: from,
|
|
31
|
+
currencies: to,
|
|
32
|
+
});
|
|
33
|
+
const exchangeRate = response.data.data[to] * 0.9987;
|
|
34
|
+
return exchangeRate;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
console.log(e);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const buildCurrencyAPIClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const CURRENCY_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("CURRENCY_API_KEY");
|
|
44
|
+
if (!CURRENCY_API_KEY) {
|
|
45
|
+
throw new Error("Unable to get CURRENCY_API_KEY");
|
|
46
|
+
}
|
|
47
|
+
// Create FixerClient instance and return
|
|
48
|
+
return new CurrencyAPIClient(CURRENCY_API_KEY);
|
|
49
|
+
});
|
|
50
|
+
exports.buildCurrencyAPIClient = buildCurrencyAPIClient;
|
package/build/index.d.ts
CHANGED
|
@@ -40,4 +40,5 @@ export * from "./clients/etherscan-client";
|
|
|
40
40
|
export * from "./clients/rio-client";
|
|
41
41
|
export * from "./clients/secret-manager-client";
|
|
42
42
|
export * from "./clients/gcloud-storage-client";
|
|
43
|
+
export * from "./clients/currency-api-client";
|
|
43
44
|
export * from "./helpers/get-user-helper";
|
package/build/index.js
CHANGED
|
@@ -56,4 +56,5 @@ __exportStar(require("./clients/etherscan-client"), exports);
|
|
|
56
56
|
__exportStar(require("./clients/rio-client"), exports);
|
|
57
57
|
__exportStar(require("./clients/secret-manager-client"), exports);
|
|
58
58
|
__exportStar(require("./clients/gcloud-storage-client"), exports);
|
|
59
|
+
__exportStar(require("./clients/currency-api-client"), exports);
|
|
59
60
|
__exportStar(require("./helpers/get-user-helper"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.612",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@aws-sdk/client-s3": "^3.297.0",
|
|
25
|
+
"@everapi/currencyapi-js": "^1.0.6",
|
|
25
26
|
"@google-cloud/storage": "^6.9.5",
|
|
26
27
|
"@riocrypto/common": "^1.0.582",
|
|
27
28
|
"@types/express": "^4.17.13",
|