@riocrypto/common-server 1.0.568 → 1.0.570
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.
|
@@ -13,11 +13,16 @@ interface AdminAuthPayload {
|
|
|
13
13
|
id: string;
|
|
14
14
|
email: string;
|
|
15
15
|
}
|
|
16
|
+
interface PartnerAuthPayload {
|
|
17
|
+
id: string;
|
|
18
|
+
email: string;
|
|
19
|
+
}
|
|
16
20
|
declare global {
|
|
17
21
|
namespace Express {
|
|
18
22
|
interface Request {
|
|
19
23
|
currentAuth?: AuthPayload;
|
|
20
24
|
currentAdminAuth?: AdminAuthPayload;
|
|
25
|
+
currentPartnerAuth?: PartnerAuthPayload;
|
|
21
26
|
user?: UserDoc | BusinessUserDoc;
|
|
22
27
|
partner?: PartnerDoc;
|
|
23
28
|
validAdminApiKey?: boolean;
|
|
@@ -22,7 +22,7 @@ const auth_1 = require("../models/auth");
|
|
|
22
22
|
const apiKey_1 = require("../services/apiKey");
|
|
23
23
|
const secret_manager_client_1 = require("../clients/secret-manager-client");
|
|
24
24
|
const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
25
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
26
26
|
let missingKYC = false;
|
|
27
27
|
if (authorizationTypes.includes(common_1.AuthorizationType.AdminAPI)) {
|
|
28
28
|
let apiKey = req.header("x-api-key");
|
|
@@ -38,8 +38,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
38
38
|
authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC) ||
|
|
39
39
|
authorizationTypes.includes(common_1.AuthorizationType.User) ||
|
|
40
40
|
authorizationTypes.includes(common_1.AuthorizationType.UserOptional) ||
|
|
41
|
-
authorizationTypes.includes(common_1.AuthorizationType.Broker)
|
|
42
|
-
authorizationTypes.includes(common_1.AuthorizationType.Partner)) {
|
|
41
|
+
authorizationTypes.includes(common_1.AuthorizationType.Broker)) {
|
|
43
42
|
const apiKey = req.header("x-api-key");
|
|
44
43
|
if (apiKey) {
|
|
45
44
|
try {
|
|
@@ -99,11 +98,24 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
99
98
|
catch (err) { }
|
|
100
99
|
}
|
|
101
100
|
}
|
|
101
|
+
if (authorizationTypes.includes(common_1.AuthorizationType.PartnerAuth)) {
|
|
102
|
+
if ((_g = req.cookies) === null || _g === void 0 ? void 0 : _g.partnerAccessToken) {
|
|
103
|
+
try {
|
|
104
|
+
const PARTNER_ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("PARTNER_ACCESS_TOKEN_SECRET");
|
|
105
|
+
if (!PARTNER_ACCESS_TOKEN_SECRET) {
|
|
106
|
+
throw new Error("Unable to get PARTNER_ACCESS_TOKEN_SECRET");
|
|
107
|
+
}
|
|
108
|
+
const payload = jsonwebtoken_1.default.verify(req.cookies.partnerAccessToken, PARTNER_ACCESS_TOKEN_SECRET);
|
|
109
|
+
req.currentPartnerAuth = payload;
|
|
110
|
+
}
|
|
111
|
+
catch (err) { }
|
|
112
|
+
}
|
|
113
|
+
}
|
|
102
114
|
if (authorizationTypes.includes(common_1.AuthorizationType.Partner) &&
|
|
103
|
-
req.
|
|
115
|
+
req.currentPartnerAuth) {
|
|
104
116
|
const Partner = yield (0, partner_1.buildPartner)(mongoose);
|
|
105
117
|
const partner = yield Partner.findOne({
|
|
106
|
-
authId: req.
|
|
118
|
+
authId: req.currentPartnerAuth.id,
|
|
107
119
|
});
|
|
108
120
|
if (partner) {
|
|
109
121
|
req.partner = partner;
|
|
@@ -207,6 +219,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
207
219
|
// if no auth
|
|
208
220
|
(!req.currentAdminAuth &&
|
|
209
221
|
!req.currentAuth &&
|
|
222
|
+
!req.currentPartnerAuth &&
|
|
210
223
|
!req.user &&
|
|
211
224
|
!req.partner &&
|
|
212
225
|
!req.validAdminApiKey) ||
|
|
@@ -229,12 +242,12 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
229
242
|
}
|
|
230
243
|
if ((authorizationTypes.includes(common_1.AuthorizationType.User) ||
|
|
231
244
|
authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) &&
|
|
232
|
-
((
|
|
245
|
+
((_h = req.cookies) === null || _h === void 0 ? void 0 : _h.accessToken)) {
|
|
233
246
|
throw new common_1.MissingUserError();
|
|
234
247
|
}
|
|
235
248
|
if (authorizationTypes.includes(common_1.AuthorizationType.Admin) &&
|
|
236
249
|
authorizationTypes.length === 1 &&
|
|
237
|
-
((
|
|
250
|
+
((_j = req.cookies) === null || _j === void 0 ? void 0 : _j.accessToken)) {
|
|
238
251
|
throw new common_1.AdminOnlyError();
|
|
239
252
|
}
|
|
240
253
|
if (!req.user && authorizationTypes.includes(common_1.AuthorizationType.Broker)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.570",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@aws-sdk/client-s3": "^3.297.0",
|
|
25
25
|
"@google-cloud/storage": "^6.9.5",
|
|
26
|
-
"@riocrypto/common": "^1.0.
|
|
26
|
+
"@riocrypto/common": "^1.0.556",
|
|
27
27
|
"@types/express": "^4.17.13",
|
|
28
28
|
"axios": "^0.27.2",
|
|
29
29
|
"ccxt": "^3.0.30",
|