@spritz-finance/service-client 0.29.1 → 0.30.0
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/README.md +65 -0
- package/lib/bridge/bridgeServiceClient.js +8 -7
- package/lib/checkbook/checkbookServiceClient.js +5 -4
- package/lib/exchangeRates/exchangeRatesServiceClient.js +3 -2
- package/lib/features/featuresServiceClient.js +4 -3
- package/lib/growth/growthServiceClient.js +8 -7
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/liabilities/liabilitiesServiceClient.js +21 -20
- package/lib/notifications/notificationsServiceClient.js +3 -2
- package/lib/onramp/onrampServiceClient.js +6 -5
- package/lib/payableAccounts/payableAccountsServiceClient.js +16 -15
- package/lib/paymentAddress/paymentAddressServiceClient.js +3 -2
- package/lib/payments/paymentsClient.js +20 -19
- package/lib/payouts/payoutsServiceClient.js +8 -7
- package/lib/platform/platformServiceClient.js +11 -7
- package/lib/rain/rainServiceClient.js +15 -14
- package/lib/restClient.d.ts +2 -0
- package/lib/restClient.js +7 -0
- package/lib/serviceClient.d.ts +1 -1
- package/lib/serviceClient.js +8 -3
- package/lib/sigv4.d.ts +4 -0
- package/lib/sigv4.js +95 -0
- package/lib/transactions/transactionsServiceClient.js +8 -7
- package/lib/unblock/unblockServiceClient.js +8 -7
- package/lib/users/usersServiceClient.js +13 -12
- package/lib/verification/verificationServiceClient.js +9 -8
- package/lib/web3/web3ServiceClient.js +13 -12
- package/package.json +5 -1
|
@@ -53,21 +53,22 @@ exports.queryUserPayments = queryUserPayments;
|
|
|
53
53
|
exports.getVoidedLiabilities = getVoidedLiabilities;
|
|
54
54
|
exports.getUnrefundedFailedRtpSum = getUnrefundedFailedRtpSum;
|
|
55
55
|
exports.PaymentsClient = __importStar(require("./paymentsClient"));
|
|
56
|
-
const
|
|
56
|
+
const restClient_1 = require("../restClient");
|
|
57
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.PAYMENTS_SERVICE_API_IAM_URL);
|
|
57
58
|
const PAYMENTS_ENDPOINT = "/liabilities";
|
|
58
59
|
const PAYMENTS_ROUTER_ENDPOINT = "/v2/liabilities/api";
|
|
59
60
|
async function createDirectPayment(args) {
|
|
60
|
-
return
|
|
61
|
+
return baseClient
|
|
61
62
|
.post(`${PAYMENTS_ENDPOINT}/direct-payments`, args)
|
|
62
63
|
.then((res) => res.data);
|
|
63
64
|
}
|
|
64
65
|
async function validatePaymentAmount(args) {
|
|
65
|
-
return
|
|
66
|
+
return baseClient
|
|
66
67
|
.post(`${PAYMENTS_ENDPOINT}/v2/direct-payments/validate`, args)
|
|
67
68
|
.then((res) => res.data);
|
|
68
69
|
}
|
|
69
70
|
async function validateDirectPayment(args) {
|
|
70
|
-
return
|
|
71
|
+
return baseClient
|
|
71
72
|
.post(`${PAYMENTS_ENDPOINT}/direct-payments`, {
|
|
72
73
|
...args,
|
|
73
74
|
validateOnly: true,
|
|
@@ -75,77 +76,77 @@ async function validateDirectPayment(args) {
|
|
|
75
76
|
.then((res) => res.data);
|
|
76
77
|
}
|
|
77
78
|
async function getValidPaymentsForAccount(accountId) {
|
|
78
|
-
return
|
|
79
|
+
return baseClient
|
|
79
80
|
.get(`${PAYMENTS_ENDPOINT}/payments/valid-payments/account/${accountId}`)
|
|
80
81
|
.then((res) => res.data);
|
|
81
82
|
}
|
|
82
83
|
async function getValidPaymentsForUser(userId) {
|
|
83
|
-
return
|
|
84
|
+
return baseClient
|
|
84
85
|
.get(`${PAYMENTS_ENDPOINT}/payments/valid-payments/user/${userId}`)
|
|
85
86
|
.then((res) => res.data);
|
|
86
87
|
}
|
|
87
88
|
async function getRewardTransactionVolume(args) {
|
|
88
|
-
return
|
|
89
|
+
return baseClient
|
|
89
90
|
.post(`${PAYMENTS_ENDPOINT}/payments/rewards/volume`, args)
|
|
90
91
|
.then((res) => res.data);
|
|
91
92
|
}
|
|
92
93
|
async function getRewardFeeAmount(args) {
|
|
93
|
-
return
|
|
94
|
+
return baseClient
|
|
94
95
|
.post(`${PAYMENTS_ENDPOINT}/payments/rewards/fees`, args)
|
|
95
96
|
.then((res) => res.data);
|
|
96
97
|
}
|
|
97
98
|
async function initializeExternalPayment(args) {
|
|
98
|
-
return
|
|
99
|
+
return baseClient
|
|
99
100
|
.post(`${PAYMENTS_ROUTER_ENDPOINT}/external-payment/initialize`, args)
|
|
100
101
|
.then((res) => res.data);
|
|
101
102
|
}
|
|
102
103
|
async function scheduleExternalPayment(args) {
|
|
103
|
-
return
|
|
104
|
+
return baseClient
|
|
104
105
|
.post(`${PAYMENTS_ROUTER_ENDPOINT}/external-payment/schedule`, args)
|
|
105
106
|
.then((res) => res.data);
|
|
106
107
|
}
|
|
107
108
|
async function updateExternalPaymentStatus(paymentId, input) {
|
|
108
|
-
return
|
|
109
|
+
return baseClient
|
|
109
110
|
.post(`${PAYMENTS_ROUTER_ENDPOINT}/external-payment/status/${paymentId}`, input)
|
|
110
111
|
.then((res) => res.data);
|
|
111
112
|
}
|
|
112
113
|
async function getDirectPaymentToken(directPaymentId) {
|
|
113
|
-
return
|
|
114
|
+
return baseClient
|
|
114
115
|
.get(`${PAYMENTS_ENDPOINT}/direct-payments/${directPaymentId}/token`)
|
|
115
116
|
.then((res) => res.data);
|
|
116
117
|
}
|
|
117
118
|
async function getDirectPaymentDetails(directPaymentId) {
|
|
118
|
-
return
|
|
119
|
+
return baseClient
|
|
119
120
|
.get(`${PAYMENTS_ENDPOINT}/direct-payments/${directPaymentId}/details`)
|
|
120
121
|
.then((res) => res.data);
|
|
121
122
|
}
|
|
122
123
|
async function getAllPaymentsForUser(userId) {
|
|
123
|
-
return
|
|
124
|
+
return baseClient
|
|
124
125
|
.get(`${PAYMENTS_ENDPOINT}/payments/user/${userId}/all`)
|
|
125
126
|
.then((res) => res.data);
|
|
126
127
|
}
|
|
127
128
|
async function getUserPaymentById(userId, paymentId) {
|
|
128
|
-
return
|
|
129
|
+
return baseClient
|
|
129
130
|
.get(`${PAYMENTS_ENDPOINT}/payments/user/${userId}/payment/${paymentId}`)
|
|
130
131
|
.then((res) => res.data);
|
|
131
132
|
}
|
|
132
133
|
async function directPaymentsForRiskAnalysis(userId) {
|
|
133
|
-
return
|
|
134
|
+
return baseClient
|
|
134
135
|
.get(`${PAYMENTS_ENDPOINT}/direct-payments/user/${userId}/risk-analysis`)
|
|
135
136
|
.then((res) => res.data);
|
|
136
137
|
}
|
|
137
138
|
async function queryUserPayments(userId, input = {}) {
|
|
138
|
-
return
|
|
139
|
+
return baseClient
|
|
139
140
|
.post(`${PAYMENTS_ENDPOINT}/payments/query?userId=${userId}`, input)
|
|
140
141
|
.then((res) => res.data);
|
|
141
142
|
}
|
|
142
143
|
async function getVoidedLiabilities() {
|
|
143
|
-
return
|
|
144
|
+
return baseClient
|
|
144
145
|
.get(`${PAYMENTS_ROUTER_ENDPOINT}/checkbook/voided-liabilities`)
|
|
145
146
|
.then((res) => res.data);
|
|
146
147
|
}
|
|
147
148
|
async function getUnrefundedFailedRtpSum() {
|
|
148
|
-
return
|
|
149
|
+
return baseClient
|
|
149
150
|
.get(`${PAYMENTS_ROUTER_ENDPOINT}/payments/liabilities/rtp`)
|
|
150
151
|
.then((res) => res.data);
|
|
151
152
|
}
|
|
@@ -41,10 +41,11 @@ exports.submit7702Message = submit7702Message;
|
|
|
41
41
|
exports.executeRainAdminChange = executeRainAdminChange;
|
|
42
42
|
exports.getTreasuryBalances = getTreasuryBalances;
|
|
43
43
|
exports.PayoutsClient = __importStar(require("./payoutsServiceClient"));
|
|
44
|
-
const
|
|
44
|
+
const restClient_1 = require("../restClient");
|
|
45
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.PAYOUTS_SERVICE_API_IAM_URL);
|
|
45
46
|
const PAYOUTS_ENDPOINT = "/bridgebot";
|
|
46
47
|
async function requestCryptoPayout({ userId, type, network, amountFiat, referenceId, toAddress, tokenSymbol, currencyFiat = "USD", fromDispatchWallet = false, }) {
|
|
47
|
-
return
|
|
48
|
+
return baseClient
|
|
48
49
|
.post(`${PAYOUTS_ENDPOINT}/payouts/crypto`, {
|
|
49
50
|
userId,
|
|
50
51
|
type,
|
|
@@ -59,7 +60,7 @@ async function requestCryptoPayout({ userId, type, network, amountFiat, referenc
|
|
|
59
60
|
.then((res) => res.data);
|
|
60
61
|
}
|
|
61
62
|
async function getPayoutFromHash({ userId, transactionHash, }) {
|
|
62
|
-
return
|
|
63
|
+
return baseClient
|
|
63
64
|
.post(`${PAYOUTS_ENDPOINT}/payouts/hash`, {
|
|
64
65
|
userId,
|
|
65
66
|
transactionHash,
|
|
@@ -67,17 +68,17 @@ async function getPayoutFromHash({ userId, transactionHash, }) {
|
|
|
67
68
|
.then((res) => res.data);
|
|
68
69
|
}
|
|
69
70
|
async function requestWithdrawlSignature(input) {
|
|
70
|
-
return
|
|
71
|
+
return baseClient
|
|
71
72
|
.post(`${PAYOUTS_ENDPOINT}/signers/collateral-withdrawl`, input)
|
|
72
73
|
.then((res) => res.data);
|
|
73
74
|
}
|
|
74
75
|
async function submit7702Message(input) {
|
|
75
|
-
return
|
|
76
|
+
return baseClient
|
|
76
77
|
.post(`${PAYOUTS_ENDPOINT}/signers/7702`, input)
|
|
77
78
|
.then((res) => res.data);
|
|
78
79
|
}
|
|
79
80
|
async function executeRainAdminChange(input) {
|
|
80
|
-
return
|
|
81
|
+
return baseClient
|
|
81
82
|
.post(`${PAYOUTS_ENDPOINT}/signers/rain-admin-change`, input)
|
|
82
83
|
.then((res) => res.data);
|
|
83
84
|
}
|
|
@@ -85,7 +86,7 @@ async function executeRainAdminChange(input) {
|
|
|
85
86
|
// host via the /v2/bridgebot base path (the bare /bridgebot base path maps to
|
|
86
87
|
// bridgebot's legacy REST API, which does not carry this route).
|
|
87
88
|
async function getTreasuryBalances() {
|
|
88
|
-
return
|
|
89
|
+
return baseClient
|
|
89
90
|
.get(`/v2${PAYOUTS_ENDPOINT}/api/treasury/balances`)
|
|
90
91
|
.then((res) => res.data);
|
|
91
92
|
}
|
|
@@ -57,19 +57,23 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
57
57
|
// @ts-expect-error no type declarations for axios-token-interceptor
|
|
58
58
|
const axios_token_interceptor_1 = __importDefault(require("axios-token-interceptor"));
|
|
59
59
|
const config_1 = require("../config");
|
|
60
|
+
const sigv4_1 = require("../sigv4");
|
|
60
61
|
const credentials_1 = require("../credentials");
|
|
61
62
|
const EXPIRATION_BUFFER_MS = 20 * 60 * 1000;
|
|
63
|
+
const iamUrl = process.env.PLATFORM_SERVICE_API_IAM_URL;
|
|
62
64
|
const platformClient = axios_1.default.create({
|
|
63
|
-
baseURL: config_1.config.platformEndpoint,
|
|
65
|
+
baseURL: iamUrl || config_1.config.platformEndpoint,
|
|
64
66
|
// See DEFAULT_TIMEOUT_MS in serviceClient.ts — same rationale.
|
|
65
67
|
timeout: 10000,
|
|
66
68
|
});
|
|
67
|
-
platformClient.interceptors.request.use(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
})
|
|
69
|
+
platformClient.interceptors.request.use(iamUrl
|
|
70
|
+
? (0, sigv4_1.createSigV4Interceptor)(iamUrl)
|
|
71
|
+
: (0, axios_token_interceptor_1.default)({
|
|
72
|
+
getToken: axios_token_interceptor_1.default.tokenCache(credentials_1.getServiceCredentials, {
|
|
73
|
+
getMaxAge: () => EXPIRATION_BUFFER_MS,
|
|
74
|
+
}),
|
|
75
|
+
headerFormatter: (res) => `Bearer ${res.access_token}`,
|
|
76
|
+
}));
|
|
73
77
|
const BILLPAY_ENDPOINT = "/v1/billpay";
|
|
74
78
|
async function validateBill(request) {
|
|
75
79
|
return platformClient
|
|
@@ -48,25 +48,26 @@ exports.orderPhysicalCard = orderPhysicalCard;
|
|
|
48
48
|
exports.getPendingCardOrder = getPendingCardOrder;
|
|
49
49
|
exports.getCardUser = getCardUser;
|
|
50
50
|
exports.RainClient = __importStar(require("./rainServiceClient"));
|
|
51
|
-
const
|
|
51
|
+
const restClient_1 = require("../restClient");
|
|
52
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.RAIN_SERVICE_API_IAM_URL);
|
|
52
53
|
const RAIN_ENDPOINT = "/rain-v2";
|
|
53
54
|
async function createCardApplication(userId, input) {
|
|
54
|
-
return
|
|
55
|
+
return baseClient
|
|
55
56
|
.post(`${RAIN_ENDPOINT}/application?userId=${userId}`, input)
|
|
56
57
|
.then((res) => res.data);
|
|
57
58
|
}
|
|
58
59
|
async function getUserDepositAddress({ userId, network, }) {
|
|
59
|
-
return
|
|
60
|
+
return baseClient
|
|
60
61
|
.get(`${RAIN_ENDPOINT}/api/users/${userId}/deposit-address?network=${network}`)
|
|
61
62
|
.then((res) => res.data);
|
|
62
63
|
}
|
|
63
64
|
async function validateContractAddress(input) {
|
|
64
|
-
return
|
|
65
|
+
return baseClient
|
|
65
66
|
.post(`${RAIN_ENDPOINT}/contract/validate`, input)
|
|
66
67
|
.then((res) => res.data);
|
|
67
68
|
}
|
|
68
69
|
async function createRainCard({ userId, nickname, type, shipping, }) {
|
|
69
|
-
return
|
|
70
|
+
return baseClient
|
|
70
71
|
.post(`${RAIN_ENDPOINT}/card`, {
|
|
71
72
|
userId,
|
|
72
73
|
nickname,
|
|
@@ -76,7 +77,7 @@ async function createRainCard({ userId, nickname, type, shipping, }) {
|
|
|
76
77
|
.then((res) => res.data);
|
|
77
78
|
}
|
|
78
79
|
async function updateCardStatus({ userId, status, cardExternalId, }) {
|
|
79
|
-
return
|
|
80
|
+
return baseClient
|
|
80
81
|
.post(`${RAIN_ENDPOINT}/card/status`, {
|
|
81
82
|
userId,
|
|
82
83
|
status,
|
|
@@ -85,7 +86,7 @@ async function updateCardStatus({ userId, status, cardExternalId, }) {
|
|
|
85
86
|
.then((res) => res.data);
|
|
86
87
|
}
|
|
87
88
|
async function activatePhysicalCard({ userId, accountId, expirationMonth, expirationYear, }) {
|
|
88
|
-
return
|
|
89
|
+
return baseClient
|
|
89
90
|
.post(`${RAIN_ENDPOINT}/card/activate`, {
|
|
90
91
|
userId,
|
|
91
92
|
accountId,
|
|
@@ -95,19 +96,19 @@ async function activatePhysicalCard({ userId, accountId, expirationMonth, expira
|
|
|
95
96
|
.then((res) => res.data);
|
|
96
97
|
}
|
|
97
98
|
async function getLiveBalance({ userId }) {
|
|
98
|
-
return
|
|
99
|
+
return baseClient
|
|
99
100
|
.get(`${RAIN_ENDPOINT}/api/users/${userId}/cards/balance`)
|
|
100
101
|
.then((res) => res.data);
|
|
101
102
|
}
|
|
102
103
|
async function getCardDetails({ userId, cardId }) {
|
|
103
|
-
return
|
|
104
|
+
return baseClient
|
|
104
105
|
.post(`${RAIN_ENDPOINT}/api/cards/${cardId}/details`, {
|
|
105
106
|
userId,
|
|
106
107
|
})
|
|
107
108
|
.then((res) => res.data);
|
|
108
109
|
}
|
|
109
110
|
async function requestWithdrawalSignature({ userId, network, amount, }) {
|
|
110
|
-
return
|
|
111
|
+
return baseClient
|
|
111
112
|
.post(`${RAIN_ENDPOINT}/withdrawl-signature`, {
|
|
112
113
|
userId,
|
|
113
114
|
network,
|
|
@@ -116,22 +117,22 @@ async function requestWithdrawalSignature({ userId, network, amount, }) {
|
|
|
116
117
|
.then((res) => res.data);
|
|
117
118
|
}
|
|
118
119
|
async function adminGetUserInfo({ userId }) {
|
|
119
|
-
return
|
|
120
|
+
return baseClient
|
|
120
121
|
.get(`${RAIN_ENDPOINT}/admin/user/${userId}/info`)
|
|
121
122
|
.then((res) => res.data);
|
|
122
123
|
}
|
|
123
124
|
async function orderPhysicalCard(input) {
|
|
124
|
-
return
|
|
125
|
+
return baseClient
|
|
125
126
|
.post(`${RAIN_ENDPOINT}/card/order`, input)
|
|
126
127
|
.then((res) => res.data);
|
|
127
128
|
}
|
|
128
129
|
async function getPendingCardOrder(userId) {
|
|
129
|
-
return
|
|
130
|
+
return baseClient
|
|
130
131
|
.get(`${RAIN_ENDPOINT}/api/cards/orders/pending?userId=${userId}`)
|
|
131
132
|
.then((res) => res.data);
|
|
132
133
|
}
|
|
133
134
|
async function getCardUser(userId) {
|
|
134
|
-
return
|
|
135
|
+
return baseClient
|
|
135
136
|
.get(`${RAIN_ENDPOINT}/api/users/${userId}/application`)
|
|
136
137
|
.then((res) => res.data);
|
|
137
138
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRestClient = void 0;
|
|
4
|
+
const serviceClient_1 = require("./serviceClient");
|
|
5
|
+
/** Preserve the shared legacy client unless this service explicitly opts into IAM. */
|
|
6
|
+
const getRestClient = (iamUrl) => iamUrl ? (0, serviceClient_1.createServiceClient)({}, iamUrl) : serviceClient_1.baseClient;
|
|
7
|
+
exports.getRestClient = getRestClient;
|
package/lib/serviceClient.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from "axios";
|
|
2
2
|
export declare const DEFAULT_TIMEOUT_MS = 10000;
|
|
3
|
-
export declare const createServiceClient: (config: AxiosRequestConfig) => import("axios").AxiosInstance;
|
|
3
|
+
export declare const createServiceClient: (config: AxiosRequestConfig, iamUrl?: string) => import("axios").AxiosInstance;
|
|
4
4
|
export declare const baseClient: import("axios").AxiosInstance;
|
package/lib/serviceClient.js
CHANGED
|
@@ -10,6 +10,7 @@ const axios_token_interceptor_1 = __importDefault(require("axios-token-intercept
|
|
|
10
10
|
const logger_1 = __importDefault(require("@spritz-finance/logger"));
|
|
11
11
|
const config_1 = require("./config");
|
|
12
12
|
const credentials_1 = require("./credentials");
|
|
13
|
+
const sigv4_1 = require("./sigv4");
|
|
13
14
|
const EXPIRATION_BUFFER_MS = 20 * 60 * 1000; // 20 minutes buffer
|
|
14
15
|
const RETRY_DELAY_MS = 300;
|
|
15
16
|
const RETRY_STATUS_CODE = 502;
|
|
@@ -29,9 +30,13 @@ const interceptor = function (tokenProvider, authenticate) {
|
|
|
29
30
|
return tokenProvider({ getToken, headerFormatter });
|
|
30
31
|
};
|
|
31
32
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
32
|
-
const createServiceClient = (config) => {
|
|
33
|
-
const serviceClient = axios_1.default.create({
|
|
34
|
-
|
|
33
|
+
const createServiceClient = (config, iamUrl) => {
|
|
34
|
+
const serviceClient = axios_1.default.create({
|
|
35
|
+
timeout: exports.DEFAULT_TIMEOUT_MS,
|
|
36
|
+
...config,
|
|
37
|
+
...(iamUrl ? { baseURL: iamUrl } : {}),
|
|
38
|
+
});
|
|
39
|
+
serviceClient.interceptors.request.use(iamUrl ? (0, sigv4_1.createSigV4Interceptor)(iamUrl) : interceptor(axios_token_interceptor_1.default, credentials_1.getServiceCredentials));
|
|
35
40
|
// Add trace header propagation interceptor
|
|
36
41
|
serviceClient.interceptors.request.use((requestConfig) => {
|
|
37
42
|
var _a, _b;
|
package/lib/sigv4.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AwsCredentialIdentityProvider } from "@smithy/types";
|
|
2
|
+
import { AxiosRequestConfig } from "axios";
|
|
3
|
+
/** Register before other request interceptors: axios runs them in reverse order. */
|
|
4
|
+
export declare function createSigV4Interceptor(iamUrl: string, credentialProvider?: AwsCredentialIdentityProvider): (request: AxiosRequestConfig) => Promise<AxiosRequestConfig>;
|
package/lib/sigv4.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createSigV4Interceptor = createSigV4Interceptor;
|
|
7
|
+
const credential_providers_1 = require("@aws-sdk/credential-providers");
|
|
8
|
+
const hash_node_1 = require("@smithy/hash-node");
|
|
9
|
+
const signature_v4_1 = require("@smithy/signature-v4");
|
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
|
11
|
+
const config_1 = require("./config");
|
|
12
|
+
// Cache the provider, not its result: the SDK owns credential refresh/expiry.
|
|
13
|
+
const credentials = (0, credential_providers_1.fromNodeProviderChain)();
|
|
14
|
+
const headerGroups = ["common", "delete", "get", "head", "post", "put", "patch"];
|
|
15
|
+
const signingHeaders = new Set([
|
|
16
|
+
"authorization",
|
|
17
|
+
"host",
|
|
18
|
+
"x-amz-date",
|
|
19
|
+
"x-amz-security-token",
|
|
20
|
+
"x-amz-content-sha256",
|
|
21
|
+
]);
|
|
22
|
+
/** Register before other request interceptors: axios runs them in reverse order. */
|
|
23
|
+
function createSigV4Interceptor(iamUrl, credentialProvider = credentials) {
|
|
24
|
+
const origin = new URL(iamUrl).origin;
|
|
25
|
+
const signer = new signature_v4_1.SignatureV4({
|
|
26
|
+
credentials: credentialProvider,
|
|
27
|
+
region: config_1.config.region,
|
|
28
|
+
service: "lambda",
|
|
29
|
+
sha256: hash_node_1.Hash.bind(null, "sha256"),
|
|
30
|
+
});
|
|
31
|
+
return async (request) => {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const baseUrl = request.baseURL;
|
|
34
|
+
if (!baseUrl || new URL(baseUrl).origin !== origin)
|
|
35
|
+
return request;
|
|
36
|
+
// Match axios 0.26's baseURL concatenation (a leading slash keeps the base path).
|
|
37
|
+
const requestUrl = request.url || "";
|
|
38
|
+
const fullUrl = /^([a-z][a-z\d+.-]*:)?\/\//i.test(requestUrl)
|
|
39
|
+
? new URL(requestUrl, baseUrl).href
|
|
40
|
+
: `${baseUrl.replace(/\/+$/, "")}/${requestUrl.replace(/^\/+/, "")}`;
|
|
41
|
+
const url = new URL(axios_1.default.getUri({ ...request, url: fullUrl }));
|
|
42
|
+
if (url.origin !== origin)
|
|
43
|
+
return request;
|
|
44
|
+
if (request.auth || url.username || url.password) {
|
|
45
|
+
throw new Error("IAM requests cannot use HTTP basic authentication");
|
|
46
|
+
}
|
|
47
|
+
// Serialize once, before hashing, using the same transforms axios would run.
|
|
48
|
+
const rawHeaders = request.headers || {};
|
|
49
|
+
const transforms = (_b = (_a = request.transformRequest) !== null && _a !== void 0 ? _a : axios_1.default.defaults.transformRequest) !== null && _b !== void 0 ? _b : [];
|
|
50
|
+
let body = request.data;
|
|
51
|
+
for (const transform of Array.isArray(transforms) ? transforms : [transforms]) {
|
|
52
|
+
body = transform.call(request, body, rawHeaders);
|
|
53
|
+
}
|
|
54
|
+
if (body instanceof ArrayBuffer)
|
|
55
|
+
body = Buffer.from(body);
|
|
56
|
+
if (body != null && typeof body !== "string" && !Buffer.isBuffer(body)) {
|
|
57
|
+
throw new Error("IAM requests require a buffered body; streams are not supported");
|
|
58
|
+
}
|
|
59
|
+
// Axios 0.x's types omit its nested common/method header defaults.
|
|
60
|
+
const flattened = Object.assign({}, rawHeaders.common, rawHeaders[request.method || "get"], rawHeaders);
|
|
61
|
+
const headers = {};
|
|
62
|
+
for (const [name, value] of Object.entries(flattened)) {
|
|
63
|
+
const lower = name.toLowerCase();
|
|
64
|
+
if (!headerGroups.includes(lower) && !signingHeaders.has(lower) && value != null) {
|
|
65
|
+
headers[lower] = String(value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
headers.host = url.host;
|
|
69
|
+
const query = Object.create(null);
|
|
70
|
+
for (const key of new Set(url.searchParams.keys())) {
|
|
71
|
+
query[key] = url.searchParams.getAll(key);
|
|
72
|
+
}
|
|
73
|
+
const signed = await signer.sign({
|
|
74
|
+
method: (request.method || "get").toUpperCase(),
|
|
75
|
+
protocol: url.protocol,
|
|
76
|
+
hostname: url.hostname,
|
|
77
|
+
port: url.port ? Number(url.port) : undefined,
|
|
78
|
+
path: url.pathname,
|
|
79
|
+
query,
|
|
80
|
+
headers,
|
|
81
|
+
body: body !== null && body !== void 0 ? body : "",
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
...request,
|
|
85
|
+
url: url.href,
|
|
86
|
+
params: undefined,
|
|
87
|
+
paramsSerializer: undefined,
|
|
88
|
+
data: body,
|
|
89
|
+
headers: signed.headers,
|
|
90
|
+
transformRequest: [(data) => data],
|
|
91
|
+
// Redirects bypass interceptors and could forward the session token to another host.
|
|
92
|
+
maxRedirects: 0,
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -41,10 +41,11 @@ exports.getWalletMembership = getWalletMembership;
|
|
|
41
41
|
exports.getOutstandingUserTransactions = getOutstandingUserTransactions;
|
|
42
42
|
exports.updateUserTransactionStatus = updateUserTransactionStatus;
|
|
43
43
|
exports.TransactionsClient = __importStar(require("./transactionsServiceClient"));
|
|
44
|
-
const
|
|
44
|
+
const restClient_1 = require("../restClient");
|
|
45
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.TRANSACTIONS_SERVICE_API_IAM_URL);
|
|
45
46
|
const TRANSACTIONS_ENDPOINT = "/transactions";
|
|
46
47
|
async function createPaymentInvoice(network, amount, paymentReference, tokenAddress, userId) {
|
|
47
|
-
return
|
|
48
|
+
return baseClient
|
|
48
49
|
.post(`${TRANSACTIONS_ENDPOINT}/v2/invoices`, {
|
|
49
50
|
network,
|
|
50
51
|
amount,
|
|
@@ -55,12 +56,12 @@ async function createPaymentInvoice(network, amount, paymentReference, tokenAddr
|
|
|
55
56
|
.then((res) => res.data);
|
|
56
57
|
}
|
|
57
58
|
async function getAssetPriceBySymbol(symbol) {
|
|
58
|
-
return
|
|
59
|
+
return baseClient
|
|
59
60
|
.get(`${TRANSACTIONS_ENDPOINT}/v2/asset-price/${symbol}`)
|
|
60
61
|
.then((res) => res.data);
|
|
61
62
|
}
|
|
62
63
|
async function reserveAddress(network, accountId) {
|
|
63
|
-
return
|
|
64
|
+
return baseClient
|
|
64
65
|
.post(`${TRANSACTIONS_ENDPOINT}/addresses/reserve`, {
|
|
65
66
|
network,
|
|
66
67
|
accountId,
|
|
@@ -68,17 +69,17 @@ async function reserveAddress(network, accountId) {
|
|
|
68
69
|
.then((res) => res.data);
|
|
69
70
|
}
|
|
70
71
|
async function getWalletMembership(address) {
|
|
71
|
-
return
|
|
72
|
+
return baseClient
|
|
72
73
|
.get(`${TRANSACTIONS_ENDPOINT}/addresses/${address}/membership`)
|
|
73
74
|
.then((res) => res.data);
|
|
74
75
|
}
|
|
75
76
|
async function getOutstandingUserTransactions(userId, accountId) {
|
|
76
|
-
return
|
|
77
|
+
return baseClient
|
|
77
78
|
.get(`${TRANSACTIONS_ENDPOINT}/wallet-transactions/outstanding/${userId}/account/${accountId}`)
|
|
78
79
|
.then((res) => res.data);
|
|
79
80
|
}
|
|
80
81
|
async function updateUserTransactionStatus(input) {
|
|
81
|
-
return
|
|
82
|
+
return baseClient
|
|
82
83
|
.post(`${TRANSACTIONS_ENDPOINT}/wallet-transactions/user`, input)
|
|
83
84
|
.then((res) => res.data);
|
|
84
85
|
}
|
|
@@ -41,33 +41,34 @@ exports.getUnblockPayment = getUnblockPayment;
|
|
|
41
41
|
exports.getExternalPayments = getExternalPayments;
|
|
42
42
|
exports.getBlockchainTransactions = getBlockchainTransactions;
|
|
43
43
|
exports.UnblockClient = __importStar(require("./unblockServiceClient"));
|
|
44
|
-
const
|
|
44
|
+
const restClient_1 = require("../restClient");
|
|
45
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.UNBLOCK_SERVICE_API_IAM_URL);
|
|
45
46
|
const UNBLOCK_ENDPOINT = "/unblock";
|
|
46
47
|
async function requestOTP(userId) {
|
|
47
|
-
return
|
|
48
|
+
return baseClient
|
|
48
49
|
.get(`${UNBLOCK_ENDPOINT}/user/${userId}/request-otp`)
|
|
49
50
|
.then((res) => res.data);
|
|
50
51
|
}
|
|
51
52
|
async function createUnblockAccount(input) {
|
|
52
|
-
return
|
|
53
|
+
return baseClient
|
|
53
54
|
.post(`${UNBLOCK_ENDPOINT}/account`, input)
|
|
54
55
|
.then((res) => res.data);
|
|
55
56
|
}
|
|
56
57
|
async function createUnblockUser(input) {
|
|
57
|
-
return
|
|
58
|
+
return baseClient.post(`${UNBLOCK_ENDPOINT}/user`, input).then((res) => res.data);
|
|
58
59
|
}
|
|
59
60
|
async function getUnblockPayment(externalPaymentId) {
|
|
60
|
-
return
|
|
61
|
+
return baseClient
|
|
61
62
|
.get(`${UNBLOCK_ENDPOINT}/payment/id/${externalPaymentId}`)
|
|
62
63
|
.then((res) => res.data);
|
|
63
64
|
}
|
|
64
65
|
async function getExternalPayments(accountIds) {
|
|
65
|
-
return
|
|
66
|
+
return baseClient
|
|
66
67
|
.get(`${UNBLOCK_ENDPOINT}/external-payments?accountIds=${accountIds.join(",")}`)
|
|
67
68
|
.then((res) => res.data);
|
|
68
69
|
}
|
|
69
70
|
async function getBlockchainTransactions(paymentIds) {
|
|
70
|
-
return
|
|
71
|
+
return baseClient
|
|
71
72
|
.get(`${UNBLOCK_ENDPOINT}/blockchain-transactions?paymentIds=${paymentIds.join(",")}`)
|
|
72
73
|
.then((res) => res.data);
|
|
73
74
|
}
|
|
@@ -46,27 +46,28 @@ exports.getIntegratorWebhooks = getIntegratorWebhooks;
|
|
|
46
46
|
exports.getIntegrator = getIntegrator;
|
|
47
47
|
exports.getIntegratorByCode = getIntegratorByCode;
|
|
48
48
|
exports.UsersClient = __importStar(require("./usersServiceClient"));
|
|
49
|
-
const
|
|
49
|
+
const restClient_1 = require("../restClient");
|
|
50
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.USERS_SERVICE_API_IAM_URL);
|
|
50
51
|
const NEW_USER_ENDPOINT = "/v2/users/api";
|
|
51
52
|
async function getActiveUsers() {
|
|
52
|
-
return
|
|
53
|
+
return baseClient
|
|
53
54
|
.get(`${NEW_USER_ENDPOINT}/users/active`)
|
|
54
55
|
.then((res) => res.data);
|
|
55
56
|
}
|
|
56
57
|
async function getUserById(id) {
|
|
57
|
-
return
|
|
58
|
+
return baseClient
|
|
58
59
|
.get(`${NEW_USER_ENDPOINT}/users/${id}`)
|
|
59
60
|
.then((res) => res.data);
|
|
60
61
|
}
|
|
61
62
|
async function setMembership(userId, membership) {
|
|
62
|
-
return
|
|
63
|
+
return baseClient
|
|
63
64
|
.post(`${NEW_USER_ENDPOINT}/users/${userId}/membership`, {
|
|
64
65
|
membership,
|
|
65
66
|
})
|
|
66
67
|
.then((res) => res.data);
|
|
67
68
|
}
|
|
68
69
|
async function findOrInitialize(email) {
|
|
69
|
-
return
|
|
70
|
+
return baseClient
|
|
70
71
|
.post(`${NEW_USER_ENDPOINT}/users`, {
|
|
71
72
|
email,
|
|
72
73
|
})
|
|
@@ -82,7 +83,7 @@ async function findOrInitialize(email) {
|
|
|
82
83
|
* when the tenant is known, or `listByEmail` and choose explicitly.
|
|
83
84
|
*/
|
|
84
85
|
async function findByEmail(email) {
|
|
85
|
-
return
|
|
86
|
+
return baseClient
|
|
86
87
|
.get(`${NEW_USER_ENDPOINT}/users?email=${encodeURIComponent(email)}`)
|
|
87
88
|
.then((res) => res.data);
|
|
88
89
|
}
|
|
@@ -95,7 +96,7 @@ async function findByEmail(email) {
|
|
|
95
96
|
*/
|
|
96
97
|
async function findByEmailInTenant(email, tenant) {
|
|
97
98
|
const query = `email=${encodeURIComponent(email)}&tenant=${encodeURIComponent(tenant)}`;
|
|
98
|
-
return
|
|
99
|
+
return baseClient
|
|
99
100
|
.get(`${NEW_USER_ENDPOINT}/users/by-email?${query}`)
|
|
100
101
|
.then((res) => res.data);
|
|
101
102
|
}
|
|
@@ -106,22 +107,22 @@ async function findByEmailInTenant(email, tenant) {
|
|
|
106
107
|
* refuse and ask for an account id rather than take the first.
|
|
107
108
|
*/
|
|
108
109
|
async function listByEmail(email) {
|
|
109
|
-
return
|
|
110
|
+
return baseClient
|
|
110
111
|
.get(`${NEW_USER_ENDPOINT}/users/all-by-email?email=${encodeURIComponent(email)}`)
|
|
111
112
|
.then((res) => res.data);
|
|
112
113
|
}
|
|
113
114
|
async function validateAdIdentifiers(adIdentifiers) {
|
|
114
|
-
return
|
|
115
|
+
return baseClient
|
|
115
116
|
.post(`${NEW_USER_ENDPOINT}/users/ad-identifiers/validations`, adIdentifiers)
|
|
116
117
|
.then((res) => res.data);
|
|
117
118
|
}
|
|
118
119
|
async function getIntegratorWebhooks(integratorId) {
|
|
119
|
-
return
|
|
120
|
+
return baseClient
|
|
120
121
|
.get(`${NEW_USER_ENDPOINT}/integrators/${integratorId}/webhooks`)
|
|
121
122
|
.then((res) => res.data);
|
|
122
123
|
}
|
|
123
124
|
async function getIntegrator(integratorId) {
|
|
124
|
-
return
|
|
125
|
+
return baseClient
|
|
125
126
|
.get(`${NEW_USER_ENDPOINT}/integrators/${integratorId}`)
|
|
126
127
|
.then((res) => res.data);
|
|
127
128
|
}
|
|
@@ -130,7 +131,7 @@ async function getIntegrator(integratorId) {
|
|
|
130
131
|
* Returns identity only — use `getIntegrator` when you need the full record.
|
|
131
132
|
*/
|
|
132
133
|
async function getIntegratorByCode(code) {
|
|
133
|
-
return
|
|
134
|
+
return baseClient
|
|
134
135
|
.get(`${NEW_USER_ENDPOINT}/integrators/by-code?code=${encodeURIComponent(code)}`)
|
|
135
136
|
.then((res) => res.data);
|
|
136
137
|
}
|