@spritz-finance/service-client 0.40.0 → 0.41.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 +17 -15
- package/lib/bridge/bridgeServiceClient.js +1 -1
- package/lib/checkbook/checkbookServiceClient.js +1 -1
- package/lib/exchangeRates/exchangeRatesServiceClient.js +1 -1
- package/lib/features/featuresServiceClient.js +1 -1
- package/lib/growth/growthServiceClient.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/liabilities/liabilitiesServiceClient.js +1 -1
- package/lib/notifications/notificationsServiceClient.js +1 -1
- package/lib/onramp/onrampServiceClient.js +1 -1
- package/lib/payableAccounts/payableAccountsServiceClient.js +1 -1
- package/lib/paymentAddress/paymentAddressServiceClient.js +1 -1
- package/lib/payments/paymentsClient.js +1 -1
- package/lib/payouts/payoutsServiceClient.js +1 -1
- package/lib/platform/platformServiceClient.js +9 -6
- package/lib/rain/rainServiceClient.d.ts +14 -13
- package/lib/rain/rainServiceClient.js +47 -4
- package/lib/restClient.d.ts +13 -4
- package/lib/restClient.js +14 -6
- package/lib/serviceClient.d.ts +13 -1
- package/lib/serviceClient.js +42 -4
- package/lib/transactions/transactionsServiceClient.js +1 -1
- package/lib/unblock/unblockServiceClient.js +1 -1
- package/lib/users/usersServiceClient.js +1 -1
- package/lib/verification/verificationServiceClient.js +1 -1
- package/lib/web3/web3ServiceClient.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# Service client
|
|
2
2
|
|
|
3
|
-
REST clients
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
REST clients for services with an IAM twin authenticate with AWS IAM (SigV4) and
|
|
4
|
+
**require** their `<SVC>_SERVICE_API_IAM_URL` environment variable, set **before
|
|
5
|
+
importing this package**. Without it every call on that client rejects with
|
|
6
|
+
`MissingIamTwinError` (`no IAM twin configured for <svc> — set <SVC>_SERVICE_API_IAM_URL`)
|
|
7
|
+
before any request or token is made; there is no
|
|
8
|
+
shared-secret fallback. Importing the package never throws, so a consumer only
|
|
9
|
+
needs the variables of the clients it calls. Graph authentication is unaffected.
|
|
7
10
|
|
|
8
11
|
```ts
|
|
9
12
|
// Deployment environment:
|
|
@@ -13,21 +16,17 @@ import { UsersClient } from "@spritz-finance/service-client";
|
|
|
13
16
|
await UsersClient.getUserById("user-id");
|
|
14
17
|
```
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
`/
|
|
20
|
-
|
|
21
|
-
namespace stay on the gateway with the `service_` token — so mixed modules
|
|
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.
|
|
19
|
+
**Per-request routing:** only calls under a client's gateway prefix (e.g.
|
|
20
|
+
`/v2/<svc>/api`) are signed and sent to the IAM twin (the prefix is stripped to
|
|
21
|
+
`/api/...`). Calls to legacy v1 REST routes in the same namespace (e.g.
|
|
22
|
+
`/liabilities/...`, `/verification/...`) still go to the gateway with the
|
|
23
|
+
deprecated `service_` token, until callers move to the `/api` equivalents.
|
|
24
24
|
Set these variables to the corresponding service's IAM Function URL:
|
|
25
25
|
|
|
26
26
|
| Client | Environment variable |
|
|
27
27
|
| --------------------- | -------------------------------------- |
|
|
28
28
|
| BridgeClient | `BRIDGE_SERVICE_API_IAM_URL` |
|
|
29
29
|
| CheckbookClient | `CHECKBOOK_SERVICE_API_IAM_URL` |
|
|
30
|
-
| ExchangeRatesClient | `EXCHANGE_RATES_SERVICE_API_IAM_URL` |
|
|
31
30
|
| FeaturesClient | `FEATURES_SERVICE_API_IAM_URL` |
|
|
32
31
|
| GrowthClient | `GROWTH_SERVICE_API_IAM_URL` |
|
|
33
32
|
| LiabilitiesClient | `LIABILITIES_SERVICE_API_IAM_URL` |
|
|
@@ -37,14 +36,17 @@ Set these variables to the corresponding service's IAM Function URL:
|
|
|
37
36
|
| PaymentAddressClient | `PAYMENT_ADDRESS_SERVICE_API_IAM_URL` |
|
|
38
37
|
| PaymentsClient | `PAYMENTS_SERVICE_API_IAM_URL` |
|
|
39
38
|
| PayoutsClient | `PAYOUTS_SERVICE_API_IAM_URL` |
|
|
40
|
-
| PlatformClient | `PLATFORM_SERVICE_API_IAM_URL` |
|
|
41
39
|
| RainClient | `RAIN_SERVICE_API_IAM_URL` |
|
|
42
40
|
| TransactionsClient | `TRANSACTIONS_SERVICE_API_IAM_URL` |
|
|
43
|
-
| UnblockClient | `UNBLOCK_SERVICE_API_IAM_URL` |
|
|
44
41
|
| UsersClient | `USERS_SERVICE_API_IAM_URL` |
|
|
45
42
|
| VerificationClient | `VERIFICATION_SERVICE_API_IAM_URL` |
|
|
46
43
|
| Web3Client | `WEB3_SERVICE_API_IAM_URL` |
|
|
47
44
|
|
|
45
|
+
**Twinless callees (deprecated):** ExchangeRatesClient and UnblockClient always use
|
|
46
|
+
the gateway with the shared `service_` token. PlatformClient uses it unless
|
|
47
|
+
`PLATFORM_SERVICE_API_IAM_URL` is set. This path is removed when the shared
|
|
48
|
+
service-client auth secret is deleted.
|
|
49
|
+
|
|
48
50
|
The IAM URL becomes the base URL only for calls under the service's
|
|
49
51
|
`/v2/<svc>/api` gateway prefix; the prefix is stripped to `/api/...`, which is
|
|
50
52
|
what the Function URL twin serves. Calls to legacy v1 REST routes in the same
|
|
@@ -43,7 +43,7 @@ exports.getExchangeRates = getExchangeRates;
|
|
|
43
43
|
exports.getExternalPayments = getExternalPayments;
|
|
44
44
|
exports.BridgeClient = __importStar(require("./bridgeServiceClient"));
|
|
45
45
|
const restClient_1 = require("../restClient");
|
|
46
|
-
const baseClient = (0, restClient_1.
|
|
46
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("BRIDGE_SERVICE_API_IAM_URL", "/v2/bridge/api");
|
|
47
47
|
const ONRAMP_ROUTER_ENDPOINT = "/v2/bridge/api";
|
|
48
48
|
async function getTransferHashes(externalPaymentIds) {
|
|
49
49
|
return baseClient
|
|
@@ -39,7 +39,7 @@ exports.getBatchBalances = getBatchBalances;
|
|
|
39
39
|
exports.getFundingBatchBalances = getFundingBatchBalances;
|
|
40
40
|
exports.CheckbookClient = __importStar(require("./checkbookServiceClient"));
|
|
41
41
|
const restClient_1 = require("../restClient");
|
|
42
|
-
const baseClient = (0, restClient_1.
|
|
42
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("CHECKBOOK_SERVICE_API_IAM_URL", "/v2/liabilities/api");
|
|
43
43
|
const CHECKBOOK_ENDPOINT = "/liabilities";
|
|
44
44
|
const CHECKBOOK_API_ENDPOINT = "/v2/liabilities/api";
|
|
45
45
|
async function triggerBatch({ config, configs, reserve, currency, }) {
|
|
@@ -37,7 +37,7 @@ exports.ExchangeRatesClient = void 0;
|
|
|
37
37
|
exports.getLatestRate = getLatestRate;
|
|
38
38
|
exports.ExchangeRatesClient = __importStar(require("./exchangeRatesServiceClient"));
|
|
39
39
|
const restClient_1 = require("../restClient");
|
|
40
|
-
const baseClient = (0, restClient_1.
|
|
40
|
+
const baseClient = (0, restClient_1.getLegacyRestClient)();
|
|
41
41
|
const EXCHANGE_RATE_ENDPOINT = "/exchange-rates";
|
|
42
42
|
async function getLatestRate(target, base = "USD") {
|
|
43
43
|
return baseClient
|
|
@@ -43,7 +43,7 @@ exports.FeaturesClient = __importStar(require("./featuresServiceClient"));
|
|
|
43
43
|
const restClient_1 = require("../restClient");
|
|
44
44
|
const utils_1 = require("../utils");
|
|
45
45
|
const types_1 = require("./types");
|
|
46
|
-
const baseClient = (0, restClient_1.
|
|
46
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("FEATURES_SERVICE_API_IAM_URL", "/v2/users/api");
|
|
47
47
|
const FEATURES_ENDPOINT = "/v2/users/api/feature-flags";
|
|
48
48
|
const networkToFlag = (network) => {
|
|
49
49
|
switch (network) {
|
|
@@ -42,7 +42,7 @@ exports.validatePointsRedemption = validatePointsRedemption;
|
|
|
42
42
|
exports.confirmPointsRedemption = confirmPointsRedemption;
|
|
43
43
|
exports.GrowthClient = __importStar(require("./growthServiceClient"));
|
|
44
44
|
const restClient_1 = require("../restClient");
|
|
45
|
-
const baseClient = (0, restClient_1.
|
|
45
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("GROWTH_SERVICE_API_IAM_URL", "/v2/growth/api");
|
|
46
46
|
const GROWTH_ENDPOINT = "/growth";
|
|
47
47
|
const GROWTH_SERVICE_API_ENDPOINT = "/v2/growth/api";
|
|
48
48
|
/**
|
package/lib/index.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export { UnblockClient } from "./unblock/unblockServiceClient";
|
|
|
35
35
|
export * from "./users/types";
|
|
36
36
|
export { UsersClient } from "./users/usersServiceClient";
|
|
37
37
|
export * from "./utils";
|
|
38
|
+
export { MissingIamTwinError } from "./serviceClient";
|
|
38
39
|
export { createSigV4Interceptor } from "./sigv4";
|
|
39
40
|
export * from "./verification/types";
|
|
40
41
|
export { VerificationClient } from "./verification/verificationServiceClient";
|
package/lib/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Web3Client = exports.VerificationClient = exports.createSigV4Interceptor = exports.UsersClient = exports.UnblockClient = exports.TransactionsClient = exports.RainClient = exports.PayoutsClient = exports.PaymentsClient = exports.PlatformClient = exports.PaymentAddressClient = exports.PayableAccountsClient = exports.OnrampClient = exports.NotificationsClient = exports.LiabilitiesClient = exports.GrowthClient = exports.FeaturesClient = exports.ExchangeRatesClient = exports.CheckbookClient = exports.BridgeClient = void 0;
|
|
17
|
+
exports.Web3Client = exports.VerificationClient = exports.createSigV4Interceptor = exports.MissingIamTwinError = exports.UsersClient = exports.UnblockClient = exports.TransactionsClient = exports.RainClient = exports.PayoutsClient = exports.PaymentsClient = exports.PlatformClient = exports.PaymentAddressClient = exports.PayableAccountsClient = exports.OnrampClient = exports.NotificationsClient = exports.LiabilitiesClient = exports.GrowthClient = exports.FeaturesClient = exports.ExchangeRatesClient = exports.CheckbookClient = exports.BridgeClient = void 0;
|
|
18
18
|
var bridgeServiceClient_1 = require("./bridge/bridgeServiceClient");
|
|
19
19
|
Object.defineProperty(exports, "BridgeClient", { enumerable: true, get: function () { return bridgeServiceClient_1.BridgeClient; } });
|
|
20
20
|
__exportStar(require("./bridge/types"), exports);
|
|
@@ -69,6 +69,8 @@ __exportStar(require("./users/types"), exports);
|
|
|
69
69
|
var usersServiceClient_1 = require("./users/usersServiceClient");
|
|
70
70
|
Object.defineProperty(exports, "UsersClient", { enumerable: true, get: function () { return usersServiceClient_1.UsersClient; } });
|
|
71
71
|
__exportStar(require("./utils"), exports);
|
|
72
|
+
var serviceClient_1 = require("./serviceClient");
|
|
73
|
+
Object.defineProperty(exports, "MissingIamTwinError", { enumerable: true, get: function () { return serviceClient_1.MissingIamTwinError; } });
|
|
72
74
|
var sigv4_1 = require("./sigv4");
|
|
73
75
|
Object.defineProperty(exports, "createSigV4Interceptor", { enumerable: true, get: function () { return sigv4_1.createSigV4Interceptor; } });
|
|
74
76
|
__exportStar(require("./verification/types"), exports);
|
|
@@ -60,7 +60,7 @@ exports.getDirectPayment = getDirectPayment;
|
|
|
60
60
|
exports.issueRefundCredit = issueRefundCredit;
|
|
61
61
|
exports.LiabilitiesClient = __importStar(require("./liabilitiesServiceClient"));
|
|
62
62
|
const restClient_1 = require("../restClient");
|
|
63
|
-
const baseClient = (0, restClient_1.
|
|
63
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("LIABILITIES_SERVICE_API_IAM_URL", "/v2/liabilities/api");
|
|
64
64
|
const LIABILITIES_ENDPOINT = "/liabilities";
|
|
65
65
|
const LIABILITIES_V2_ENDPOINT = "/v2/liabilities/api";
|
|
66
66
|
/** Returns the envelope, including INVALID_INPUT and upstream service errors. */
|
|
@@ -37,7 +37,7 @@ exports.NotificationsClient = void 0;
|
|
|
37
37
|
exports.verifyEmail = verifyEmail;
|
|
38
38
|
exports.NotificationsClient = __importStar(require("./notificationsServiceClient"));
|
|
39
39
|
const restClient_1 = require("../restClient");
|
|
40
|
-
const baseClient = (0, restClient_1.
|
|
40
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("NOTIFICATIONS_SERVICE_API_IAM_URL", "/v2/notifications/api");
|
|
41
41
|
const NOTIFICATIONS_ENDPOINT = "/v2/notifications/api";
|
|
42
42
|
/**
|
|
43
43
|
* Verifies deliverability through the notifications service's reputation
|
|
@@ -40,7 +40,7 @@ exports.upsertBridgeUser = upsertBridgeUser;
|
|
|
40
40
|
exports.createBusinessUser = createBusinessUser;
|
|
41
41
|
exports.OnrampClient = __importStar(require("./onrampServiceClient"));
|
|
42
42
|
const restClient_1 = require("../restClient");
|
|
43
|
-
const baseClient = (0, restClient_1.
|
|
43
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("ONRAMP_SERVICE_API_IAM_URL", "/v2/bridge/api");
|
|
44
44
|
const ONRAMP_ENDPOINT = "/bridge";
|
|
45
45
|
const ONRAMP_ROUTER_ENDPOINT = "/v2/bridge/api";
|
|
46
46
|
/**
|
|
@@ -50,7 +50,7 @@ exports.markUnpayable = markUnpayable;
|
|
|
50
50
|
exports.markDebitCardUnpayable = markDebitCardUnpayable;
|
|
51
51
|
exports.PayableAccountsClient = __importStar(require("./payableAccountsServiceClient"));
|
|
52
52
|
const restClient_1 = require("../restClient");
|
|
53
|
-
const baseClient = (0, restClient_1.
|
|
53
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("PAYABLE_ACCOUNTS_SERVICE_API_IAM_URL", "/payable-accounts-v2/api");
|
|
54
54
|
const PAYABLE_ACCOUNTS_ENDPOINT = "/payable-accounts";
|
|
55
55
|
// The Hono ServiceApi (`/api/{proxy+}`) is mapped on the shared gateway domain
|
|
56
56
|
// under the `payable-accounts-v2` key (serverless.yaml HTTPAPIMapping).
|
|
@@ -37,7 +37,7 @@ exports.PaymentAddressClient = void 0;
|
|
|
37
37
|
exports.initializePaymentAddresses = initializePaymentAddresses;
|
|
38
38
|
exports.PaymentAddressClient = __importStar(require("./paymentAddressServiceClient"));
|
|
39
39
|
const restClient_1 = require("../restClient");
|
|
40
|
-
const baseClient = (0, restClient_1.
|
|
40
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("PAYMENT_ADDRESS_SERVICE_API_IAM_URL", "/payment-addresses-v2/api");
|
|
41
41
|
// Payment-addresses' Hono ServiceApi, reached through the gateway's
|
|
42
42
|
// /payment-addresses-v2 base path.
|
|
43
43
|
const PAYMENT_ADDRESSES_API_ENDPOINT = "/payment-addresses-v2/api";
|
|
@@ -54,7 +54,7 @@ exports.getVoidedLiabilities = getVoidedLiabilities;
|
|
|
54
54
|
exports.getUnrefundedFailedRtpSum = getUnrefundedFailedRtpSum;
|
|
55
55
|
exports.PaymentsClient = __importStar(require("./paymentsClient"));
|
|
56
56
|
const restClient_1 = require("../restClient");
|
|
57
|
-
const baseClient = (0, restClient_1.
|
|
57
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("PAYMENTS_SERVICE_API_IAM_URL", "/v2/liabilities/api");
|
|
58
58
|
const PAYMENTS_ENDPOINT = "/liabilities";
|
|
59
59
|
const PAYMENTS_ROUTER_ENDPOINT = "/v2/liabilities/api";
|
|
60
60
|
/**
|
|
@@ -42,7 +42,7 @@ exports.executeRainAdminChange = executeRainAdminChange;
|
|
|
42
42
|
exports.getTreasuryBalances = getTreasuryBalances;
|
|
43
43
|
exports.PayoutsClient = __importStar(require("./payoutsServiceClient"));
|
|
44
44
|
const restClient_1 = require("../restClient");
|
|
45
|
-
const baseClient = (0, restClient_1.
|
|
45
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("PAYOUTS_SERVICE_API_IAM_URL", "/v2/bridgebot/api");
|
|
46
46
|
const PAYOUTS_ENDPOINT = "/bridgebot";
|
|
47
47
|
// Bridgebot's Hono /api surface, reached through the same gateway host via the
|
|
48
48
|
// /v2/bridgebot base path (the bare /bridgebot base path maps to bridgebot's
|
|
@@ -69,12 +69,15 @@ const platformClient = axios_1.default.create({
|
|
|
69
69
|
});
|
|
70
70
|
platformClient.interceptors.request.use(iamUrl
|
|
71
71
|
? (0, sigv4_1.createSigV4Interceptor)(iamUrl)
|
|
72
|
-
:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
: // DEPRECATED: gateway + shared `service_` bearer, kept because platform is
|
|
73
|
+
// a twinless callee. The service-auth-secret funeral deletes
|
|
74
|
+
// `/{stage}/service-client/auth-secret` and getServiceCredentials with it.
|
|
75
|
+
(0, axios_token_interceptor_1.default)({
|
|
76
|
+
getToken: axios_token_interceptor_1.default.tokenCache(credentials_1.getServiceCredentials, {
|
|
77
|
+
getMaxAge: () => EXPIRATION_BUFFER_MS,
|
|
78
|
+
}),
|
|
79
|
+
headerFormatter: (res) => `Bearer ${res.access_token}`,
|
|
80
|
+
}));
|
|
78
81
|
const BILLPAY_ENDPOINT = "/v1/billpay";
|
|
79
82
|
async function validateBill(request) {
|
|
80
83
|
return platformClient
|
|
@@ -1,57 +1,58 @@
|
|
|
1
1
|
export * as RainClient from "./rainServiceClient";
|
|
2
2
|
import { VirtualCardStatus } from "../payableAccounts/types";
|
|
3
|
+
import { ApiFailure, ApiResponse } from "../types";
|
|
3
4
|
import { ApplicationStatus, CardDetailsResponse, CardOrderStatus, CardType, CreateRainApplicationInput, OrderPhysicalCardInput, OrderPhysicalCardResponse, RainCard, RainContract, RainUser, ShippingDetails, WithdrawalSignature } from "./types";
|
|
4
5
|
export declare const CREATE_CARD_APPLICATION_TIMEOUT_MS = 28000;
|
|
5
|
-
export declare function createCardApplication(userId: string, input: CreateRainApplicationInput): Promise<
|
|
6
|
+
export declare function createCardApplication(userId: string, input: CreateRainApplicationInput): Promise<ApiFailure | import("../types").ApiSuccess<RainUser>>;
|
|
6
7
|
export declare function getUserDepositAddress({ userId, network, }: {
|
|
7
8
|
userId: string;
|
|
8
9
|
network: string;
|
|
9
|
-
}): Promise<
|
|
10
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<RainContract>>;
|
|
10
11
|
export declare function validateContractAddress(input: {
|
|
11
12
|
userId: string;
|
|
12
13
|
network: string;
|
|
13
14
|
contractAddress: string;
|
|
14
|
-
}): Promise<
|
|
15
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<boolean>>;
|
|
15
16
|
export declare function createRainCard({ userId, nickname, type, shipping, }: {
|
|
16
17
|
userId: string;
|
|
17
18
|
nickname?: string;
|
|
18
19
|
type?: CardType;
|
|
19
20
|
shipping?: ShippingDetails;
|
|
20
|
-
}): Promise<
|
|
21
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<RainCard>>;
|
|
21
22
|
export declare function updateCardStatus({ userId, status, cardExternalId, }: {
|
|
22
23
|
userId: string;
|
|
23
24
|
status: VirtualCardStatus;
|
|
24
25
|
cardExternalId: string;
|
|
25
|
-
}): Promise<
|
|
26
|
+
}): Promise<ApiResponse<RainCard>>;
|
|
26
27
|
export declare function activatePhysicalCard({ userId, accountId, expirationMonth, expirationYear, }: {
|
|
27
28
|
userId: string;
|
|
28
29
|
accountId: string;
|
|
29
30
|
expirationMonth: string;
|
|
30
31
|
expirationYear: string;
|
|
31
|
-
}): Promise<
|
|
32
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<RainCard>>;
|
|
32
33
|
export declare function getLiveBalance({ userId }: {
|
|
33
34
|
userId: string;
|
|
34
|
-
}): Promise<
|
|
35
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<{
|
|
35
36
|
balance: number;
|
|
36
37
|
}>>;
|
|
37
38
|
export declare function getCardDetails({ userId, cardId }: {
|
|
38
39
|
userId: string;
|
|
39
40
|
cardId: string;
|
|
40
|
-
}): Promise<
|
|
41
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<CardDetailsResponse>>;
|
|
41
42
|
export declare function requestWithdrawalSignature({ userId, network, amount, }: {
|
|
42
43
|
userId: string;
|
|
43
44
|
network: string;
|
|
44
45
|
amount: string;
|
|
45
|
-
}): Promise<
|
|
46
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<WithdrawalSignature>>;
|
|
46
47
|
export declare function adminGetUserInfo({ userId }: {
|
|
47
48
|
userId: string;
|
|
48
|
-
}): Promise<
|
|
49
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<{
|
|
49
50
|
id: string;
|
|
50
51
|
externalId: string;
|
|
51
52
|
applicationStatus: ApplicationStatus;
|
|
52
53
|
depositAddress: string;
|
|
53
54
|
}>>;
|
|
54
|
-
export declare function orderPhysicalCard(input: OrderPhysicalCardInput): Promise<
|
|
55
|
+
export declare function orderPhysicalCard(input: OrderPhysicalCardInput): Promise<ApiFailure | import("../types").ApiSuccess<OrderPhysicalCardResponse>>;
|
|
55
56
|
export interface PendingCardOrder {
|
|
56
57
|
id: string;
|
|
57
58
|
userId: string;
|
|
@@ -74,7 +75,7 @@ export interface PendingCardOrder {
|
|
|
74
75
|
replacementFor?: string;
|
|
75
76
|
replacementForCard?: string;
|
|
76
77
|
}
|
|
77
|
-
export declare function getPendingCardOrder(userId: string): Promise<
|
|
78
|
+
export declare function getPendingCardOrder(userId: string): Promise<ApiFailure | import("../types").ApiSuccess<PendingCardOrder | null>>;
|
|
78
79
|
type CashbackSummary = {
|
|
79
80
|
enabled: boolean;
|
|
80
81
|
activeSpree: {
|
|
@@ -90,7 +91,7 @@ type CashbackSummary = {
|
|
|
90
91
|
nextSpreeMinPayment: number | null;
|
|
91
92
|
};
|
|
92
93
|
};
|
|
93
|
-
export declare function getCardUser(userId: string): Promise<
|
|
94
|
+
export declare function getCardUser(userId: string): Promise<ApiFailure | import("../types").ApiSuccess<{
|
|
94
95
|
id: string | undefined;
|
|
95
96
|
status: ApplicationStatus;
|
|
96
97
|
applicationCompletionLink: string | undefined;
|
|
@@ -48,8 +48,10 @@ exports.orderPhysicalCard = orderPhysicalCard;
|
|
|
48
48
|
exports.getPendingCardOrder = getPendingCardOrder;
|
|
49
49
|
exports.getCardUser = getCardUser;
|
|
50
50
|
exports.RainClient = __importStar(require("./rainServiceClient"));
|
|
51
|
+
const types_1 = require("../payableAccounts/types");
|
|
51
52
|
const restClient_1 = require("../restClient");
|
|
52
|
-
const
|
|
53
|
+
const types_2 = require("./types");
|
|
54
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("RAIN_SERVICE_API_IAM_URL", "/rain-v2/api");
|
|
53
55
|
const RAIN_ENDPOINT = "/rain-v2";
|
|
54
56
|
// Rain's CreateRainApplication submits the application and uploads the ID
|
|
55
57
|
// documents, which takes 10-18s in production. The 10s DEFAULT_TIMEOUT_MS
|
|
@@ -90,12 +92,53 @@ async function createRainCard({ userId, nickname, type, shipping, }) {
|
|
|
90
92
|
})
|
|
91
93
|
.then((res) => res.data);
|
|
92
94
|
}
|
|
95
|
+
// The statuses `PATCH /api/cards/:cardId/status` accepts. The legacy route
|
|
96
|
+
// also took NotActivated, which no caller sends and Rain cannot set.
|
|
97
|
+
const CARD_STATUS_BY_VIRTUAL_CARD_STATUS = {
|
|
98
|
+
[types_1.VirtualCardStatus.Active]: types_2.CardStatus.Active,
|
|
99
|
+
[types_1.VirtualCardStatus.Frozen]: types_2.CardStatus.Locked,
|
|
100
|
+
[types_1.VirtualCardStatus.Cancelled]: types_2.CardStatus.Canceled,
|
|
101
|
+
};
|
|
102
|
+
// `/api/cards/users/:userId` caps a page at 100 cards.
|
|
103
|
+
const USER_CARDS_PAGE_LIMIT = 100;
|
|
104
|
+
function failure(message) {
|
|
105
|
+
return { status: "failure", error: { message } };
|
|
106
|
+
}
|
|
107
|
+
// Rain's card list is the only `/api` route that maps a card's externalId to
|
|
108
|
+
// its accountId; walk its pages until the card turns up.
|
|
109
|
+
async function findCardAccountId(userId, cardExternalId) {
|
|
110
|
+
let cursor;
|
|
111
|
+
do {
|
|
112
|
+
const page = await baseClient
|
|
113
|
+
.get(`${RAIN_ENDPOINT}/api/cards/users/${userId}`, { params: { limit: USER_CARDS_PAGE_LIMIT, cursor } })
|
|
114
|
+
.then((res) => res.data);
|
|
115
|
+
if (page.status === "failure")
|
|
116
|
+
return page;
|
|
117
|
+
const card = page.data.data.find((c) => c.externalId === cardExternalId);
|
|
118
|
+
if (card) {
|
|
119
|
+
return card.accountId
|
|
120
|
+
? { status: "success", data: card.accountId }
|
|
121
|
+
: failure("Card has no payable account");
|
|
122
|
+
}
|
|
123
|
+
cursor = page.data.nextCursor;
|
|
124
|
+
} while (cursor);
|
|
125
|
+
return failure("Card not found");
|
|
126
|
+
}
|
|
127
|
+
// `/api/cards/:cardId/status` finds the card by its payable accountId, where
|
|
128
|
+
// the legacy `/card/status` took Rain's card externalId, and takes Rain's
|
|
129
|
+
// status values. Callers still pass the externalId and a VirtualCardStatus, so
|
|
130
|
+
// the wrapper resolves the accountId and maps the status first.
|
|
93
131
|
async function updateCardStatus({ userId, status, cardExternalId, }) {
|
|
132
|
+
const cardStatus = CARD_STATUS_BY_VIRTUAL_CARD_STATUS[status];
|
|
133
|
+
if (!cardStatus)
|
|
134
|
+
return failure(`Unsupported card status: ${status}`);
|
|
135
|
+
const accountId = await findCardAccountId(userId, cardExternalId);
|
|
136
|
+
if (accountId.status === "failure")
|
|
137
|
+
return accountId;
|
|
94
138
|
return baseClient
|
|
95
|
-
.
|
|
139
|
+
.patch(`${RAIN_ENDPOINT}/api/cards/${accountId.data}/status`, {
|
|
96
140
|
userId,
|
|
97
|
-
status,
|
|
98
|
-
cardExternalId,
|
|
141
|
+
status: cardStatus,
|
|
99
142
|
})
|
|
100
143
|
.then((res) => res.data);
|
|
101
144
|
}
|
package/lib/restClient.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
type IamUrlEnvVar = `${string}_SERVICE_API_IAM_URL`;
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Client for a module whose callee has an IAM twin. Requests under
|
|
4
|
+
* `twinGatewayPrefix` go SigV4-signed to the twin at `process.env[iamUrlEnvVar]`;
|
|
5
|
+
* v1/other paths stay on the gateway. With the env var unset every request
|
|
6
|
+
* fails fast with MissingIamTwinError instead of minting a `service_` token.
|
|
5
7
|
*/
|
|
6
|
-
export declare const
|
|
8
|
+
export declare const getTwinRestClient: (iamUrlEnvVar: IamUrlEnvVar, twinGatewayPrefix: string) => import("axios").AxiosInstance;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Gateway + shared `service_` bearer, for the twinless callees
|
|
11
|
+
* (exchange-rates, unblock) only. The service-auth-secret funeral deletes
|
|
12
|
+
* `/{stage}/service-client/auth-secret` and removes this path; don't add callers.
|
|
13
|
+
*/
|
|
14
|
+
export declare const getLegacyRestClient: () => import("axios").AxiosInstance;
|
|
15
|
+
export {};
|
package/lib/restClient.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getLegacyRestClient = exports.getTwinRestClient = void 0;
|
|
4
4
|
const serviceClient_1 = require("./serviceClient");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Client for a module whose callee has an IAM twin. Requests under
|
|
7
|
+
* `twinGatewayPrefix` go SigV4-signed to the twin at `process.env[iamUrlEnvVar]`;
|
|
8
|
+
* v1/other paths stay on the gateway. With the env var unset every request
|
|
9
|
+
* fails fast with MissingIamTwinError instead of minting a `service_` token.
|
|
9
10
|
*/
|
|
10
|
-
const
|
|
11
|
-
exports.
|
|
11
|
+
const getTwinRestClient = (iamUrlEnvVar, twinGatewayPrefix) => (0, serviceClient_1.createDualClient)({}, twinGatewayPrefix, process.env[iamUrlEnvVar], iamUrlEnvVar);
|
|
12
|
+
exports.getTwinRestClient = getTwinRestClient;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Gateway + shared `service_` bearer, for the twinless callees
|
|
15
|
+
* (exchange-rates, unblock) only. The service-auth-secret funeral deletes
|
|
16
|
+
* `/{stage}/service-client/auth-secret` and removes this path; don't add callers.
|
|
17
|
+
*/
|
|
18
|
+
const getLegacyRestClient = () => serviceClient_1.baseClient;
|
|
19
|
+
exports.getLegacyRestClient = getLegacyRestClient;
|
package/lib/serviceClient.d.ts
CHANGED
|
@@ -2,6 +2,15 @@ import { AxiosRequestConfig } from "axios";
|
|
|
2
2
|
export declare const DEFAULT_TIMEOUT_MS = 10000;
|
|
3
3
|
export declare const createServiceClient: (config: AxiosRequestConfig, iamUrl?: string) => import("axios").AxiosInstance;
|
|
4
4
|
export declare const baseClient: import("axios").AxiosInstance;
|
|
5
|
+
/**
|
|
6
|
+
* Thrown, before any token is minted, by the client of a twin-backed service
|
|
7
|
+
* whose IAM twin URL is unset. The shared `service_` bearer is retired for
|
|
8
|
+
* these services: the caller must set the env var, not fall back.
|
|
9
|
+
*/
|
|
10
|
+
export declare class MissingIamTwinError extends Error {
|
|
11
|
+
readonly iamUrlEnvVar: string;
|
|
12
|
+
constructor(iamUrlEnvVar: string);
|
|
13
|
+
}
|
|
5
14
|
/**
|
|
6
15
|
* Dual-mode client for the ServiceApi SigV4 migration: requests whose path
|
|
7
16
|
* starts with `twinGatewayPrefix` (e.g. "/v2/users/api") are rewritten onto the
|
|
@@ -9,7 +18,10 @@ export declare const baseClient: import("axios").AxiosInstance;
|
|
|
9
18
|
* every other path keeps the legacy gateway + `service_` token. This is what
|
|
10
19
|
* lets modules mixing v1 REST and v2 `/api` calls migrate per-route.
|
|
11
20
|
*
|
|
21
|
+
* Without `iamUrl` every request fails fast with MissingIamTwinError: a
|
|
22
|
+
* twin-backed service no longer falls back to gateway + `service_` bearer.
|
|
23
|
+
*
|
|
12
24
|
* Interceptor execution order (axios runs request interceptors last-registered
|
|
13
25
|
* first): rewrite → credential attach → trace → sigv4.
|
|
14
26
|
*/
|
|
15
|
-
export declare const createDualClient: (axiosConfig: AxiosRequestConfig, twinGatewayPrefix: string, iamUrl
|
|
27
|
+
export declare const createDualClient: (axiosConfig: AxiosRequestConfig, twinGatewayPrefix: string, iamUrl: string | undefined, iamUrlEnvVar: string) => import("axios").AxiosInstance;
|
package/lib/serviceClient.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.createDualClient = exports.baseClient = exports.createServiceClient = exports.DEFAULT_TIMEOUT_MS = void 0;
|
|
6
|
+
exports.createDualClient = exports.MissingIamTwinError = exports.baseClient = exports.createServiceClient = exports.DEFAULT_TIMEOUT_MS = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
// @ts-expect-error no type declarations for axios-token-interceptor
|
|
9
9
|
const axios_token_interceptor_1 = __importDefault(require("axios-token-interceptor"));
|
|
@@ -75,7 +75,13 @@ const createServiceClient = (config, iamUrl) => {
|
|
|
75
75
|
...config,
|
|
76
76
|
...(iamUrl ? { baseURL: iamUrl } : {}),
|
|
77
77
|
});
|
|
78
|
-
serviceClient.interceptors.request.use(iamUrl
|
|
78
|
+
serviceClient.interceptors.request.use(iamUrl
|
|
79
|
+
? (0, sigv4_1.createSigV4Interceptor)(iamUrl)
|
|
80
|
+
: // DEPRECATED: gateway + shared `service_` bearer. Kept only for the
|
|
81
|
+
// twinless callees (exchange-rates, unblock); the service-auth-secret
|
|
82
|
+
// funeral deletes `/{stage}/service-client/auth-secret` and
|
|
83
|
+
// getServiceCredentials with it.
|
|
84
|
+
interceptor(axios_token_interceptor_1.default, credentials_1.getServiceCredentials));
|
|
79
85
|
serviceClient.interceptors.request.use(traceInterceptor);
|
|
80
86
|
serviceClient.interceptors.response.use((response) => response, retryInterceptor(serviceClient));
|
|
81
87
|
return serviceClient;
|
|
@@ -84,6 +90,32 @@ exports.createServiceClient = createServiceClient;
|
|
|
84
90
|
exports.baseClient = (0, exports.createServiceClient)({
|
|
85
91
|
baseURL: config_1.config.baseEndpoint,
|
|
86
92
|
});
|
|
93
|
+
/**
|
|
94
|
+
* Thrown, before any token is minted, by the client of a twin-backed service
|
|
95
|
+
* whose IAM twin URL is unset. The shared `service_` bearer is retired for
|
|
96
|
+
* these services: the caller must set the env var, not fall back.
|
|
97
|
+
*/
|
|
98
|
+
class MissingIamTwinError extends Error {
|
|
99
|
+
constructor(iamUrlEnvVar) {
|
|
100
|
+
const service = iamUrlEnvVar
|
|
101
|
+
.replace(/_SERVICE_API_IAM_URL$/, "")
|
|
102
|
+
.toLowerCase()
|
|
103
|
+
.replace(/_/g, "-");
|
|
104
|
+
super(`no IAM twin configured for ${service} — set ${iamUrlEnvVar}`);
|
|
105
|
+
this.iamUrlEnvVar = iamUrlEnvVar;
|
|
106
|
+
this.name = "MissingIamTwinError";
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.MissingIamTwinError = MissingIamTwinError;
|
|
110
|
+
// Fails every request at call time, never at import: the package index loads
|
|
111
|
+
// every module, and a consumer only needs the env vars of the services it calls.
|
|
112
|
+
const createMissingTwinClient = (iamUrlEnvVar) => {
|
|
113
|
+
const client = axios_1.default.create();
|
|
114
|
+
client.interceptors.request.use(() => {
|
|
115
|
+
throw new MissingIamTwinError(iamUrlEnvVar);
|
|
116
|
+
});
|
|
117
|
+
return client;
|
|
118
|
+
};
|
|
87
119
|
/**
|
|
88
120
|
* Dual-mode client for the ServiceApi SigV4 migration: requests whose path
|
|
89
121
|
* starts with `twinGatewayPrefix` (e.g. "/v2/users/api") are rewritten onto the
|
|
@@ -91,17 +123,23 @@ exports.baseClient = (0, exports.createServiceClient)({
|
|
|
91
123
|
* every other path keeps the legacy gateway + `service_` token. This is what
|
|
92
124
|
* lets modules mixing v1 REST and v2 `/api` calls migrate per-route.
|
|
93
125
|
*
|
|
126
|
+
* Without `iamUrl` every request fails fast with MissingIamTwinError: a
|
|
127
|
+
* twin-backed service no longer falls back to gateway + `service_` bearer.
|
|
128
|
+
*
|
|
94
129
|
* Interceptor execution order (axios runs request interceptors last-registered
|
|
95
130
|
* first): rewrite → credential attach → trace → sigv4.
|
|
96
131
|
*/
|
|
97
|
-
const createDualClient = (axiosConfig, twinGatewayPrefix, iamUrl) => {
|
|
132
|
+
const createDualClient = (axiosConfig, twinGatewayPrefix, iamUrl, iamUrlEnvVar) => {
|
|
98
133
|
if (!iamUrl)
|
|
99
|
-
return (
|
|
134
|
+
return createMissingTwinClient(iamUrlEnvVar);
|
|
100
135
|
const serviceClient = axios_1.default.create({
|
|
101
136
|
timeout: exports.DEFAULT_TIMEOUT_MS,
|
|
102
137
|
baseURL: config_1.config.baseEndpoint,
|
|
103
138
|
...axiosConfig,
|
|
104
139
|
});
|
|
140
|
+
// DEPRECATED: the v1 methods of mixed modules still ride gateway + `service_`
|
|
141
|
+
// bearer. Each must move to its `/api` equivalent before the
|
|
142
|
+
// service-auth-secret funeral deletes the secret.
|
|
105
143
|
const tokenAttach = interceptor(axios_token_interceptor_1.default, credentials_1.getServiceCredentials);
|
|
106
144
|
// Runs last: signs only requests the rewrite pointed at the twin.
|
|
107
145
|
serviceClient.interceptors.request.use((0, sigv4_1.createSigV4Interceptor)(iamUrl));
|
|
@@ -42,7 +42,7 @@ 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.
|
|
45
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("TRANSACTIONS_SERVICE_API_IAM_URL", "/v2/transactions/api");
|
|
46
46
|
const TRANSACTIONS_ENDPOINT = "/transactions";
|
|
47
47
|
// Transactions' Hono ServiceApi, reached through the gateway's /v2/transactions
|
|
48
48
|
// base path (the bare /transactions base path maps to the legacy REST routes).
|
|
@@ -42,7 +42,7 @@ exports.getExternalPayments = getExternalPayments;
|
|
|
42
42
|
exports.getBlockchainTransactions = getBlockchainTransactions;
|
|
43
43
|
exports.UnblockClient = __importStar(require("./unblockServiceClient"));
|
|
44
44
|
const restClient_1 = require("../restClient");
|
|
45
|
-
const baseClient = (0, restClient_1.
|
|
45
|
+
const baseClient = (0, restClient_1.getLegacyRestClient)();
|
|
46
46
|
const UNBLOCK_ENDPOINT = "/unblock";
|
|
47
47
|
async function requestOTP(userId) {
|
|
48
48
|
return baseClient
|
|
@@ -47,7 +47,7 @@ exports.getIntegrator = getIntegrator;
|
|
|
47
47
|
exports.getIntegratorByCode = getIntegratorByCode;
|
|
48
48
|
exports.UsersClient = __importStar(require("./usersServiceClient"));
|
|
49
49
|
const restClient_1 = require("../restClient");
|
|
50
|
-
const baseClient = (0, restClient_1.
|
|
50
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("USERS_SERVICE_API_IAM_URL", "/v2/users/api");
|
|
51
51
|
const NEW_USER_ENDPOINT = "/v2/users/api";
|
|
52
52
|
async function getActiveUsers() {
|
|
53
53
|
return baseClient
|
|
@@ -43,7 +43,7 @@ exports.activateVirtualCardModule = activateVirtualCardModule;
|
|
|
43
43
|
exports.deactivateBillsModule = deactivateBillsModule;
|
|
44
44
|
exports.VerificationClient = __importStar(require("./verificationServiceClient"));
|
|
45
45
|
const restClient_1 = require("../restClient");
|
|
46
|
-
const baseClient = (0, restClient_1.
|
|
46
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("VERIFICATION_SERVICE_API_IAM_URL", "/v2/verification/api");
|
|
47
47
|
const VERIFICATION_ENDPOINT = "/verification";
|
|
48
48
|
const VERIFICATION_API_ENDPOINT = "/v2/verification/api";
|
|
49
49
|
/**
|
|
@@ -51,7 +51,7 @@ exports.listListedKaminoVaultIds = listListedKaminoVaultIds;
|
|
|
51
51
|
exports.Web3Client = __importStar(require("./web3ServiceClient"));
|
|
52
52
|
const axios_1 = __importDefault(require("axios"));
|
|
53
53
|
const restClient_1 = require("../restClient");
|
|
54
|
-
const baseClient = (0, restClient_1.
|
|
54
|
+
const baseClient = (0, restClient_1.getTwinRestClient)("WEB3_SERVICE_API_IAM_URL", "/v2/web3/api");
|
|
55
55
|
const WEB3_ENDPOINT = "/web3";
|
|
56
56
|
const WEB3_V2_ENDPOINT = "/v2/web3/api";
|
|
57
57
|
/**
|