@riocrypto/common-server 1.0.2018 → 1.0.2020
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/axios-with-logging.d.ts +1 -2
- package/build/clients/axios-with-logging.js +70 -66
- package/build/clients/bitso-client.d.ts +1 -0
- package/build/clients/bitso-client.js +16 -15
- package/build/clients/bridge-client.d.ts +1 -0
- package/build/clients/bridge-client.js +17 -16
- package/build/clients/circle-client.d.ts +1 -0
- package/build/clients/circle-client.js +7 -9
- package/build/clients/cluster-client.js +3 -5
- package/build/clients/coincover-client.d.ts +1 -0
- package/build/clients/coincover-client.js +7 -9
- package/build/clients/cosigner-client.d.ts +1 -0
- package/build/clients/cosigner-client.js +3 -2
- package/build/clients/currency-api-client.d.ts +1 -0
- package/build/clients/currency-api-client.js +4 -3
- package/build/clients/slack-client.d.ts +1 -0
- package/build/clients/slack-client.js +5 -3
- package/package.json +1 -1
|
@@ -1,2 +1 @@
|
|
|
1
|
-
declare
|
|
2
|
-
export default axiosWithLogging;
|
|
1
|
+
export declare function buildAxiosWithLogging(): import("axios").AxiosInstance;
|
|
@@ -3,74 +3,78 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildAxiosWithLogging = void 0;
|
|
6
7
|
const axios_1 = __importDefault(require("axios"));
|
|
7
8
|
const logger_1 = __importDefault(require("../services/logger"));
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
9
|
+
function buildAxiosWithLogging() {
|
|
10
|
+
const axiosWithLogging = axios_1.default.create();
|
|
11
|
+
const sensitiveHeaders = [
|
|
12
|
+
"Authorization",
|
|
13
|
+
"x-api-key",
|
|
14
|
+
"Api-Key",
|
|
15
|
+
"x-cluster-api-key",
|
|
16
|
+
"X-API-KEY",
|
|
17
|
+
"CB-ACCESS-KEY",
|
|
18
|
+
"CB-ACCESS-SIGN",
|
|
19
|
+
"CB-ACCESS-TIMESTAMP",
|
|
20
|
+
"CB-ACCESS-PASSPHRASE",
|
|
21
|
+
];
|
|
22
|
+
function maskHeaderValue(value) {
|
|
23
|
+
return value.length > 4
|
|
24
|
+
? "*".repeat(value.length - 4) + value.slice(-4)
|
|
25
|
+
: value;
|
|
26
|
+
}
|
|
27
|
+
// Masking function to selectively mask headers
|
|
28
|
+
function maskHeaders(headers) {
|
|
29
|
+
const maskedHeaders = Object.assign({}, headers);
|
|
30
|
+
Object.keys(maskedHeaders).forEach((header) => {
|
|
31
|
+
if (sensitiveHeaders.includes(header)) {
|
|
32
|
+
maskedHeaders[header] = maskHeaderValue(maskedHeaders[header]);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return maskedHeaders;
|
|
36
|
+
}
|
|
37
|
+
// Request Interceptor
|
|
38
|
+
axiosWithLogging.interceptors.request.use((config) => {
|
|
39
|
+
var _a;
|
|
40
|
+
const customConfig = config;
|
|
41
|
+
// Check if logging is disabled for this request
|
|
42
|
+
if (!customConfig.skipLogging) {
|
|
43
|
+
// Mask sensitive headers in the configuration
|
|
44
|
+
const maskedHeaders = maskHeaders(customConfig.headers);
|
|
45
|
+
// Combine and log the full request configuration with masked headers
|
|
46
|
+
const logMessage = `Request: method=${customConfig.method}, url=${customConfig.url}, headers=${JSON.stringify(maskedHeaders)}, data=${JSON.stringify(customConfig.data)}`;
|
|
47
|
+
((_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.info(logMessage)) || console.log(logMessage);
|
|
31
48
|
}
|
|
49
|
+
return config;
|
|
50
|
+
}, (error) => {
|
|
51
|
+
var _a;
|
|
52
|
+
// Log the request error with combined details
|
|
53
|
+
((_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.info(`Request Error: ${error}`)) ||
|
|
54
|
+
console.log(`Request Error: ${error}`);
|
|
55
|
+
return Promise.reject(error);
|
|
32
56
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
((_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.info(`Request Error: ${error}`)) ||
|
|
52
|
-
console.log(`Request Error: ${error}`);
|
|
53
|
-
return Promise.reject(error);
|
|
54
|
-
});
|
|
55
|
-
// Response Interceptor
|
|
56
|
-
axiosWithLogging.interceptors.response.use((response) => {
|
|
57
|
-
var _a;
|
|
58
|
-
const customConfig = response.config;
|
|
59
|
-
// Check if logging is disabled for this request
|
|
60
|
-
if (!customConfig.skipLogging) {
|
|
61
|
-
// Combine and log the full response details
|
|
62
|
-
const logMessage = `Response: url=${customConfig.url}, status=${response.status}, data=${JSON.stringify(response.data)}`;
|
|
57
|
+
// Response Interceptor
|
|
58
|
+
axiosWithLogging.interceptors.response.use((response) => {
|
|
59
|
+
var _a;
|
|
60
|
+
const customConfig = response.config;
|
|
61
|
+
// Check if logging is disabled for this request
|
|
62
|
+
if (!customConfig.skipLogging) {
|
|
63
|
+
// Combine and log the full response details
|
|
64
|
+
const logMessage = `Response: url=${customConfig.url}, status=${response.status}, data=${JSON.stringify(response.data)}`;
|
|
65
|
+
((_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.info(logMessage)) || console.log(logMessage);
|
|
66
|
+
}
|
|
67
|
+
return response;
|
|
68
|
+
}, (error) => {
|
|
69
|
+
var _a;
|
|
70
|
+
// Combine and log the response error details without headers
|
|
71
|
+
let logMessage = `Response Error: url=${error.config ? error.config.url : "unknown"}, message=${error.message}`;
|
|
72
|
+
if (error.response) {
|
|
73
|
+
logMessage += `, status=${error.response.status}, data=${JSON.stringify(error.response.data)}`;
|
|
74
|
+
}
|
|
63
75
|
((_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.info(logMessage)) || console.log(logMessage);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
let logMessage = `Response Error: url=${error.config ? error.config.url : "unknown"}, message=${error.message}`;
|
|
70
|
-
if (error.response) {
|
|
71
|
-
logMessage += `, status=${error.response.status}, data=${JSON.stringify(error.response.data)}`;
|
|
72
|
-
}
|
|
73
|
-
((_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.info(logMessage)) || console.log(logMessage);
|
|
74
|
-
return Promise.reject(error);
|
|
75
|
-
});
|
|
76
|
-
exports.default = axiosWithLogging;
|
|
76
|
+
return Promise.reject(error);
|
|
77
|
+
});
|
|
78
|
+
return axiosWithLogging;
|
|
79
|
+
}
|
|
80
|
+
exports.buildAxiosWithLogging = buildAxiosWithLogging;
|
|
@@ -5,6 +5,7 @@ declare class BitsoClient {
|
|
|
5
5
|
private apiSecret;
|
|
6
6
|
private env;
|
|
7
7
|
private baseUrl;
|
|
8
|
+
private axiosClient;
|
|
8
9
|
constructor(apiKey: string, apiSecret: string, env: "production" | "sandbox");
|
|
9
10
|
createClabe(): Promise<string>;
|
|
10
11
|
createReceivingAccount(user: User, bankAccount: BankAccount): Promise<string>;
|
|
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.buildBitsoClient = void 0;
|
|
16
16
|
const secret_manager_client_1 = require("./secret-manager-client");
|
|
17
17
|
const axios_1 = __importDefault(require("axios"));
|
|
18
|
-
const axios_with_logging_1 =
|
|
18
|
+
const axios_with_logging_1 = require("./axios-with-logging");
|
|
19
19
|
const common_1 = require("@riocrypto/common");
|
|
20
20
|
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
21
21
|
class BitsoClient {
|
|
@@ -27,6 +27,7 @@ class BitsoClient {
|
|
|
27
27
|
env === "production"
|
|
28
28
|
? "https://api.bitso.com"
|
|
29
29
|
: "https://stage.bitso.com";
|
|
30
|
+
this.axiosClient = (0, axios_with_logging_1.buildAxiosWithLogging)();
|
|
30
31
|
}
|
|
31
32
|
createClabe() {
|
|
32
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -41,7 +42,7 @@ class BitsoClient {
|
|
|
41
42
|
},
|
|
42
43
|
};
|
|
43
44
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
44
|
-
const { data } = yield
|
|
45
|
+
const { data } = yield this.axiosClient(signedRequestConfig);
|
|
45
46
|
return data.payload.clabe;
|
|
46
47
|
});
|
|
47
48
|
}
|
|
@@ -73,7 +74,7 @@ class BitsoClient {
|
|
|
73
74
|
},
|
|
74
75
|
};
|
|
75
76
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
76
|
-
const { data } = yield
|
|
77
|
+
const { data } = yield this.axiosClient(signedRequestConfig);
|
|
77
78
|
if (!data.success) {
|
|
78
79
|
throw new Error("Error creating Bitso receiving account");
|
|
79
80
|
}
|
|
@@ -90,7 +91,7 @@ class BitsoClient {
|
|
|
90
91
|
url: `${this.baseUrl}/api/v3/consumer-contacts/${bitsoReceivingAccountId}`,
|
|
91
92
|
};
|
|
92
93
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
93
|
-
const { data } = yield
|
|
94
|
+
const { data } = yield this.axiosClient(signedRequestConfig);
|
|
94
95
|
if (!data.success) {
|
|
95
96
|
throw new Error("Error deleting Bitso receiving account");
|
|
96
97
|
}
|
|
@@ -121,7 +122,7 @@ class BitsoClient {
|
|
|
121
122
|
},
|
|
122
123
|
};
|
|
123
124
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
124
|
-
const { data } = yield
|
|
125
|
+
const { data } = yield this.axiosClient(signedRequestConfig);
|
|
125
126
|
if (!data.success) {
|
|
126
127
|
throw new Error("Error creating Bitso withdraw");
|
|
127
128
|
}
|
|
@@ -138,7 +139,7 @@ class BitsoClient {
|
|
|
138
139
|
},
|
|
139
140
|
};
|
|
140
141
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
141
|
-
const { data } = yield
|
|
142
|
+
const { data } = yield this.axiosClient(signedRequestConfig);
|
|
142
143
|
if (!data.success || !data.payload.length) {
|
|
143
144
|
throw new Error("Error getting Bitso order");
|
|
144
145
|
}
|
|
@@ -167,7 +168,7 @@ class BitsoClient {
|
|
|
167
168
|
},
|
|
168
169
|
};
|
|
169
170
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
170
|
-
const { data } = yield
|
|
171
|
+
const { data } = yield this.axiosClient(signedRequestConfig);
|
|
171
172
|
if (!data.success) {
|
|
172
173
|
throw new Error("Error creating Bitso limit order");
|
|
173
174
|
}
|
|
@@ -184,7 +185,7 @@ class BitsoClient {
|
|
|
184
185
|
},
|
|
185
186
|
};
|
|
186
187
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
187
|
-
const { data } = yield
|
|
188
|
+
const { data } = yield this.axiosClient(signedRequestConfig);
|
|
188
189
|
if (!data.success || !data.payload.length) {
|
|
189
190
|
throw new Error("Error getting Bitso order");
|
|
190
191
|
}
|
|
@@ -201,7 +202,7 @@ class BitsoClient {
|
|
|
201
202
|
},
|
|
202
203
|
};
|
|
203
204
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
204
|
-
const { data } = yield
|
|
205
|
+
const { data } = yield this.axiosClient(signedRequestConfig);
|
|
205
206
|
if (!data.success) {
|
|
206
207
|
throw new Error("Error getting Bitso order");
|
|
207
208
|
}
|
|
@@ -218,7 +219,7 @@ class BitsoClient {
|
|
|
218
219
|
},
|
|
219
220
|
};
|
|
220
221
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
221
|
-
const { data } = yield
|
|
222
|
+
const { data } = yield this.axiosClient(signedRequestConfig);
|
|
222
223
|
if (!data.success) {
|
|
223
224
|
throw new Error("Error getting Bitso order trades");
|
|
224
225
|
}
|
|
@@ -255,7 +256,7 @@ class BitsoClient {
|
|
|
255
256
|
},
|
|
256
257
|
};
|
|
257
258
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
258
|
-
const { data } = yield
|
|
259
|
+
const { data } = yield this.axiosClient(signedRequestConfig);
|
|
259
260
|
if (!data.success) {
|
|
260
261
|
throw new Error("Error deleting Bitso order");
|
|
261
262
|
}
|
|
@@ -271,7 +272,7 @@ class BitsoClient {
|
|
|
271
272
|
},
|
|
272
273
|
};
|
|
273
274
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
274
|
-
const { data } = yield
|
|
275
|
+
const { data } = yield this.axiosClient(signedRequestConfig);
|
|
275
276
|
if (!data.success) {
|
|
276
277
|
throw new Error("Error getting Bitso order book");
|
|
277
278
|
}
|
|
@@ -288,7 +289,7 @@ class BitsoClient {
|
|
|
288
289
|
},
|
|
289
290
|
};
|
|
290
291
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
291
|
-
const res = yield
|
|
292
|
+
const res = yield this.axiosClient(signedRequestConfig);
|
|
292
293
|
const data = res.data;
|
|
293
294
|
if (!data.success) {
|
|
294
295
|
throw new Error("Error getting Bitso fees");
|
|
@@ -311,7 +312,7 @@ class BitsoClient {
|
|
|
311
312
|
},
|
|
312
313
|
};
|
|
313
314
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
314
|
-
const res = yield
|
|
315
|
+
const res = yield this.axiosClient(signedRequestConfig);
|
|
315
316
|
const data = res.data;
|
|
316
317
|
if (!data.success) {
|
|
317
318
|
throw new Error("Error getting Bitso fees");
|
|
@@ -406,7 +407,7 @@ class BitsoClient {
|
|
|
406
407
|
},
|
|
407
408
|
};
|
|
408
409
|
const signedRequestConfig = this.signRequest(requestConfig);
|
|
409
|
-
const { data } = yield
|
|
410
|
+
const { data } = yield this.axiosClient(signedRequestConfig);
|
|
410
411
|
if (!data.success) {
|
|
411
412
|
throw new Error("Error creating Bitso withdraw");
|
|
412
413
|
}
|
|
@@ -15,12 +15,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.buildBridgeClient = void 0;
|
|
16
16
|
const secret_manager_client_1 = require("./secret-manager-client");
|
|
17
17
|
const axios_1 = __importDefault(require("axios"));
|
|
18
|
-
const axios_with_logging_1 =
|
|
18
|
+
const axios_with_logging_1 = require("./axios-with-logging");
|
|
19
19
|
const common_1 = require("@riocrypto/common");
|
|
20
20
|
const uuid_1 = require("uuid");
|
|
21
21
|
class BridgeClient {
|
|
22
22
|
constructor(apiKey) {
|
|
23
23
|
this.apiKey = apiKey;
|
|
24
|
+
this.axiosClient = (0, axios_with_logging_1.buildAxiosWithLogging)();
|
|
24
25
|
if ([common_1.RioEnv.Production, common_1.RioEnv.Development].includes(process.env.RIO_ENV)) {
|
|
25
26
|
this.baseUrl = "https://api.bridge.xyz";
|
|
26
27
|
}
|
|
@@ -30,7 +31,7 @@ class BridgeClient {
|
|
|
30
31
|
}
|
|
31
32
|
createKYCLink(fullName, email, userType) {
|
|
32
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const { data } = yield
|
|
34
|
+
const { data } = yield this.axiosClient.post(`${this.baseUrl}/v0/kyc_links`, {
|
|
34
35
|
full_name: fullName,
|
|
35
36
|
email,
|
|
36
37
|
type: userType,
|
|
@@ -45,7 +46,7 @@ class BridgeClient {
|
|
|
45
46
|
}
|
|
46
47
|
getKYCLink(id) {
|
|
47
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const { data } = yield
|
|
49
|
+
const { data } = yield this.axiosClient.get(`${this.baseUrl}/v0/kyc_links/${id}`, {
|
|
49
50
|
headers: {
|
|
50
51
|
"Api-Key": this.apiKey,
|
|
51
52
|
},
|
|
@@ -58,7 +59,7 @@ class BridgeClient {
|
|
|
58
59
|
if ([common_1.RioEnv.Sandbox, common_1.RioEnv.Local, common_1.RioEnv.Test].includes(process.env.RIO_ENV)) {
|
|
59
60
|
throw new Error("Bridge transfers are disabled in sandbox mode.");
|
|
60
61
|
}
|
|
61
|
-
const { data } = yield
|
|
62
|
+
const { data } = yield this.axiosClient.post(`${this.baseUrl}/v0/transfers`, {
|
|
62
63
|
amount: amountInUSD,
|
|
63
64
|
on_behalf_of: bridgeCustomerId,
|
|
64
65
|
developer_fee: developerFee,
|
|
@@ -82,7 +83,7 @@ class BridgeClient {
|
|
|
82
83
|
}
|
|
83
84
|
deleteTransfer(transferId) {
|
|
84
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
const { data } = yield
|
|
86
|
+
const { data } = yield this.axiosClient.delete(`${this.baseUrl}/v0/transfers/${transferId}`, {
|
|
86
87
|
headers: {
|
|
87
88
|
"Api-Key": this.apiKey,
|
|
88
89
|
},
|
|
@@ -102,7 +103,7 @@ class BridgeClient {
|
|
|
102
103
|
}
|
|
103
104
|
getAllCustomerTransfers(customerId) {
|
|
104
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
const { data } = yield
|
|
106
|
+
const { data } = yield this.axiosClient.get(`${this.baseUrl}/v0/customers/${customerId}/transfers`, {
|
|
106
107
|
headers: {
|
|
107
108
|
"Api-Key": this.apiKey,
|
|
108
109
|
},
|
|
@@ -115,7 +116,7 @@ class BridgeClient {
|
|
|
115
116
|
if ([common_1.RioEnv.Sandbox, common_1.RioEnv.Local, common_1.RioEnv.Test].includes(process.env.RIO_ENV)) {
|
|
116
117
|
throw new Error("Bridge liquidation addresses are disabled in sandbox mode.");
|
|
117
118
|
}
|
|
118
|
-
const { data } = yield
|
|
119
|
+
const { data } = yield this.axiosClient.post(`${this.baseUrl}/v0/customers/${bridgeCustomerId}/liquidation_addresses`, {
|
|
119
120
|
currency,
|
|
120
121
|
chain,
|
|
121
122
|
external_account_id: externalAccountId,
|
|
@@ -130,7 +131,7 @@ class BridgeClient {
|
|
|
130
131
|
}
|
|
131
132
|
getLiquidationAddresses(bridgeCustomerId, crypto) {
|
|
132
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
const { data } = yield
|
|
134
|
+
const { data } = yield this.axiosClient.get(`${this.baseUrl}/v0/customers/${bridgeCustomerId}/liquidation_addresses/`, {
|
|
134
135
|
headers: {
|
|
135
136
|
"Api-Key": this.apiKey,
|
|
136
137
|
},
|
|
@@ -142,7 +143,7 @@ class BridgeClient {
|
|
|
142
143
|
}
|
|
143
144
|
getLiquidationAddress(bridgeCustomerId, bridgeLiquidationAddressId) {
|
|
144
145
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
const { data } = yield
|
|
146
|
+
const { data } = yield this.axiosClient.get(`${this.baseUrl}/v0/customers/${bridgeCustomerId}/liquidation_addresses/${bridgeLiquidationAddressId}`, {
|
|
146
147
|
headers: {
|
|
147
148
|
"Api-Key": this.apiKey,
|
|
148
149
|
},
|
|
@@ -152,7 +153,7 @@ class BridgeClient {
|
|
|
152
153
|
}
|
|
153
154
|
getLiquidationAddressDrains(bridgeCustomerId, liquidationAddressId) {
|
|
154
155
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
const response = yield
|
|
156
|
+
const response = yield this.axiosClient.get(`${this.baseUrl}/v0/customers/${bridgeCustomerId}/liquidation_addresses/${liquidationAddressId}/drains`, {
|
|
156
157
|
headers: {
|
|
157
158
|
"Api-Key": this.apiKey,
|
|
158
159
|
},
|
|
@@ -165,7 +166,7 @@ class BridgeClient {
|
|
|
165
166
|
if ([common_1.RioEnv.Sandbox, common_1.RioEnv.Local, common_1.RioEnv.Test].includes(process.env.RIO_ENV)) {
|
|
166
167
|
throw new Error("Bridge plaid link tokens are disabled in sandbox mode.");
|
|
167
168
|
}
|
|
168
|
-
const { data } = yield
|
|
169
|
+
const { data } = yield this.axiosClient.post(`${this.baseUrl}/v0/customers/${bridgeCustomerId}/plaid_link_requests`, undefined, {
|
|
169
170
|
headers: {
|
|
170
171
|
"Api-Key": this.apiKey,
|
|
171
172
|
"Idempotency-Key": (0, uuid_1.v4)(),
|
|
@@ -176,7 +177,7 @@ class BridgeClient {
|
|
|
176
177
|
}
|
|
177
178
|
getExternalAccounts(customerId) {
|
|
178
179
|
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
-
const { data } = yield
|
|
180
|
+
const { data } = yield this.axiosClient.get(`${this.baseUrl}/v0/customers/${customerId}/external_accounts`, {
|
|
180
181
|
headers: {
|
|
181
182
|
"Api-Key": this.apiKey,
|
|
182
183
|
},
|
|
@@ -186,7 +187,7 @@ class BridgeClient {
|
|
|
186
187
|
}
|
|
187
188
|
getExternalAccount(bridgeCustomerId, externalAccountId) {
|
|
188
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
-
const { data } = yield
|
|
190
|
+
const { data } = yield this.axiosClient.get(`${this.baseUrl}/v0/customers/${bridgeCustomerId}/external_accounts/${externalAccountId}`, {
|
|
190
191
|
headers: {
|
|
191
192
|
"Api-Key": this.apiKey,
|
|
192
193
|
},
|
|
@@ -199,7 +200,7 @@ class BridgeClient {
|
|
|
199
200
|
if ([common_1.RioEnv.Sandbox, common_1.RioEnv.Local, common_1.RioEnv.Test].includes(process.env.RIO_ENV)) {
|
|
200
201
|
throw new Error("Bridge plaid exchange public token is disabled in sandbox mode.");
|
|
201
202
|
}
|
|
202
|
-
const { data } = yield
|
|
203
|
+
const { data } = yield this.axiosClient.post(`${this.baseUrl}/v0/plaid_exchange_public_token/${linkToken}`, {
|
|
203
204
|
public_token: publicToken,
|
|
204
205
|
}, {
|
|
205
206
|
headers: {
|
|
@@ -214,7 +215,7 @@ class BridgeClient {
|
|
|
214
215
|
if ([common_1.RioEnv.Sandbox, common_1.RioEnv.Local, common_1.RioEnv.Test].includes(process.env.RIO_ENV)) {
|
|
215
216
|
throw new Error("Bridge external accounts are disabled in sandbox mode.");
|
|
216
217
|
}
|
|
217
|
-
const { data } = yield
|
|
218
|
+
const { data } = yield this.axiosClient.post(`${this.baseUrl}/v0/customers/${bridgeCustomerId}/external_accounts`, {
|
|
218
219
|
type: "wire",
|
|
219
220
|
bank_name: bankName,
|
|
220
221
|
account_number: accountNumber,
|
|
@@ -232,7 +233,7 @@ class BridgeClient {
|
|
|
232
233
|
}
|
|
233
234
|
deleteExternalAccount(customerId, externalAccountId) {
|
|
234
235
|
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
-
const { data } = yield
|
|
236
|
+
const { data } = yield this.axiosClient.delete(`${this.baseUrl}/v0/customers/${customerId}/external_accounts/${externalAccountId}`, {
|
|
236
237
|
headers: {
|
|
237
238
|
"Api-Key": this.apiKey,
|
|
238
239
|
},
|
|
@@ -2,6 +2,7 @@ import { CircleChain, User } from "@riocrypto/common";
|
|
|
2
2
|
declare class CircleClient {
|
|
3
3
|
private apiKey;
|
|
4
4
|
private baseUrl;
|
|
5
|
+
private axiosClient;
|
|
5
6
|
constructor(apiKey: string);
|
|
6
7
|
createAddressBookRecipient(user: User, address: string, chain: CircleChain): Promise<{
|
|
7
8
|
id: string;
|
|
@@ -8,13 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.buildCircleClient = void 0;
|
|
16
13
|
const secret_manager_client_1 = require("./secret-manager-client");
|
|
17
|
-
const axios_with_logging_1 =
|
|
14
|
+
const axios_with_logging_1 = require("./axios-with-logging");
|
|
18
15
|
const common_1 = require("@riocrypto/common");
|
|
19
16
|
const uuid_1 = require("uuid");
|
|
20
17
|
class CircleClient {
|
|
@@ -24,12 +21,13 @@ class CircleClient {
|
|
|
24
21
|
process.env.RIO_ENV === common_1.RioEnv.Production
|
|
25
22
|
? "https://api.circle.com"
|
|
26
23
|
: "https://api-sandbox.circle.com";
|
|
24
|
+
this.axiosClient = (0, axios_with_logging_1.buildAxiosWithLogging)();
|
|
27
25
|
}
|
|
28
26
|
createAddressBookRecipient(user, address, chain) {
|
|
29
27
|
var _a;
|
|
30
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
29
|
const uuid = (0, uuid_1.v1)();
|
|
32
|
-
const response = yield
|
|
30
|
+
const response = yield this.axiosClient.post(`${this.baseUrl}/v1/addressBook/recipients`, {
|
|
33
31
|
idempotencyKey: uuid,
|
|
34
32
|
chain,
|
|
35
33
|
address,
|
|
@@ -47,7 +45,7 @@ class CircleClient {
|
|
|
47
45
|
getAddressBookRecipient(id) {
|
|
48
46
|
var _a;
|
|
49
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const response = yield
|
|
48
|
+
const response = yield this.axiosClient.get(`${this.baseUrl}/v1/addressBook/recipients/${id}`, {
|
|
51
49
|
headers: {
|
|
52
50
|
Authorization: `Bearer ${this.apiKey}`,
|
|
53
51
|
},
|
|
@@ -59,7 +57,7 @@ class CircleClient {
|
|
|
59
57
|
var _a;
|
|
60
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
59
|
const uuid = (0, uuid_1.v1)();
|
|
62
|
-
const response = yield
|
|
60
|
+
const response = yield this.axiosClient.post(`${this.baseUrl}/v1/payouts`, {
|
|
63
61
|
idempotencyKey: uuid,
|
|
64
62
|
source: {
|
|
65
63
|
type: "wallet",
|
|
@@ -103,7 +101,7 @@ class CircleClient {
|
|
|
103
101
|
getPayout(id) {
|
|
104
102
|
var _a;
|
|
105
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
const response = yield
|
|
104
|
+
const response = yield this.axiosClient.get(`${this.baseUrl}/v1/payouts/${id}`, {
|
|
107
105
|
headers: {
|
|
108
106
|
Authorization: `Bearer ${this.apiKey}`,
|
|
109
107
|
},
|
|
@@ -113,7 +111,7 @@ class CircleClient {
|
|
|
113
111
|
}
|
|
114
112
|
getUSDCBalance(walletId) {
|
|
115
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
const response = yield
|
|
114
|
+
const response = yield this.axiosClient.get(`${this.baseUrl}/v1/wallets/${walletId}`, {
|
|
117
115
|
headers: {
|
|
118
116
|
Authorization: `Bearer ${this.apiKey}`,
|
|
119
117
|
},
|
|
@@ -8,19 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.buildClusterClient = void 0;
|
|
16
13
|
const common_1 = require("@riocrypto/common");
|
|
17
|
-
const axios_with_logging_1 =
|
|
14
|
+
const axios_with_logging_1 = require("./axios-with-logging");
|
|
18
15
|
const secret_manager_client_1 = require("./secret-manager-client");
|
|
19
16
|
class ClusterClient {
|
|
20
17
|
constructor(baseUrl, clusterApiKey) {
|
|
21
18
|
this.baseUrl = baseUrl;
|
|
22
19
|
this.clusterApiKey = clusterApiKey;
|
|
23
|
-
|
|
20
|
+
const axiosWithLogging = (0, axios_with_logging_1.buildAxiosWithLogging)();
|
|
21
|
+
this.axios = axiosWithLogging;
|
|
24
22
|
this.axios.defaults.baseURL = baseUrl;
|
|
25
23
|
// Set the Host header based on environment
|
|
26
24
|
const environment = process.env.RIO_ENV;
|
|
@@ -3,6 +3,7 @@ declare class CoincoverClient {
|
|
|
3
3
|
private apiKey;
|
|
4
4
|
private baseUrl;
|
|
5
5
|
private coingeckoMappings;
|
|
6
|
+
private axiosClient;
|
|
6
7
|
constructor(apiKey: string);
|
|
7
8
|
checkTransaction(transactionId: string, userId: string, crypto: Crypto, originVaultOrExchangeId: string, destinationAddress: string, amount: number): Promise<{
|
|
8
9
|
transactionUUID: string;
|
|
@@ -8,13 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.buildCoincoverClient = void 0;
|
|
16
13
|
const common_1 = require("@riocrypto/common");
|
|
17
|
-
const axios_with_logging_1 =
|
|
14
|
+
const axios_with_logging_1 = require("./axios-with-logging");
|
|
18
15
|
const secret_manager_client_1 = require("./secret-manager-client");
|
|
19
16
|
class CoincoverClient {
|
|
20
17
|
constructor(apiKey) {
|
|
@@ -53,10 +50,11 @@ class CoincoverClient {
|
|
|
53
50
|
[common_1.Crypto.TRON]: "tron",
|
|
54
51
|
[common_1.Crypto.SOL]: "solana",
|
|
55
52
|
};
|
|
53
|
+
this.axiosClient = (0, axios_with_logging_1.buildAxiosWithLogging)();
|
|
56
54
|
}
|
|
57
55
|
checkTransaction(transactionId, userId, crypto, originVaultOrExchangeId, destinationAddress, amount) {
|
|
58
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
const { data } = yield
|
|
57
|
+
const { data } = yield this.axiosClient.post(`${this.baseUrl}/transaction`, {
|
|
60
58
|
transactionCustomerId: transactionId,
|
|
61
59
|
coin: this.coingeckoMappings[crypto],
|
|
62
60
|
walletId: `${originVaultOrExchangeId}-${crypto}`,
|
|
@@ -78,7 +76,7 @@ class CoincoverClient {
|
|
|
78
76
|
registerIndividualUser(user) {
|
|
79
77
|
var _a, _b, _c;
|
|
80
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const { data } = yield
|
|
79
|
+
const { data } = yield this.axiosClient.post(`${this.baseUrl}/user`, {
|
|
82
80
|
userId: user.id,
|
|
83
81
|
firstName: (_a = user.individualData) === null || _a === void 0 ? void 0 : _a.firstName,
|
|
84
82
|
lastName: (_b = user.individualData) === null || _b === void 0 ? void 0 : _b.lastName,
|
|
@@ -97,7 +95,7 @@ class CoincoverClient {
|
|
|
97
95
|
registerBusinessUser(user, address, contactPersonName, contactPersonEmail) {
|
|
98
96
|
var _a;
|
|
99
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
const { data } = yield
|
|
98
|
+
const { data } = yield this.axiosClient.post(`${this.baseUrl}/business`, {
|
|
101
99
|
businessId: user.id,
|
|
102
100
|
name: (_a = user.businessData) === null || _a === void 0 ? void 0 : _a.businessName,
|
|
103
101
|
address: this.formatAddress(address.street1, address.city, address.state, address.postalCode, address.country, address.street2),
|
|
@@ -114,7 +112,7 @@ class CoincoverClient {
|
|
|
114
112
|
patchIndividualUser(user) {
|
|
115
113
|
var _a, _b, _c;
|
|
116
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
const { data } = yield
|
|
115
|
+
const { data } = yield this.axiosClient.patch(`${this.baseUrl}/user/${user.id}`, {
|
|
118
116
|
firstName: (_a = user.individualData) === null || _a === void 0 ? void 0 : _a.firstName,
|
|
119
117
|
lastName: (_b = user.individualData) === null || _b === void 0 ? void 0 : _b.lastName,
|
|
120
118
|
dob: ((_c = user.individualData) === null || _c === void 0 ? void 0 : _c.birthday)
|
|
@@ -132,7 +130,7 @@ class CoincoverClient {
|
|
|
132
130
|
patchBusinessUser(user, address, contactPersonName, contactPersonEmail) {
|
|
133
131
|
var _a;
|
|
134
132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
const { data } = yield
|
|
133
|
+
const { data } = yield this.axiosClient.patch(`${this.baseUrl}/business/${user.id}`, {
|
|
136
134
|
name: (_a = user.businessData) === null || _a === void 0 ? void 0 : _a.businessName,
|
|
137
135
|
address: this.formatAddress(address.street1, address.city, address.state, address.postalCode, address.country, address.street2),
|
|
138
136
|
contactPersonName,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
declare class CosignerClient {
|
|
2
2
|
private apiKey;
|
|
3
3
|
private webhookSecret;
|
|
4
|
+
private axiosClient;
|
|
4
5
|
constructor(apiKey: string, webhookSecret: string);
|
|
5
6
|
sendRequest(title: string, description: string, minApprovers: number, notificationUrl: string, approverGroupId: string, metadata?: Object): Promise<void>;
|
|
6
7
|
decryptNotification(encryptedData: string, iv: string): Promise<string>;
|
|
@@ -14,16 +14,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.buildCosignerClient = void 0;
|
|
16
16
|
const secret_manager_client_1 = require("./secret-manager-client");
|
|
17
|
-
const axios_with_logging_1 =
|
|
17
|
+
const axios_with_logging_1 = require("./axios-with-logging");
|
|
18
18
|
const crypto_1 = __importDefault(require("crypto"));
|
|
19
19
|
class CosignerClient {
|
|
20
20
|
constructor(apiKey, webhookSecret) {
|
|
21
21
|
this.apiKey = apiKey;
|
|
22
22
|
this.webhookSecret = webhookSecret;
|
|
23
|
+
this.axiosClient = (0, axios_with_logging_1.buildAxiosWithLogging)();
|
|
23
24
|
}
|
|
24
25
|
sendRequest(title, description, minApprovers, notificationUrl, approverGroupId, metadata) {
|
|
25
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
yield
|
|
27
|
+
yield this.axiosClient.post("https://www.cosigner.xyz/api/requests", {
|
|
27
28
|
title,
|
|
28
29
|
description,
|
|
29
30
|
metadata,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fiat } from "@riocrypto/common";
|
|
2
2
|
declare class CurrencyAPIClient {
|
|
3
3
|
private apiKey;
|
|
4
|
+
private axiosClient;
|
|
4
5
|
constructor(apiKey: string);
|
|
5
6
|
convert(from: Fiat, to: Fiat): Promise<number>;
|
|
6
7
|
getHistoricalExchangeRates(from: Fiat, to: Fiat, start: string, end: string): Promise<any>;
|
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.buildCurrencyAPIClient = void 0;
|
|
16
16
|
const common_1 = require("@riocrypto/common");
|
|
17
|
-
const axios_with_logging_1 =
|
|
17
|
+
const axios_with_logging_1 = 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
20
|
const logger_1 = __importDefault(require("../services/logger"));
|
|
@@ -22,6 +22,7 @@ const cache = new node_cache_1.default({ stdTTL: 10 });
|
|
|
22
22
|
class CurrencyAPIClient {
|
|
23
23
|
constructor(apiKey) {
|
|
24
24
|
this.apiKey = apiKey;
|
|
25
|
+
this.axiosClient = (0, axios_with_logging_1.buildAxiosWithLogging)();
|
|
25
26
|
}
|
|
26
27
|
convert(from, to) {
|
|
27
28
|
var _a;
|
|
@@ -33,7 +34,7 @@ class CurrencyAPIClient {
|
|
|
33
34
|
exchangeRate = cachedResponse.data[to].value;
|
|
34
35
|
}
|
|
35
36
|
else {
|
|
36
|
-
const currencyAPIResponse = yield
|
|
37
|
+
const currencyAPIResponse = yield this.axiosClient.get(`https://api.currencyapi.com/v3/latest?apikey=${this.apiKey}&base_currency=${from}¤cies=${to}`);
|
|
37
38
|
exchangeRate = currencyAPIResponse.data.data[to].value;
|
|
38
39
|
cache.set(`v3/latest?apikey=${this.apiKey}&base_currency=${from}¤cies=${to}`, currencyAPIResponse.data);
|
|
39
40
|
}
|
|
@@ -61,7 +62,7 @@ class CurrencyAPIClient {
|
|
|
61
62
|
exchangeRates = cachedResponse.data;
|
|
62
63
|
}
|
|
63
64
|
else {
|
|
64
|
-
const currencyAPIResponse = yield
|
|
65
|
+
const currencyAPIResponse = yield this.axiosClient.get(`https://api.currencyapi.com/v3/range?apikey=${this.apiKey}&datetime_start=${start}&datetime_end=${end}&accuracy=minute¤cies=${to}&base_currency=${from}`);
|
|
65
66
|
exchangeRates = currencyAPIResponse.data.data;
|
|
66
67
|
cache.set(`v3/range?apikey=${this.apiKey}&datetime_start=${start}&datetime_end=${end}&accuracy=minute¤cies=${to}&base_currency=${from}`, currencyAPIResponse.data);
|
|
67
68
|
}
|
|
@@ -14,14 +14,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.slackClient = void 0;
|
|
16
16
|
const logger_1 = __importDefault(require("../services/logger"));
|
|
17
|
-
const axios_with_logging_1 =
|
|
17
|
+
const axios_with_logging_1 = require("./axios-with-logging");
|
|
18
18
|
class SlackClient {
|
|
19
|
-
constructor() {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.axiosClient = (0, axios_with_logging_1.buildAxiosWithLogging)();
|
|
21
|
+
}
|
|
20
22
|
sendMessageWithWebhook(message, webhookUrl) {
|
|
21
23
|
var _a;
|
|
22
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
25
|
try {
|
|
24
|
-
yield
|
|
26
|
+
yield this.axiosClient.post(webhookUrl, {
|
|
25
27
|
text: message,
|
|
26
28
|
});
|
|
27
29
|
}
|