@spritz-finance/service-client 0.31.0 → 0.32.1
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 +13 -3
- package/lib/bridge/bridgeServiceClient.js +1 -1
- package/lib/checkbook/checkbookServiceClient.js +1 -1
- package/lib/config.js +5 -4
- package/lib/features/featuresServiceClient.js +1 -1
- package/lib/features/types.d.ts +1 -0
- package/lib/features/types.js +1 -0
- package/lib/growth/growthServiceClient.js +1 -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/rain/rainServiceClient.js +1 -1
- package/lib/restClient.d.ts +6 -2
- package/lib/restClient.js +6 -2
- package/lib/serviceClient.d.ts +11 -0
- package/lib/serviceClient.js +86 -40
- 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
|
@@ -14,6 +14,14 @@ await UsersClient.getUserById("user-id");
|
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
Each namespace opts in independently, including namespaces that share a backend.
|
|
17
|
+
|
|
18
|
+
**Per-request routing:** when a service is opted in, only calls under its
|
|
19
|
+
`/v2/<svc>/api` gateway prefix are signed and sent to the IAM twin (the prefix
|
|
20
|
+
is stripped to `/api/...`). Calls to legacy v1 REST routes in the same
|
|
21
|
+
namespace stay on the gateway with the `service_` token — so mixed modules
|
|
22
|
+
migrate route by route, and v1-only namespaces (transactions, unblock,
|
|
23
|
+
verification's v1 paths, ...) are unaffected until their callers move to the
|
|
24
|
+
`/api` equivalents.
|
|
17
25
|
Set these variables to the corresponding service's IAM Function URL:
|
|
18
26
|
|
|
19
27
|
| Client | Environment variable |
|
|
@@ -38,9 +46,11 @@ Set these variables to the corresponding service's IAM Function URL:
|
|
|
38
46
|
| VerificationClient | `VERIFICATION_SERVICE_API_IAM_URL` |
|
|
39
47
|
| Web3Client | `WEB3_SERVICE_API_IAM_URL` |
|
|
40
48
|
|
|
41
|
-
The IAM URL
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
The IAM URL becomes the base URL only for calls under the service's
|
|
50
|
+
`/v2/<svc>/api` gateway prefix; the prefix is stripped to `/api/...`, which is
|
|
51
|
+
what the Function URL twin serves. Calls to legacy v1 REST routes in the same
|
|
52
|
+
namespace (e.g. `/liabilities/...`, `/verification/...`) keep the gateway base
|
|
53
|
+
URL and the `service_` token unchanged. CheckbookClient and PaymentsClient target liabilities
|
|
44
54
|
routes; FeaturesClient targets users routes; BridgeClient and OnrampClient target
|
|
45
55
|
bridge routes. Their variables can point at the same backend URL.
|
|
46
56
|
|
|
@@ -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.getRestClient)(process.env.BRIDGE_SERVICE_API_IAM_URL);
|
|
46
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.BRIDGE_SERVICE_API_IAM_URL, "/v2/bridge/api");
|
|
47
47
|
const ONRAMP_ENDPOINT = "/bridge";
|
|
48
48
|
const ONRAMP_ROUTER_ENDPOINT = "/v2/bridge/api";
|
|
49
49
|
async function getTransferHashes(externalPaymentIds) {
|
|
@@ -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.getRestClient)(process.env.CHECKBOOK_SERVICE_API_IAM_URL);
|
|
42
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.CHECKBOOK_SERVICE_API_IAM_URL, "/v2/liabilities/api");
|
|
43
43
|
const CHECKBOOK_ENDPOINT = "/liabilities";
|
|
44
44
|
async function triggerBatch({ config, configs, reserve, currency, }) {
|
|
45
45
|
return baseClient
|
package/lib/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a, _b, _c, _d;
|
|
2
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.config = void 0;
|
|
5
5
|
const config_1 = require("@spritz-finance/config");
|
|
@@ -8,6 +8,7 @@ const envConfigs = {
|
|
|
8
8
|
env: (_b = (_a = process.env.STAGE) !== null && _a !== void 0 ? _a : process.env.NODE_ENV) !== null && _b !== void 0 ? _b : "dev",
|
|
9
9
|
region: (_c = process.env.REGION) !== null && _c !== void 0 ? _c : "us-east-1",
|
|
10
10
|
serviceClientKeyArn: (_d = process.env.SERVICE_CLIENT_KEY_ARN) !== null && _d !== void 0 ? _d : "",
|
|
11
|
+
// Overridable for local runs and tests; the stage default otherwise.
|
|
11
12
|
baseEndpoint: "https://api-dev.spritz.finance",
|
|
12
13
|
authEndpoint: "https://auth-dev.spritz.finance/oauth2/token",
|
|
13
14
|
graphEndpoint: "https://api-dev.spritz.finance/graphql",
|
|
@@ -26,7 +27,7 @@ const envConfigs = {
|
|
|
26
27
|
test: {
|
|
27
28
|
env: "staging",
|
|
28
29
|
authEndpoint: "https://auth-staging.spritz.finance/oauth2/token",
|
|
29
|
-
baseEndpoint: "https://api-staging.spritz.finance",
|
|
30
|
+
baseEndpoint: (_e = process.env.SERVICE_CLIENT_BASE_ENDPOINT) !== null && _e !== void 0 ? _e : "https://api-staging.spritz.finance",
|
|
30
31
|
graphEndpoint: "https://api-staging.spritz.finance/router/graph",
|
|
31
32
|
verificationServiceEndpoint: "https://api-staging.spritz.finance/verification",
|
|
32
33
|
transactionsServiceEndpoint: "https://api-staging.spritz.finance/transactions",
|
|
@@ -40,7 +41,7 @@ const envConfigs = {
|
|
|
40
41
|
platformEndpoint: "http://internal-InternalApiLoad-kzfntbsu-1503066598.us-east-1.elb.amazonaws.com:50051",
|
|
41
42
|
},
|
|
42
43
|
staging: {
|
|
43
|
-
baseEndpoint: "https://api-staging.spritz.finance",
|
|
44
|
+
baseEndpoint: (_f = process.env.SERVICE_CLIENT_BASE_ENDPOINT) !== null && _f !== void 0 ? _f : "https://api-staging.spritz.finance",
|
|
44
45
|
authEndpoint: "https://auth-staging.spritz.finance/oauth2/token",
|
|
45
46
|
graphEndpoint: "https://api-staging.spritz.finance/router/graph",
|
|
46
47
|
verificationServiceEndpoint: "https://api-staging.spritz.finance/verification",
|
|
@@ -56,7 +57,7 @@ const envConfigs = {
|
|
|
56
57
|
platformEndpoint: "http://internal-InternalApiLoad-kzfntbsu-1503066598.us-east-1.elb.amazonaws.com:50051",
|
|
57
58
|
},
|
|
58
59
|
production: {
|
|
59
|
-
baseEndpoint: "https://api.spritz.finance",
|
|
60
|
+
baseEndpoint: (_g = process.env.SERVICE_CLIENT_BASE_ENDPOINT) !== null && _g !== void 0 ? _g : "https://api.spritz.finance",
|
|
60
61
|
authEndpoint: "https://auth.spritz.finance/oauth2/token",
|
|
61
62
|
graphEndpoint: "https://api.spritz.finance/router/graph",
|
|
62
63
|
verificationServiceEndpoint: "https://api.spritz.finance/verification",
|
|
@@ -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.getRestClient)(process.env.FEATURES_SERVICE_API_IAM_URL);
|
|
46
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.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) {
|
package/lib/features/types.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ export declare enum FeatureFlag {
|
|
|
52
52
|
BinanceBridgeEnabled = "binanceBridge.enabled",
|
|
53
53
|
CheckbookAutomatedWires = "checkbook.automatedWires",
|
|
54
54
|
CircleFundTransfers = "circle.fundTransfers",
|
|
55
|
+
SolanaOnrampPrefund = "solana.onrampPrefund",
|
|
55
56
|
FalconXFundTransfers = "falconx.fundTransfers",
|
|
56
57
|
CoinbaseFundTransfers = "coinbase.fundTransfers",
|
|
57
58
|
RunCheckbookBatch = "checkbook.runBatch",
|
package/lib/features/types.js
CHANGED
|
@@ -55,6 +55,7 @@ var FeatureFlag;
|
|
|
55
55
|
FeatureFlag["BinanceBridgeEnabled"] = "binanceBridge.enabled";
|
|
56
56
|
FeatureFlag["CheckbookAutomatedWires"] = "checkbook.automatedWires";
|
|
57
57
|
FeatureFlag["CircleFundTransfers"] = "circle.fundTransfers";
|
|
58
|
+
FeatureFlag["SolanaOnrampPrefund"] = "solana.onrampPrefund";
|
|
58
59
|
FeatureFlag["FalconXFundTransfers"] = "falconx.fundTransfers";
|
|
59
60
|
FeatureFlag["CoinbaseFundTransfers"] = "coinbase.fundTransfers";
|
|
60
61
|
FeatureFlag["RunCheckbookBatch"] = "checkbook.runBatch";
|
|
@@ -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.getRestClient)(process.env.GROWTH_SERVICE_API_IAM_URL);
|
|
45
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.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
|
/**
|
|
@@ -55,7 +55,7 @@ exports.getDirectPayment = getDirectPayment;
|
|
|
55
55
|
exports.issueRefundCredit = issueRefundCredit;
|
|
56
56
|
exports.LiabilitiesClient = __importStar(require("./liabilitiesServiceClient"));
|
|
57
57
|
const restClient_1 = require("../restClient");
|
|
58
|
-
const baseClient = (0, restClient_1.getRestClient)(process.env.LIABILITIES_SERVICE_API_IAM_URL);
|
|
58
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.LIABILITIES_SERVICE_API_IAM_URL, "/v2/liabilities/api");
|
|
59
59
|
const LIABILITIES_ENDPOINT = "/liabilities";
|
|
60
60
|
async function getRewardTransaction(transactionId) {
|
|
61
61
|
return baseClient
|
|
@@ -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.getRestClient)(process.env.NOTIFICATIONS_SERVICE_API_IAM_URL);
|
|
40
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.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.getRestClient)(process.env.ONRAMP_SERVICE_API_IAM_URL);
|
|
43
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.ONRAMP_SERVICE_API_IAM_URL, "/v2/bridge/api");
|
|
44
44
|
const ONRAMP_ENDPOINT = "/bridge";
|
|
45
45
|
async function syncTransfer(input) {
|
|
46
46
|
return baseClient
|
|
@@ -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.getRestClient)(process.env.PAYABLE_ACCOUNTS_SERVICE_API_IAM_URL);
|
|
53
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.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.getRestClient)(process.env.PAYMENT_ADDRESS_SERVICE_API_IAM_URL);
|
|
40
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.PAYMENT_ADDRESS_SERVICE_API_IAM_URL, "/payment-addresses-v2/api");
|
|
41
41
|
const PAYABLE_ACCOUNTS_ENDPOINT = "/payment-addresses";
|
|
42
42
|
async function initializePaymentAddresses(body) {
|
|
43
43
|
return baseClient
|
|
@@ -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.getRestClient)(process.env.PAYMENTS_SERVICE_API_IAM_URL);
|
|
57
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.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
|
async function createDirectPayment(args) {
|
|
@@ -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.getRestClient)(process.env.PAYOUTS_SERVICE_API_IAM_URL);
|
|
45
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.PAYOUTS_SERVICE_API_IAM_URL, "/v2/bridgebot/api");
|
|
46
46
|
const PAYOUTS_ENDPOINT = "/bridgebot";
|
|
47
47
|
async function requestCryptoPayout({ userId, type, network, amountFiat, referenceId, toAddress, tokenSymbol, currencyFiat = "USD", fromDispatchWallet = false, }) {
|
|
48
48
|
return baseClient
|
|
@@ -49,7 +49,7 @@ exports.getPendingCardOrder = getPendingCardOrder;
|
|
|
49
49
|
exports.getCardUser = getCardUser;
|
|
50
50
|
exports.RainClient = __importStar(require("./rainServiceClient"));
|
|
51
51
|
const restClient_1 = require("../restClient");
|
|
52
|
-
const baseClient = (0, restClient_1.getRestClient)(process.env.RAIN_SERVICE_API_IAM_URL);
|
|
52
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.RAIN_SERVICE_API_IAM_URL, "/rain-v2/api");
|
|
53
53
|
const RAIN_ENDPOINT = "/rain-v2";
|
|
54
54
|
async function createCardApplication(userId, input) {
|
|
55
55
|
return baseClient
|
package/lib/restClient.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Preserve the shared legacy client unless this service explicitly opts into
|
|
3
|
+
* IAM. With both args, requests under `twinGatewayPrefix` go SigV4-signed to
|
|
4
|
+
* the IAM twin; v1/other paths stay on the gateway.
|
|
5
|
+
*/
|
|
6
|
+
export declare const getRestClient: (iamUrl?: string, twinGatewayPrefix?: string) => import("axios").AxiosInstance;
|
package/lib/restClient.js
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRestClient = void 0;
|
|
4
4
|
const serviceClient_1 = require("./serviceClient");
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Preserve the shared legacy client unless this service explicitly opts into
|
|
7
|
+
* IAM. With both args, requests under `twinGatewayPrefix` go SigV4-signed to
|
|
8
|
+
* the IAM twin; v1/other paths stay on the gateway.
|
|
9
|
+
*/
|
|
10
|
+
const getRestClient = (iamUrl, twinGatewayPrefix) => iamUrl && twinGatewayPrefix ? (0, serviceClient_1.createDualClient)({}, twinGatewayPrefix, iamUrl) : serviceClient_1.baseClient;
|
|
7
11
|
exports.getRestClient = getRestClient;
|
package/lib/serviceClient.d.ts
CHANGED
|
@@ -2,3 +2,14 @@ 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
|
+
* Dual-mode client for the ServiceApi SigV4 migration: requests whose path
|
|
7
|
+
* starts with `twinGatewayPrefix` (e.g. "/v2/users/api") are rewritten onto the
|
|
8
|
+
* target's IAM Function URL (prefix stripped to "/api/...") and SigV4-signed;
|
|
9
|
+
* every other path keeps the legacy gateway + `service_` token. This is what
|
|
10
|
+
* lets modules mixing v1 REST and v2 `/api` calls migrate per-route.
|
|
11
|
+
*
|
|
12
|
+
* Interceptor execution order (axios runs request interceptors last-registered
|
|
13
|
+
* first): rewrite → credential attach → trace → sigv4.
|
|
14
|
+
*/
|
|
15
|
+
export declare const createDualClient: (axiosConfig: AxiosRequestConfig, twinGatewayPrefix: string, iamUrl?: 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.baseClient = exports.createServiceClient = exports.DEFAULT_TIMEOUT_MS = void 0;
|
|
6
|
+
exports.createDualClient = 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"));
|
|
@@ -30,6 +30,45 @@ const interceptor = function (tokenProvider, authenticate) {
|
|
|
30
30
|
return tokenProvider({ getToken, headerFormatter });
|
|
31
31
|
};
|
|
32
32
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
33
|
+
// Trace propagation, shared by every client flavour.
|
|
34
|
+
const traceInterceptor = (requestConfig) => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
requestConfig.headers = requestConfig.headers || {};
|
|
37
|
+
// Propagate correlation ID across services
|
|
38
|
+
const correlationId = (_a = logger_1.default.defaultMeta) === null || _a === void 0 ? void 0 : _a.correlationId;
|
|
39
|
+
if (correlationId) {
|
|
40
|
+
requestConfig.headers["x-correlation-id"] = correlationId;
|
|
41
|
+
}
|
|
42
|
+
const annotations = (_b = logger_1.default.defaultMeta) === null || _b === void 0 ? void 0 : _b.annotations;
|
|
43
|
+
if (annotations) {
|
|
44
|
+
// Propagate request ID for distributed tracing
|
|
45
|
+
if (annotations.requestId) {
|
|
46
|
+
requestConfig.headers["x-request-id"] = annotations.requestId;
|
|
47
|
+
}
|
|
48
|
+
// Propagate user ID for distributed tracing
|
|
49
|
+
if (annotations.userId) {
|
|
50
|
+
requestConfig.headers["x-user-id"] = annotations.userId;
|
|
51
|
+
}
|
|
52
|
+
// Increment depth for call chain tracking
|
|
53
|
+
const currentDepth = annotations.depth || 0;
|
|
54
|
+
requestConfig.headers["x-request-depth"] = String(currentDepth + 1);
|
|
55
|
+
}
|
|
56
|
+
return requestConfig;
|
|
57
|
+
};
|
|
58
|
+
const retryInterceptor = (client) => async (error) => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
const originalConfig = error.config;
|
|
61
|
+
const isRetryableError = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === RETRY_STATUS_CODE &&
|
|
62
|
+
originalConfig &&
|
|
63
|
+
!((_b = originalConfig.headers) === null || _b === void 0 ? void 0 : _b["x-retry-attempt"]);
|
|
64
|
+
if (isRetryableError) {
|
|
65
|
+
await sleep(RETRY_DELAY_MS);
|
|
66
|
+
originalConfig.headers = originalConfig.headers || {};
|
|
67
|
+
originalConfig.headers["x-retry-attempt"] = "true";
|
|
68
|
+
return client.request(originalConfig);
|
|
69
|
+
}
|
|
70
|
+
return Promise.reject(error);
|
|
71
|
+
};
|
|
33
72
|
const createServiceClient = (config, iamUrl) => {
|
|
34
73
|
const serviceClient = axios_1.default.create({
|
|
35
74
|
timeout: exports.DEFAULT_TIMEOUT_MS,
|
|
@@ -37,48 +76,55 @@ const createServiceClient = (config, iamUrl) => {
|
|
|
37
76
|
...(iamUrl ? { baseURL: iamUrl } : {}),
|
|
38
77
|
});
|
|
39
78
|
serviceClient.interceptors.request.use(iamUrl ? (0, sigv4_1.createSigV4Interceptor)(iamUrl) : interceptor(axios_token_interceptor_1.default, credentials_1.getServiceCredentials));
|
|
40
|
-
|
|
41
|
-
serviceClient.interceptors.
|
|
42
|
-
var _a, _b;
|
|
43
|
-
requestConfig.headers = requestConfig.headers || {};
|
|
44
|
-
// Propagate correlation ID across services
|
|
45
|
-
const correlationId = (_a = logger_1.default.defaultMeta) === null || _a === void 0 ? void 0 : _a.correlationId;
|
|
46
|
-
if (correlationId) {
|
|
47
|
-
requestConfig.headers["x-correlation-id"] = correlationId;
|
|
48
|
-
}
|
|
49
|
-
const annotations = (_b = logger_1.default.defaultMeta) === null || _b === void 0 ? void 0 : _b.annotations;
|
|
50
|
-
if (annotations) {
|
|
51
|
-
// Propagate request ID for distributed tracing
|
|
52
|
-
if (annotations.requestId) {
|
|
53
|
-
requestConfig.headers["x-request-id"] = annotations.requestId;
|
|
54
|
-
}
|
|
55
|
-
// Propagate user ID for distributed tracing
|
|
56
|
-
if (annotations.userId) {
|
|
57
|
-
requestConfig.headers["x-user-id"] = annotations.userId;
|
|
58
|
-
}
|
|
59
|
-
// Increment depth for call chain tracking
|
|
60
|
-
const currentDepth = annotations.depth || 0;
|
|
61
|
-
requestConfig.headers["x-request-depth"] = String(currentDepth + 1);
|
|
62
|
-
}
|
|
63
|
-
return requestConfig;
|
|
64
|
-
});
|
|
65
|
-
serviceClient.interceptors.response.use((response) => response, async (error) => {
|
|
66
|
-
var _a, _b;
|
|
67
|
-
const originalConfig = error.config;
|
|
68
|
-
const isRetryableError = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === RETRY_STATUS_CODE &&
|
|
69
|
-
originalConfig &&
|
|
70
|
-
!((_b = originalConfig.headers) === null || _b === void 0 ? void 0 : _b["x-retry-attempt"]);
|
|
71
|
-
if (isRetryableError) {
|
|
72
|
-
await sleep(RETRY_DELAY_MS);
|
|
73
|
-
originalConfig.headers = originalConfig.headers || {};
|
|
74
|
-
originalConfig.headers["x-retry-attempt"] = "true";
|
|
75
|
-
return serviceClient.request(originalConfig);
|
|
76
|
-
}
|
|
77
|
-
return Promise.reject(error);
|
|
78
|
-
});
|
|
79
|
+
serviceClient.interceptors.request.use(traceInterceptor);
|
|
80
|
+
serviceClient.interceptors.response.use((response) => response, retryInterceptor(serviceClient));
|
|
79
81
|
return serviceClient;
|
|
80
82
|
};
|
|
81
83
|
exports.createServiceClient = createServiceClient;
|
|
82
84
|
exports.baseClient = (0, exports.createServiceClient)({
|
|
83
85
|
baseURL: config_1.config.baseEndpoint,
|
|
84
86
|
});
|
|
87
|
+
/**
|
|
88
|
+
* Dual-mode client for the ServiceApi SigV4 migration: requests whose path
|
|
89
|
+
* starts with `twinGatewayPrefix` (e.g. "/v2/users/api") are rewritten onto the
|
|
90
|
+
* target's IAM Function URL (prefix stripped to "/api/...") and SigV4-signed;
|
|
91
|
+
* every other path keeps the legacy gateway + `service_` token. This is what
|
|
92
|
+
* lets modules mixing v1 REST and v2 `/api` calls migrate per-route.
|
|
93
|
+
*
|
|
94
|
+
* Interceptor execution order (axios runs request interceptors last-registered
|
|
95
|
+
* first): rewrite → credential attach → trace → sigv4.
|
|
96
|
+
*/
|
|
97
|
+
const createDualClient = (axiosConfig, twinGatewayPrefix, iamUrl) => {
|
|
98
|
+
if (!iamUrl)
|
|
99
|
+
return (0, exports.createServiceClient)(axiosConfig);
|
|
100
|
+
const serviceClient = axios_1.default.create({
|
|
101
|
+
timeout: exports.DEFAULT_TIMEOUT_MS,
|
|
102
|
+
baseURL: config_1.config.baseEndpoint,
|
|
103
|
+
...axiosConfig,
|
|
104
|
+
});
|
|
105
|
+
const tokenAttach = interceptor(axios_token_interceptor_1.default, credentials_1.getServiceCredentials);
|
|
106
|
+
// Runs last: signs only requests the rewrite pointed at the twin.
|
|
107
|
+
serviceClient.interceptors.request.use((0, sigv4_1.createSigV4Interceptor)(iamUrl));
|
|
108
|
+
serviceClient.interceptors.request.use(traceInterceptor);
|
|
109
|
+
// Twin requests are signed, never beared.
|
|
110
|
+
serviceClient.interceptors.request.use(async (requestConfig) => {
|
|
111
|
+
if (requestConfig.baseURL === iamUrl)
|
|
112
|
+
return requestConfig;
|
|
113
|
+
return tokenAttach(requestConfig);
|
|
114
|
+
});
|
|
115
|
+
// Registered last so it runs first: route twin-prefixed paths to the twin.
|
|
116
|
+
serviceClient.interceptors.request.use((requestConfig) => {
|
|
117
|
+
var _a;
|
|
118
|
+
const p = (_a = requestConfig.url) !== null && _a !== void 0 ? _a : "";
|
|
119
|
+
if (p === twinGatewayPrefix || p.startsWith(twinGatewayPrefix + "/")) {
|
|
120
|
+
requestConfig.baseURL = iamUrl;
|
|
121
|
+
requestConfig.url = "/api" + p.slice(twinGatewayPrefix.length);
|
|
122
|
+
if (requestConfig.headers)
|
|
123
|
+
delete requestConfig.headers.Authorization;
|
|
124
|
+
}
|
|
125
|
+
return requestConfig;
|
|
126
|
+
});
|
|
127
|
+
serviceClient.interceptors.response.use((response) => response, retryInterceptor(serviceClient));
|
|
128
|
+
return serviceClient;
|
|
129
|
+
};
|
|
130
|
+
exports.createDualClient = createDualClient;
|
|
@@ -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.getRestClient)(process.env.USERS_SERVICE_API_IAM_URL);
|
|
50
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.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.getRestClient)(process.env.VERIFICATION_SERVICE_API_IAM_URL);
|
|
46
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.VERIFICATION_SERVICE_API_IAM_URL, "/v2/verification/api");
|
|
47
47
|
const VERIFICATION_ENDPOINT = "/verification";
|
|
48
48
|
async function getUserVerification(userId) {
|
|
49
49
|
return baseClient.get(`${VERIFICATION_ENDPOINT}/user/${userId}`).then((res) => res.data);
|
|
@@ -47,7 +47,7 @@ exports.buildSolanaPayment = buildSolanaPayment;
|
|
|
47
47
|
exports.listListedKaminoVaultIds = listListedKaminoVaultIds;
|
|
48
48
|
exports.Web3Client = __importStar(require("./web3ServiceClient"));
|
|
49
49
|
const restClient_1 = require("../restClient");
|
|
50
|
-
const baseClient = (0, restClient_1.getRestClient)(process.env.WEB3_SERVICE_API_IAM_URL);
|
|
50
|
+
const baseClient = (0, restClient_1.getRestClient)(process.env.WEB3_SERVICE_API_IAM_URL, "/v2/web3/api");
|
|
51
51
|
const WEB3_ENDPOINT = "/web3";
|
|
52
52
|
const WEB3_V2_ENDPOINT = "/v2/web3/api";
|
|
53
53
|
async function getExactInQuote(input) {
|