@riocrypto/common-server 1.0.2851 → 1.0.2853

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,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.buildAxiosWithLogging = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const logger_1 = __importDefault(require("../services/logger"));
9
+ // Cap how much of a request/response body we serialize into a single log line.
10
+ // The full body is essentially never needed for observability, and large
11
+ // exchange payloads (deposit/withdrawal history, order lists, transfer lists)
12
+ // otherwise flood the logs. Only the log string is truncated - the value
13
+ // returned to callers (and rejected on errors) still carries the full data.
14
+ const MAX_LOG_BODY_LENGTH = 1000;
15
+ function stringifyForLog(data) {
16
+ const serialized = JSON.stringify(data);
17
+ if (serialized === undefined) {
18
+ return "undefined";
19
+ }
20
+ if (serialized.length <= MAX_LOG_BODY_LENGTH) {
21
+ return serialized;
22
+ }
23
+ return `${serialized.slice(0, MAX_LOG_BODY_LENGTH)}...[truncated ${serialized.length - MAX_LOG_BODY_LENGTH} chars]`;
24
+ }
9
25
  function buildAxiosWithLogging() {
10
26
  const axiosWithLogging = axios_1.default.create();
11
27
  const sensitiveSubstrings = [
@@ -89,7 +105,7 @@ function buildAxiosWithLogging() {
89
105
  // Mask sensitive headers in the configuration
90
106
  const maskedHeaders = maskHeaders(customConfig.headers);
91
107
  // Combine and log the full request configuration with masked headers
92
- const logMessage = `Request: method=${customConfig.method}, url=${maskUrl(customConfig.url)}, headers=${JSON.stringify(maskedHeaders)}, data=${JSON.stringify(maskData(customConfig.data))}`;
108
+ const logMessage = `Request: method=${customConfig.method}, url=${maskUrl(customConfig.url)}, headers=${JSON.stringify(maskedHeaders)}, data=${stringifyForLog(maskData(customConfig.data))}`;
93
109
  ((_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.info(logMessage)) || console.log(logMessage);
94
110
  }
95
111
  return config;
@@ -107,7 +123,7 @@ function buildAxiosWithLogging() {
107
123
  // Check if logging is disabled for this request
108
124
  if (!customConfig.skipLogging) {
109
125
  // Combine and log the full response details
110
- const logMessage = `Response: url=${maskUrl(customConfig.url)}, status=${response.status}, data=${JSON.stringify(maskData(response.data))}`;
126
+ const logMessage = `Response: url=${maskUrl(customConfig.url)}, status=${response.status}, data=${stringifyForLog(maskData(response.data))}`;
111
127
  ((_a = logger_1.default.getLogger()) === null || _a === void 0 ? void 0 : _a.info(logMessage)) || console.log(logMessage);
112
128
  }
113
129
  return response;
@@ -116,7 +132,7 @@ function buildAxiosWithLogging() {
116
132
  // Combine and log the response error details without headers
117
133
  let logMessage = `Response Error: url=${maskUrl((_a = error.config) === null || _a === void 0 ? void 0 : _a.url)}, message=${error.message}`;
118
134
  if (error.response) {
119
- logMessage += `, status=${error.response.status}, data=${JSON.stringify(maskData(error.response.data))}`;
135
+ logMessage += `, status=${error.response.status}, data=${stringifyForLog(maskData(error.response.data))}`;
120
136
  }
121
137
  ((_b = logger_1.default.getLogger()) === null || _b === void 0 ? void 0 : _b.info(logMessage)) || console.log(logMessage);
122
138
  return Promise.reject({
@@ -208,6 +208,7 @@ declare class ClusterClient {
208
208
  mpe001IDL: number;
209
209
  beneficiaryName: string;
210
210
  }>;
211
+ getAlfinBalance(fiat: Fiat): Promise<number>;
211
212
  getSTPMXNBalance(): Promise<number>;
212
213
  createSTPMXNWithdrawal(amount: number, CLABE: string, concepto: string, beneficiaryName: string, internalTransferId?: string): Promise<STPMXNWithdrawalDoc>;
213
214
  getSTPMXNWithdrawal(id: string): Promise<STPMXNWithdrawal>;
@@ -696,6 +696,12 @@ class ClusterClient {
696
696
  return response.data;
697
697
  });
698
698
  }
699
+ getAlfinBalance(fiat) {
700
+ return __awaiter(this, void 0, void 0, function* () {
701
+ const response = yield this.axios.get(`${this.baseUrl}/api/bank/accounts/alfin/${fiat}/balance`, { headers: { "x-cluster-api-key": this.clusterApiKey } });
702
+ return response.data.disponible;
703
+ });
704
+ }
699
705
  getSTPMXNBalance() {
700
706
  return __awaiter(this, void 0, void 0, function* () {
701
707
  const response = yield this.axios.get(`${this.baseUrl}/api/bank/accounts/STP/MXN/balance`, { headers: { "x-cluster-api-key": this.clusterApiKey } });
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getProcessor = void 0;
4
4
  const common_1 = require("@riocrypto/common");
5
- // Alfin takes effect only in Test (Alfin UAT) and Production (Alfin prod). In
6
- // every other environment we never route to Alfin, regardless of user
7
- // attributes or active processors.
8
- const isAlfinEnabled = () => [common_1.RioEnv.Test, common_1.RioEnv.Production].includes(process.env.RIO_ENV);
5
+ // Alfin takes effect only in Production (Alfin prod). In every other
6
+ // environment we never route to Alfin, regardless of user attributes or active
7
+ // processors; non-prod Peru flows fall back to the mocked Interbank path.
8
+ const isAlfinEnabled = () => [common_1.RioEnv.Production].includes(process.env.RIO_ENV);
9
9
  const getProcessor = ({ country, fiat, user, activeProcessors, side, isBinanceRFQ, }) => {
10
10
  var _a, _b, _c, _d, _e, _f;
11
11
  if (isBinanceRFQ === true) {
@@ -6,6 +6,7 @@ const sanitizeCryptoAddressDoc = (doc) => {
6
6
  delete obj.fireblocksExternalWalletId;
7
7
  delete obj.isFireblocksWhitelisted;
8
8
  delete obj.userApproved;
9
+ delete obj.privyWalletId;
9
10
  return obj;
10
11
  };
11
12
  exports.sanitizeCryptoAddressDoc = sanitizeCryptoAddressDoc;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sanitizeUserDoc = void 0;
4
4
  const sanitizeUserDoc = (doc) => {
5
5
  const obj = doc.toJSON();
6
+ delete obj.privyUserId;
6
7
  delete obj.authorizedPhoneNumbers;
7
8
  delete obj.authIds;
8
9
  delete obj.cosignerGroupId;
@@ -14,6 +14,8 @@ interface CryptoAddressAttrs {
14
14
  fireblocksExternalWalletId?: string;
15
15
  isFireblocksWhitelisted?: boolean;
16
16
  availablePayoutAdvancesAmount?: number;
17
+ isPrivyWallet?: boolean;
18
+ privyWalletId?: string;
17
19
  }
18
20
  interface CryptoAddressDoc extends mongoose.Document {
19
21
  createdAt: Date;
@@ -29,6 +31,8 @@ interface CryptoAddressDoc extends mongoose.Document {
29
31
  fireblocksExternalWalletId?: string;
30
32
  isFireblocksWhitelisted?: boolean;
31
33
  availablePayoutAdvancesAmount?: number;
34
+ isPrivyWallet?: boolean;
35
+ privyWalletId?: string;
32
36
  }
33
37
  interface CryptoAddressModel extends mongoose.Model<CryptoAddressDoc> {
34
38
  build(attrs: CryptoAddressAttrs): HydratedDocument<CryptoAddressDoc>;
@@ -51,6 +51,12 @@ const buildCryptoAddress = (mongoose) => {
51
51
  availablePayoutAdvancesAmount: {
52
52
  type: Number,
53
53
  },
54
+ isPrivyWallet: {
55
+ type: Boolean,
56
+ },
57
+ privyWalletId: {
58
+ type: String,
59
+ },
54
60
  }, {
55
61
  toJSON: {
56
62
  transform(doc, ret) {
@@ -46,6 +46,9 @@ interface InternalBalancesDoc extends mongoose.Document {
46
46
  STP: {
47
47
  [key in Fiat & Crypto]: number;
48
48
  };
49
+ alfin: {
50
+ [key in Fiat & Crypto]: number;
51
+ };
49
52
  bancrea: {
50
53
  [key in Fiat & Crypto]: number;
51
54
  };
@@ -68,6 +68,9 @@ const buildInternalBalances = (mongoose) => {
68
68
  [common_1.TreasuryProvider.STP]: {
69
69
  type: Object,
70
70
  },
71
+ [common_1.TreasuryProvider.Alfin]: {
72
+ type: Object,
73
+ },
71
74
  }, {
72
75
  toJSON: {
73
76
  transform(doc, ret) {
@@ -18,6 +18,8 @@ interface UserAttrs {
18
18
  phoneNumber?: string;
19
19
  email: string;
20
20
  cosignerGroupId?: string;
21
+ privyUserId?: string;
22
+ privyRegisteredAt?: Date;
21
23
  attributes?: UserAttribute[];
22
24
  brokerId?: string;
23
25
  platformFeeRanges?: {
@@ -163,6 +165,8 @@ interface UserDoc extends Document {
163
165
  phoneNumber?: string;
164
166
  email: string;
165
167
  cosignerGroupId?: string;
168
+ privyUserId?: string;
169
+ privyRegisteredAt?: Date;
166
170
  attributes?: UserAttribute[];
167
171
  brokerId?: string;
168
172
  platformFeeRanges?: {
@@ -32,6 +32,12 @@ const buildUser = (mongoose) => {
32
32
  cosignerGroupId: {
33
33
  type: String,
34
34
  },
35
+ privyUserId: {
36
+ type: String,
37
+ },
38
+ privyRegisteredAt: {
39
+ type: Date,
40
+ },
35
41
  attioRecordId: {
36
42
  type: String,
37
43
  },
@@ -415,6 +421,7 @@ const buildUser = (mongoose) => {
415
421
  ret.id = ret._id.valueOf();
416
422
  delete ret._id;
417
423
  delete ret.__v;
424
+ delete ret.privyUserId;
418
425
  },
419
426
  },
420
427
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2851",
3
+ "version": "1.0.2853",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "@google-cloud/secret-manager": "^5.6.0",
29
29
  "@google-cloud/storage": "^7.19.0",
30
30
  "@hyperdx/node-opentelemetry": "^0.10.3",
31
- "@riocrypto/common": "1.0.2652",
31
+ "@riocrypto/common": "1.0.2654",
32
32
  "@slack/web-api": "^7.15.0",
33
33
  "@types/express": "^4.17.25",
34
34
  "axios": "1.16.0",