@riocrypto/common-server 1.0.1038 → 1.0.1039

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,11 @@
1
+ import { Quote, Fiat } from "@riocrypto/common";
2
+ declare class ClusterClient {
3
+ private baseUrl;
4
+ private clusterApiKey;
5
+ private axios;
6
+ constructor(baseUrl: string, clusterApiKey: string);
7
+ getNewQuote(orderId: string, quote: Quote): Promise<Quote>;
8
+ getBalance(asset: Crypto | Fiat): Promise<number>;
9
+ }
10
+ export declare const buildClusterClient: () => Promise<ClusterClient>;
11
+ export {};
@@ -0,0 +1,76 @@
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.buildClusterClient = void 0;
16
+ const common_1 = require("@riocrypto/common");
17
+ const axios_1 = __importDefault(require("axios"));
18
+ const secret_manager_client_1 = require("./secret-manager-client");
19
+ class ClusterClient {
20
+ constructor(baseUrl, clusterApiKey) {
21
+ this.baseUrl = baseUrl;
22
+ this.clusterApiKey = clusterApiKey;
23
+ this.axios = axios_1.default.create({
24
+ baseURL: baseUrl,
25
+ headers: {
26
+ Host: process.env.RIO_ENV === common_1.RioEnv.Development
27
+ ? "dev.riocrypto.com"
28
+ : process.env.RIO_ENV === common_1.RioEnv.Staging
29
+ ? "staging.riocrypto.com"
30
+ : process.env.RIO_ENV === common_1.RioEnv.Sandbox
31
+ ? "sandbox.riocrypto.com"
32
+ : "www.riocrypto.com",
33
+ },
34
+ });
35
+ }
36
+ getNewQuote(orderId, quote) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const response = yield this.axios.post(`${this.baseUrl}/api/quotes`, {
39
+ orderId,
40
+ userId: quote.userId,
41
+ side: quote.side,
42
+ crypto: quote.crypto,
43
+ fiat: quote.fiat,
44
+ amountFiat: !quote.quoteInCrypto ? quote.amountFiat : undefined,
45
+ amountCrypto: quote.quoteInCrypto ? quote.amountCrypto : undefined,
46
+ country: quote.country,
47
+ discount: quote.discount,
48
+ markup: quote.markup,
49
+ noMarkups: quote.noMarkups,
50
+ });
51
+ return response.data.balance;
52
+ });
53
+ }
54
+ getBalance(asset) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const rioResponse = yield this.axios.get(`${this.baseUrl}/api/wallet/balances/${asset}`);
57
+ return rioResponse.data.balance;
58
+ });
59
+ }
60
+ }
61
+ const buildClusterClient = () => __awaiter(void 0, void 0, void 0, function* () {
62
+ // Retrieve secrets asynchronously
63
+ const CLUSTER_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("CLUSTER_API_KEY");
64
+ if (!CLUSTER_API_KEY) {
65
+ throw new common_1.SecretManagerError();
66
+ }
67
+ const baseUrl = process.env.RIO_ENV === common_1.RioEnv.Development
68
+ ? "https://dev.riotransfer.co"
69
+ : process.env.RIO_ENV === common_1.RioEnv.Production
70
+ ? "https://www.riotransfer.co"
71
+ : process.env.RIO_ENV === common_1.RioEnv.Staging
72
+ ? "https://staging.riotransfer.co"
73
+ : "https://sandbox.riotransfer.co";
74
+ return new ClusterClient(baseUrl, CLUSTER_API_KEY);
75
+ });
76
+ exports.buildClusterClient = buildClusterClient;
package/build/index.d.ts CHANGED
@@ -53,6 +53,7 @@ export * from "./clients/aiprise-client";
53
53
  export * from "./clients/bridge-client";
54
54
  export * from "./clients/google-sheets-api-client";
55
55
  export * from "./clients/invopop-client";
56
+ export * from "./clients/cluster-client";
56
57
  export * from "./helpers/get-user-helper";
57
58
  export * from "./helpers/get-platform-fees";
58
59
  export * from "./helpers/get-processor-fees";
package/build/index.js CHANGED
@@ -69,6 +69,7 @@ __exportStar(require("./clients/aiprise-client"), exports);
69
69
  __exportStar(require("./clients/bridge-client"), exports);
70
70
  __exportStar(require("./clients/google-sheets-api-client"), exports);
71
71
  __exportStar(require("./clients/invopop-client"), exports);
72
+ __exportStar(require("./clients/cluster-client"), exports);
72
73
  __exportStar(require("./helpers/get-user-helper"), exports);
73
74
  __exportStar(require("./helpers/get-platform-fees"), exports);
74
75
  __exportStar(require("./helpers/get-processor-fees"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1038",
3
+ "version": "1.0.1039",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",