@spritz-finance/service-client 0.3.139 → 0.3.140

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.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.baseClient = exports.createServiceClient = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const axios_token_interceptor_1 = __importDefault(require("axios-token-interceptor"));
9
+ const logger_1 = __importDefault(require("@spritz-finance/logger"));
9
10
  const config_1 = require("./config");
10
11
  const credentials_1 = require("./credentials");
11
12
  const EXPIRATION_BUFFER_MS = 20 * 60 * 1000; // 20 minutes buffer
@@ -25,6 +26,26 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
25
26
  const createServiceClient = (config) => {
26
27
  const serviceClient = axios_1.default.create(config);
27
28
  serviceClient.interceptors.request.use(interceptor(axios_token_interceptor_1.default, credentials_1.getServiceCredentials));
29
+ // Add trace header propagation interceptor
30
+ serviceClient.interceptors.request.use((requestConfig) => {
31
+ var _a;
32
+ const annotations = (_a = logger_1.default.defaultMeta) === null || _a === void 0 ? void 0 : _a.annotations;
33
+ if (annotations) {
34
+ requestConfig.headers = requestConfig.headers || {};
35
+ // Propagate request ID for distributed tracing
36
+ if (annotations.requestId) {
37
+ requestConfig.headers['x-request-id'] = annotations.requestId;
38
+ }
39
+ // Propagate user ID for distributed tracing
40
+ if (annotations.userId) {
41
+ requestConfig.headers['x-user-id'] = annotations.userId;
42
+ }
43
+ // Increment depth for call chain tracking
44
+ const currentDepth = annotations.depth || 0;
45
+ requestConfig.headers['x-request-depth'] = String(currentDepth + 1);
46
+ }
47
+ return requestConfig;
48
+ });
28
49
  serviceClient.interceptors.response.use((response) => response, async (error) => {
29
50
  var _a, _b;
30
51
  const originalConfig = error.config;
package/lib/types.d.ts CHANGED
@@ -12,7 +12,7 @@ export interface APIGatewayProxyEventWithDeserializedBody<Body = unknown, PathPa
12
12
  export interface ServiceClientResult<Result> extends Omit<APIGatewayProxyResult, 'body'> {
13
13
  body: ApiResponse<Result>;
14
14
  }
15
- export type ServiceClientHandler<Result, Body = {}, PathParams = {}> = (event: APIGatewayProxyEventWithDeserializedBody<Body, PathParams>) => Promise<Result>;
15
+ export type ServiceClientHandler<Result, Body = object, PathParams = object> = (event: APIGatewayProxyEventWithDeserializedBody<Body, PathParams>) => Promise<Result>;
16
16
  export type ServiceClientResponse<Result, Body = unknown> = Handler<APIGatewayProxyEventWithDeserializedBody<Body>, ServiceClientResult<Result>>;
17
17
  export interface ApiError {
18
18
  message: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spritz-finance/service-client",
3
- "version": "0.3.139",
3
+ "version": "0.3.140",
4
4
  "description": "Service client",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",