@spritz-finance/service-client 0.40.1 → 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 CHANGED
@@ -1,9 +1,12 @@
1
1
  # Service client
2
2
 
3
- REST clients use the existing shared-secret credentials by default. To opt a client
4
- into AWS IAM authentication, set its `<SVC>_SERVICE_API_IAM_URL` environment variable
5
- **before importing this package**. No variable means the existing client, URLs,
6
- headers, timeouts and retries are unchanged. Graph authentication is unaffected.
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
- 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 (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.getRestClient)(process.env.BRIDGE_SERVICE_API_IAM_URL, "/v2/bridge/api");
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.getRestClient)(process.env.CHECKBOOK_SERVICE_API_IAM_URL, "/v2/liabilities/api");
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.getRestClient)(process.env.EXCHANGE_RATES_SERVICE_API_IAM_URL);
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.getRestClient)(process.env.FEATURES_SERVICE_API_IAM_URL, "/v2/users/api");
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.getRestClient)(process.env.GROWTH_SERVICE_API_IAM_URL, "/v2/growth/api");
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.getRestClient)(process.env.LIABILITIES_SERVICE_API_IAM_URL, "/v2/liabilities/api");
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.getRestClient)(process.env.NOTIFICATIONS_SERVICE_API_IAM_URL, "/v2/notifications/api");
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.getRestClient)(process.env.ONRAMP_SERVICE_API_IAM_URL, "/v2/bridge/api");
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.getRestClient)(process.env.PAYABLE_ACCOUNTS_SERVICE_API_IAM_URL, "/payable-accounts-v2/api");
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.getRestClient)(process.env.PAYMENT_ADDRESS_SERVICE_API_IAM_URL, "/payment-addresses-v2/api");
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.getRestClient)(process.env.PAYMENTS_SERVICE_API_IAM_URL, "/v2/liabilities/api");
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.getRestClient)(process.env.PAYOUTS_SERVICE_API_IAM_URL, "/v2/bridgebot/api");
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
- : (0, axios_token_interceptor_1.default)({
73
- getToken: axios_token_interceptor_1.default.tokenCache(credentials_1.getServiceCredentials, {
74
- getMaxAge: () => EXPIRATION_BUFFER_MS,
75
- }),
76
- headerFormatter: (res) => `Bearer ${res.access_token}`,
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
@@ -51,7 +51,7 @@ exports.RainClient = __importStar(require("./rainServiceClient"));
51
51
  const types_1 = require("../payableAccounts/types");
52
52
  const restClient_1 = require("../restClient");
53
53
  const types_2 = require("./types");
54
- const baseClient = (0, restClient_1.getRestClient)(process.env.RAIN_SERVICE_API_IAM_URL, "/rain-v2/api");
54
+ const baseClient = (0, restClient_1.getTwinRestClient)("RAIN_SERVICE_API_IAM_URL", "/rain-v2/api");
55
55
  const RAIN_ENDPOINT = "/rain-v2";
56
56
  // Rain's CreateRainApplication submits the application and uploads the ID
57
57
  // documents, which takes 10-18s in production. The 10s DEFAULT_TIMEOUT_MS
@@ -1,6 +1,15 @@
1
+ type IamUrlEnvVar = `${string}_SERVICE_API_IAM_URL`;
1
2
  /**
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.
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 getRestClient: (iamUrl?: string, twinGatewayPrefix?: string) => import("axios").AxiosInstance;
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.getRestClient = void 0;
3
+ exports.getLegacyRestClient = exports.getTwinRestClient = void 0;
4
4
  const serviceClient_1 = require("./serviceClient");
5
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.
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 getRestClient = (iamUrl, twinGatewayPrefix) => iamUrl && twinGatewayPrefix ? (0, serviceClient_1.createDualClient)({}, twinGatewayPrefix, iamUrl) : serviceClient_1.baseClient;
11
- exports.getRestClient = getRestClient;
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;
@@ -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?: string) => import("axios").AxiosInstance;
27
+ export declare const createDualClient: (axiosConfig: AxiosRequestConfig, twinGatewayPrefix: string, iamUrl: string | undefined, iamUrlEnvVar: string) => import("axios").AxiosInstance;
@@ -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 ? (0, sigv4_1.createSigV4Interceptor)(iamUrl) : interceptor(axios_token_interceptor_1.default, credentials_1.getServiceCredentials));
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 (0, exports.createServiceClient)(axiosConfig);
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.getRestClient)(process.env.TRANSACTIONS_SERVICE_API_IAM_URL, "/v2/transactions/api");
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.getRestClient)(process.env.UNBLOCK_SERVICE_API_IAM_URL);
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.getRestClient)(process.env.USERS_SERVICE_API_IAM_URL, "/v2/users/api");
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.getRestClient)(process.env.VERIFICATION_SERVICE_API_IAM_URL, "/v2/verification/api");
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.getRestClient)(process.env.WEB3_SERVICE_API_IAM_URL, "/v2/web3/api");
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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spritz-finance/service-client",
3
- "version": "0.40.1",
3
+ "version": "0.41.0",
4
4
  "gitHead": "06f8e96b7b38c34df26a38da329331940675e4f8",
5
5
  "description": "Service client",
6
6
  "license": "ISC",