@spritz-finance/service-client 0.3.139 → 0.4.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.
@@ -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;
@@ -31,4 +31,5 @@ export type Integrator = {
31
31
  id: string;
32
32
  name: string;
33
33
  email: number;
34
+ canSubsidizeUserFees: boolean;
34
35
  };
@@ -1,14 +1,14 @@
1
1
  export * as UsersClient from './usersServiceClient';
2
2
  import { Integrator, IntegratorWebhook, User } from './types';
3
3
  export declare function getActiveUsers(): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<string[]>>;
4
- export declare function getUserById(id: string): Promise<User>;
5
- export declare function setMembership(userId: string, membership: string): Promise<User>;
6
- export declare function findOrInitialize(email: string): Promise<User>;
7
- export declare function findByEmail(email: string): Promise<User>;
8
- export declare function getIntegratorWebhooks(integratorId: string): Promise<IntegratorWebhook[]>;
9
- export declare function getIntegrator(integratorId: string): Promise<Integrator>;
4
+ export declare function getUserById(id: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<User>>;
5
+ export declare function setMembership(userId: string, membership: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<User>>;
6
+ export declare function findOrInitialize(email: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<User>>;
7
+ export declare function findByEmail(email: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<User>>;
10
8
  export declare function validateAdIdentifiers(adIdentifiers?: {
11
9
  gclid?: string;
12
10
  twclid?: string;
13
11
  fbclid?: string;
14
12
  }): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<boolean>>;
13
+ export declare function getIntegratorWebhooks(integratorId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<IntegratorWebhook[]>>;
14
+ export declare function getIntegrator(integratorId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<Integrator>>;
@@ -23,25 +23,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.validateAdIdentifiers = exports.getIntegrator = exports.getIntegratorWebhooks = exports.findByEmail = exports.findOrInitialize = exports.setMembership = exports.getUserById = exports.getActiveUsers = exports.UsersClient = void 0;
26
+ exports.getIntegrator = exports.getIntegratorWebhooks = exports.validateAdIdentifiers = exports.findByEmail = exports.findOrInitialize = exports.setMembership = exports.getUserById = exports.getActiveUsers = exports.UsersClient = void 0;
27
27
  exports.UsersClient = __importStar(require("./usersServiceClient"));
28
28
  const serviceClient_1 = require("../serviceClient");
29
- const USERS_ENDPOINT = '/users';
29
+ const NEW_USER_ENDPOINT = '/v2/users/api';
30
30
  async function getActiveUsers() {
31
31
  return serviceClient_1.baseClient
32
- .get(`v2${USERS_ENDPOINT}/active-users`)
32
+ .get(`${NEW_USER_ENDPOINT}/users/active`)
33
33
  .then((res) => res.data);
34
34
  }
35
35
  exports.getActiveUsers = getActiveUsers;
36
36
  async function getUserById(id) {
37
37
  return serviceClient_1.baseClient
38
- .get(`${USERS_ENDPOINT}/id/${id}`)
38
+ .get(`${NEW_USER_ENDPOINT}/users/${id}`)
39
39
  .then((res) => res.data);
40
40
  }
41
41
  exports.getUserById = getUserById;
42
42
  async function setMembership(userId, membership) {
43
43
  return serviceClient_1.baseClient
44
- .post(`${USERS_ENDPOINT}/id/${userId}/membership`, {
44
+ .post(`${NEW_USER_ENDPOINT}/users/${userId}/membership`, {
45
45
  membership,
46
46
  })
47
47
  .then((res) => res.data);
@@ -49,7 +49,7 @@ async function setMembership(userId, membership) {
49
49
  exports.setMembership = setMembership;
50
50
  async function findOrInitialize(email) {
51
51
  return serviceClient_1.baseClient
52
- .post(`${USERS_ENDPOINT}/find-or-initialize`, {
52
+ .post(`${NEW_USER_ENDPOINT}/users`, {
53
53
  email,
54
54
  })
55
55
  .then((res) => res.data);
@@ -57,25 +57,25 @@ async function findOrInitialize(email) {
57
57
  exports.findOrInitialize = findOrInitialize;
58
58
  async function findByEmail(email) {
59
59
  return serviceClient_1.baseClient
60
- .get(`${USERS_ENDPOINT}/users/email/${email}`)
60
+ .get(`${NEW_USER_ENDPOINT}/users?email=${encodeURIComponent(email)}`)
61
61
  .then((res) => res.data);
62
62
  }
63
63
  exports.findByEmail = findByEmail;
64
+ async function validateAdIdentifiers(adIdentifiers) {
65
+ return serviceClient_1.baseClient
66
+ .post(`${NEW_USER_ENDPOINT}/ad-identifiers/validations`, adIdentifiers)
67
+ .then((res) => res.data);
68
+ }
69
+ exports.validateAdIdentifiers = validateAdIdentifiers;
64
70
  async function getIntegratorWebhooks(integratorId) {
65
71
  return serviceClient_1.baseClient
66
- .get(`${USERS_ENDPOINT}/integrators/service/webhooks/${integratorId}`)
72
+ .get(`${NEW_USER_ENDPOINT}/integrators/${integratorId}/webhooks`)
67
73
  .then((res) => res.data);
68
74
  }
69
75
  exports.getIntegratorWebhooks = getIntegratorWebhooks;
70
76
  async function getIntegrator(integratorId) {
71
77
  return serviceClient_1.baseClient
72
- .get(`${USERS_ENDPOINT}/integrators/integrator/${integratorId}`)
78
+ .get(`${NEW_USER_ENDPOINT}/integrators/${integratorId}`)
73
79
  .then((res) => res.data);
74
80
  }
75
81
  exports.getIntegrator = getIntegrator;
76
- async function validateAdIdentifiers(adIdentifiers) {
77
- return serviceClient_1.baseClient
78
- .post(`${USERS_ENDPOINT}/ad-identifiers/validate`, adIdentifiers)
79
- .then((res) => res.data);
80
- }
81
- exports.validateAdIdentifiers = validateAdIdentifiers;
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.4.0",
4
4
  "description": "Service client",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",