@riocrypto/common-server 1.0.2589 → 1.0.2591
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.
|
@@ -173,7 +173,7 @@ declare class ClusterClient {
|
|
|
173
173
|
CLABE: string;
|
|
174
174
|
}>;
|
|
175
175
|
getSTPMXNBalance(): Promise<number>;
|
|
176
|
-
createSTPMXNWithdrawal(amount: number, CLABE: string, concepto: string, beneficiaryName: string): Promise<STPMXNWithdrawalDoc>;
|
|
176
|
+
createSTPMXNWithdrawal(amount: number, CLABE: string, concepto: string, beneficiaryName: string, internalTransferId?: string): Promise<STPMXNWithdrawalDoc>;
|
|
177
177
|
getSTPMXNWithdrawal(id: string): Promise<STPMXNWithdrawal>;
|
|
178
178
|
createBulkBankPayout(userId: string, payoutBankAccountId: string, deferredPaymentType: DeferredPaymentType): Promise<BulkBankPayout>;
|
|
179
179
|
createBulkCryptoPayout(userId: string, payoutAddressId: string, country: Country, deferredPaymentType: DeferredPaymentType): Promise<BulkCryptoPayout>;
|
|
@@ -599,9 +599,9 @@ class ClusterClient {
|
|
|
599
599
|
return response.data.balance;
|
|
600
600
|
});
|
|
601
601
|
}
|
|
602
|
-
createSTPMXNWithdrawal(amount, CLABE, concepto, beneficiaryName) {
|
|
602
|
+
createSTPMXNWithdrawal(amount, CLABE, concepto, beneficiaryName, internalTransferId) {
|
|
603
603
|
return __awaiter(this, void 0, void 0, function* () {
|
|
604
|
-
const response = yield this.axios.post(`${this.baseUrl}/api/bank/accounts/STP/MXN/withdrawals`, { amount, CLABE, concepto, beneficiaryName }, { headers: { "x-cluster-api-key": this.clusterApiKey } });
|
|
604
|
+
const response = yield this.axios.post(`${this.baseUrl}/api/bank/accounts/STP/MXN/withdrawals`, { amount, CLABE, concepto, beneficiaryName, internalTransferId }, { headers: { "x-cluster-api-key": this.clusterApiKey } });
|
|
605
605
|
return response.data;
|
|
606
606
|
});
|
|
607
607
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./middlewares/require-min-role-or-permission";
|
|
|
8
8
|
export * from "./middlewares/require-min-admin-role";
|
|
9
9
|
export * from "./middlewares/verify-csrf-token";
|
|
10
10
|
export * from "./middlewares/dynamic-rate-limiter";
|
|
11
|
+
export * from "./middlewares/auth-context";
|
|
11
12
|
export * from "./services/apiKey";
|
|
12
13
|
export * from "./services/password";
|
|
13
14
|
export * from "./services/logger";
|
package/build/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __exportStar(require("./middlewares/require-min-role-or-permission"), exports);
|
|
|
24
24
|
__exportStar(require("./middlewares/require-min-admin-role"), exports);
|
|
25
25
|
__exportStar(require("./middlewares/verify-csrf-token"), exports);
|
|
26
26
|
__exportStar(require("./middlewares/dynamic-rate-limiter"), exports);
|
|
27
|
+
__exportStar(require("./middlewares/auth-context"), exports);
|
|
27
28
|
__exportStar(require("./services/apiKey"), exports);
|
|
28
29
|
__exportStar(require("./services/password"), exports);
|
|
29
30
|
__exportStar(require("./services/logger"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
declare global {
|
|
3
|
+
namespace Express {
|
|
4
|
+
interface Request {
|
|
5
|
+
adminContext?: {
|
|
6
|
+
adminId: string;
|
|
7
|
+
adminEmail: string;
|
|
8
|
+
adminName: string;
|
|
9
|
+
};
|
|
10
|
+
userContext?: {
|
|
11
|
+
userId: string;
|
|
12
|
+
phoneNumber: string;
|
|
13
|
+
userName: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export declare const authContextMiddleware: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.authContextMiddleware = void 0;
|
|
16
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
17
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
18
|
+
const common_1 = require("@riocrypto/common");
|
|
19
|
+
const secret_manager_client_1 = require("../clients/secret-manager-client");
|
|
20
|
+
const admin_auth_1 = require("../models/admin-auth");
|
|
21
|
+
const auth_1 = require("../models/auth");
|
|
22
|
+
let cachedAdminSecret = null;
|
|
23
|
+
let cachedUserSecret = null;
|
|
24
|
+
const authContextMiddleware = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const { adminAccessToken, accessToken } = req.cookies;
|
|
26
|
+
if (adminAccessToken) {
|
|
27
|
+
try {
|
|
28
|
+
if (!cachedAdminSecret) {
|
|
29
|
+
cachedAdminSecret = yield secret_manager_client_1.secretManagerClient.getSecretValue("ADMIN_ACCESS_TOKEN_SECRET");
|
|
30
|
+
}
|
|
31
|
+
if (cachedAdminSecret) {
|
|
32
|
+
const decoded = jsonwebtoken_1.default.verify(adminAccessToken, cachedAdminSecret);
|
|
33
|
+
const AdminAuth = (0, admin_auth_1.buildAdminAuth)(mongoose_1.default);
|
|
34
|
+
const adminAuth = yield AdminAuth.findById(decoded.id);
|
|
35
|
+
if (adminAuth) {
|
|
36
|
+
req.adminContext = {
|
|
37
|
+
adminId: decoded.id,
|
|
38
|
+
adminEmail: decoded.email,
|
|
39
|
+
adminName: (0, common_1.getAuthName)(adminAuth.toJSON()),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (error) { }
|
|
45
|
+
}
|
|
46
|
+
if (accessToken) {
|
|
47
|
+
try {
|
|
48
|
+
if (!cachedUserSecret) {
|
|
49
|
+
cachedUserSecret = yield secret_manager_client_1.secretManagerClient.getSecretValue("ACCESS_TOKEN_SECRET");
|
|
50
|
+
}
|
|
51
|
+
if (cachedUserSecret) {
|
|
52
|
+
const decoded = jsonwebtoken_1.default.verify(accessToken, cachedUserSecret);
|
|
53
|
+
const Auth = (0, auth_1.buildAuth)(mongoose_1.default);
|
|
54
|
+
const auth = yield Auth.findById(decoded.id);
|
|
55
|
+
if (auth) {
|
|
56
|
+
req.userContext = {
|
|
57
|
+
userId: decoded.id,
|
|
58
|
+
phoneNumber: decoded.phoneNumber,
|
|
59
|
+
userName: (0, common_1.getAuthName)(auth.toJSON()),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) { }
|
|
65
|
+
}
|
|
66
|
+
next();
|
|
67
|
+
});
|
|
68
|
+
exports.authContextMiddleware = authContextMiddleware;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2591",
|
|
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.3.0",
|
|
29
29
|
"@google-cloud/storage": "^6.9.5",
|
|
30
30
|
"@hyperdx/node-opentelemetry": "^0.7.0",
|
|
31
|
-
"@riocrypto/common": "^1.0.
|
|
31
|
+
"@riocrypto/common": "^1.0.2388",
|
|
32
32
|
"@types/express": "^4.17.13",
|
|
33
33
|
"axios": "^1.7.4",
|
|
34
34
|
"crypto-js": "^4.2.0",
|