@spritz-finance/service-client 0.36.0 → 0.37.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
CHANGED
|
@@ -19,9 +19,8 @@ Each namespace opts in independently, including namespaces that share a backend.
|
|
|
19
19
|
`/v2/<svc>/api` gateway prefix are signed and sent to the IAM twin (the prefix
|
|
20
20
|
is stripped to `/api/...`). Calls to legacy v1 REST routes in the same
|
|
21
21
|
namespace stay on the gateway with the `service_` token — so mixed modules
|
|
22
|
-
migrate route by route, and v1-only namespaces (
|
|
23
|
-
|
|
24
|
-
`/api` equivalents.
|
|
22
|
+
migrate route by route, and v1-only namespaces (unblock, verification's v1
|
|
23
|
+
paths, ...) are unaffected until their callers move to the `/api` equivalents.
|
|
25
24
|
Set these variables to the corresponding service's IAM Function URL:
|
|
26
25
|
|
|
27
26
|
| Client | Environment variable |
|
|
@@ -38,9 +38,11 @@ exports.initializePaymentAddresses = initializePaymentAddresses;
|
|
|
38
38
|
exports.PaymentAddressClient = __importStar(require("./paymentAddressServiceClient"));
|
|
39
39
|
const restClient_1 = require("../restClient");
|
|
40
40
|
const baseClient = (0, restClient_1.getRestClient)(process.env.PAYMENT_ADDRESS_SERVICE_API_IAM_URL, "/payment-addresses-v2/api");
|
|
41
|
-
|
|
41
|
+
// Payment-addresses' Hono ServiceApi, reached through the gateway's
|
|
42
|
+
// /payment-addresses-v2 base path.
|
|
43
|
+
const PAYMENT_ADDRESSES_API_ENDPOINT = "/payment-addresses-v2/api";
|
|
42
44
|
async function initializePaymentAddresses(body) {
|
|
43
45
|
return baseClient
|
|
44
|
-
.post(`${
|
|
46
|
+
.post(`${PAYMENT_ADDRESSES_API_ENDPOINT}/payment-addresses/initialize`, body)
|
|
45
47
|
.then((res) => res.data);
|
|
46
48
|
}
|
|
@@ -65,7 +65,7 @@ async function requestCryptoPayout({ userId, type, network, amountFiat, referenc
|
|
|
65
65
|
}
|
|
66
66
|
async function getPayoutFromHash({ userId, transactionHash, }) {
|
|
67
67
|
return baseClient
|
|
68
|
-
.post(`${
|
|
68
|
+
.post(`${PAYOUTS_API_ENDPOINT}/payouts/hash`, {
|
|
69
69
|
userId,
|
|
70
70
|
transactionHash,
|
|
71
71
|
})
|
|
@@ -57,9 +57,11 @@ const RAIN_ENDPOINT = "/rain-v2";
|
|
|
57
57
|
// user saw an error for an application that succeeded. Stay under the 30s
|
|
58
58
|
// Lambda timeout on both sides.
|
|
59
59
|
exports.CREATE_CARD_APPLICATION_TIMEOUT_MS = 28000;
|
|
60
|
+
// `/api/applications` takes the userId in the body, where the legacy
|
|
61
|
+
// `/application?userId=` route read it from the query; the argument still wins.
|
|
60
62
|
async function createCardApplication(userId, input) {
|
|
61
63
|
return baseClient
|
|
62
|
-
.post(`${RAIN_ENDPOINT}/
|
|
64
|
+
.post(`${RAIN_ENDPOINT}/api/applications`, { ...input, userId }, {
|
|
63
65
|
timeout: exports.CREATE_CARD_APPLICATION_TIMEOUT_MS,
|
|
64
66
|
// Opt out of the shared 502 retry: a 502 can arrive after Rain already
|
|
65
67
|
// created the application, a repeat create fails, and a second 28s
|
|
@@ -75,12 +77,12 @@ async function getUserDepositAddress({ userId, network, }) {
|
|
|
75
77
|
}
|
|
76
78
|
async function validateContractAddress(input) {
|
|
77
79
|
return baseClient
|
|
78
|
-
.post(`${RAIN_ENDPOINT}/
|
|
80
|
+
.post(`${RAIN_ENDPOINT}/api/contracts/validations`, input)
|
|
79
81
|
.then((res) => res.data);
|
|
80
82
|
}
|
|
81
83
|
async function createRainCard({ userId, nickname, type, shipping, }) {
|
|
82
84
|
return baseClient
|
|
83
|
-
.post(`${RAIN_ENDPOINT}/
|
|
85
|
+
.post(`${RAIN_ENDPOINT}/api/cards`, {
|
|
84
86
|
userId,
|
|
85
87
|
nickname,
|
|
86
88
|
type,
|
|
@@ -98,10 +100,10 @@ async function updateCardStatus({ userId, status, cardExternalId, }) {
|
|
|
98
100
|
.then((res) => res.data);
|
|
99
101
|
}
|
|
100
102
|
async function activatePhysicalCard({ userId, accountId, expirationMonth, expirationYear, }) {
|
|
103
|
+
// The card's accountId moves from the legacy `/card/activate` body into the path.
|
|
101
104
|
return baseClient
|
|
102
|
-
.post(`${RAIN_ENDPOINT}/
|
|
105
|
+
.post(`${RAIN_ENDPOINT}/api/cards/${accountId}/activations`, {
|
|
103
106
|
userId,
|
|
104
|
-
accountId,
|
|
105
107
|
expirationMonth,
|
|
106
108
|
expirationYear,
|
|
107
109
|
})
|
|
@@ -130,12 +132,12 @@ async function requestWithdrawalSignature({ userId, network, amount, }) {
|
|
|
130
132
|
}
|
|
131
133
|
async function adminGetUserInfo({ userId }) {
|
|
132
134
|
return baseClient
|
|
133
|
-
.get(`${RAIN_ENDPOINT}/admin/
|
|
135
|
+
.get(`${RAIN_ENDPOINT}/api/admin/users/${userId}`)
|
|
134
136
|
.then((res) => res.data);
|
|
135
137
|
}
|
|
136
138
|
async function orderPhysicalCard(input) {
|
|
137
139
|
return baseClient
|
|
138
|
-
.post(`${RAIN_ENDPOINT}/
|
|
140
|
+
.post(`${RAIN_ENDPOINT}/api/cards/orders`, input)
|
|
139
141
|
.then((res) => res.data);
|
|
140
142
|
}
|
|
141
143
|
async function getPendingCardOrder(userId) {
|
|
@@ -42,11 +42,27 @@ exports.getOutstandingUserTransactions = getOutstandingUserTransactions;
|
|
|
42
42
|
exports.updateUserTransactionStatus = updateUserTransactionStatus;
|
|
43
43
|
exports.TransactionsClient = __importStar(require("./transactionsServiceClient"));
|
|
44
44
|
const restClient_1 = require("../restClient");
|
|
45
|
-
const baseClient = (0, restClient_1.getRestClient)(process.env.TRANSACTIONS_SERVICE_API_IAM_URL);
|
|
45
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.TRANSACTIONS_SERVICE_API_IAM_URL, "/v2/transactions/api");
|
|
46
46
|
const TRANSACTIONS_ENDPOINT = "/transactions";
|
|
47
|
+
// Transactions' Hono ServiceApi, reached through the gateway's /v2/transactions
|
|
48
|
+
// base path (the bare /transactions base path maps to the legacy REST routes).
|
|
49
|
+
const TRANSACTIONS_API_ENDPOINT = "/v2/transactions/api";
|
|
50
|
+
/**
|
|
51
|
+
* Awaits an `/api` request and returns the bare body its legacy route answered
|
|
52
|
+
* with. The `/api` routes answer every failure as a 200 failure envelope;
|
|
53
|
+
* throw on it, as the legacy route's non-2xx did.
|
|
54
|
+
*/
|
|
55
|
+
async function legacyBareBody(request, failureMessage) {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const body = (await request).data;
|
|
58
|
+
if (body.status === "failure") {
|
|
59
|
+
throw new Error((_b = (_a = body.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : failureMessage);
|
|
60
|
+
}
|
|
61
|
+
return body.data;
|
|
62
|
+
}
|
|
47
63
|
async function createPaymentInvoice(network, amount, paymentReference, tokenAddress, userId) {
|
|
48
64
|
return baseClient
|
|
49
|
-
.post(`${
|
|
65
|
+
.post(`${TRANSACTIONS_API_ENDPOINT}/invoices`, {
|
|
50
66
|
network,
|
|
51
67
|
amount,
|
|
52
68
|
paymentReference,
|
|
@@ -57,7 +73,7 @@ async function createPaymentInvoice(network, amount, paymentReference, tokenAddr
|
|
|
57
73
|
}
|
|
58
74
|
async function getAssetPriceBySymbol(symbol) {
|
|
59
75
|
return baseClient
|
|
60
|
-
.get(`${
|
|
76
|
+
.get(`${TRANSACTIONS_API_ENDPOINT}/asset-price/${symbol}`)
|
|
61
77
|
.then((res) => res.data);
|
|
62
78
|
}
|
|
63
79
|
async function reserveAddress(network, accountId) {
|
|
@@ -69,17 +85,11 @@ async function reserveAddress(network, accountId) {
|
|
|
69
85
|
.then((res) => res.data);
|
|
70
86
|
}
|
|
71
87
|
async function getWalletMembership(address) {
|
|
72
|
-
return baseClient
|
|
73
|
-
.get(`${TRANSACTIONS_ENDPOINT}/addresses/${address}/membership`)
|
|
74
|
-
.then((res) => res.data);
|
|
88
|
+
return legacyBareBody(baseClient.get(`${TRANSACTIONS_API_ENDPOINT}/addresses/${address}/membership`), "Failed to get wallet membership");
|
|
75
89
|
}
|
|
76
90
|
async function getOutstandingUserTransactions(userId, accountId) {
|
|
77
|
-
return baseClient
|
|
78
|
-
.get(`${TRANSACTIONS_ENDPOINT}/wallet-transactions/outstanding/${userId}/account/${accountId}`)
|
|
79
|
-
.then((res) => res.data);
|
|
91
|
+
return legacyBareBody(baseClient.get(`${TRANSACTIONS_API_ENDPOINT}/wallet-transactions/outstanding/${userId}/account/${accountId}`), "Failed to get outstanding user transactions");
|
|
80
92
|
}
|
|
81
93
|
async function updateUserTransactionStatus(input) {
|
|
82
|
-
return baseClient
|
|
83
|
-
.post(`${TRANSACTIONS_ENDPOINT}/wallet-transactions/user`, input)
|
|
84
|
-
.then((res) => res.data);
|
|
94
|
+
return legacyBareBody(baseClient.post(`${TRANSACTIONS_API_ENDPOINT}/wallet-transactions/user`, input), "Failed to update user transaction status");
|
|
85
95
|
}
|