@riocrypto/common-server 1.0.1216 → 1.0.1218

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.
@@ -19,9 +19,10 @@ const common_1 = require("@riocrypto/common");
19
19
  const auth_1 = require("../models/auth");
20
20
  const apiKey_1 = require("../services/apiKey");
21
21
  const secret_manager_client_1 = require("../clients/secret-manager-client");
22
+ const admin_1 = require("../models/admin");
22
23
  const admin_auth_1 = require("../models/admin-auth");
23
24
  const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
24
- var _a, _b, _c, _d;
25
+ var _a, _b;
25
26
  if (authorizationTypes.includes(common_1.AuthorizationType.Cluster)) {
26
27
  let apiKey = req.header("x-cluster-api-key");
27
28
  const CLUSTER_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("CLUSTER_API_KEY");
@@ -67,17 +68,19 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
67
68
  }
68
69
  }
69
70
  if (authorizationTypes.includes(common_1.AuthorizationType.Admin)) {
70
- if ((_b = req.cookies) === null || _b === void 0 ? void 0 : _b.adminAccessToken) {
71
+ if (req.currentAdminAuth) {
72
+ let admin;
71
73
  try {
72
- const ADMIN_ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ADMIN_ACCESS_TOKEN_SECRET");
73
- if (!ADMIN_ACCESS_TOKEN_SECRET) {
74
- throw new Error("Unable to get ADMIN_ACCESS_TOKEN_SECRET");
75
- }
76
- const payload = jsonwebtoken_1.default.verify(req.cookies.adminAccessToken, ADMIN_ACCESS_TOKEN_SECRET);
77
- req.currentAdminAuth = payload;
74
+ const Admin = yield (0, admin_1.buildAdmin)(mongoose);
75
+ admin = yield Admin.findOne({
76
+ authIds: { $in: [req.currentAdminAuth.id] },
77
+ });
78
78
  }
79
79
  catch (err) {
80
- console.log(err);
80
+ admin = null;
81
+ }
82
+ if (admin) {
83
+ req.admin = admin;
81
84
  }
82
85
  }
83
86
  }
@@ -104,7 +107,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
104
107
  console.log(err);
105
108
  }
106
109
  }
107
- else if ((_c = req.cookies) === null || _c === void 0 ? void 0 : _c.accessToken) {
110
+ else if ((_b = req.cookies) === null || _b === void 0 ? void 0 : _b.accessToken) {
108
111
  try {
109
112
  const ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ACCESS_TOKEN_SECRET");
110
113
  if (!ACCESS_TOKEN_SECRET) {
@@ -129,11 +132,14 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
129
132
  user = null;
130
133
  }
131
134
  if (user) {
132
- req.user = user;
133
- }
134
- if (((_d = req.user) === null || _d === void 0 ? void 0 : _d.kycStatus) !== common_1.KYCStatus.Approved &&
135
- authorizationTypes.includes(common_1.AuthorizationType.User)) {
136
- throw new common_1.MissingKYCApprovalError();
135
+ if (authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) {
136
+ req.user = user;
137
+ }
138
+ else {
139
+ if (user.kycStatus === common_1.KYCStatus.Approved) {
140
+ req.user = user;
141
+ }
142
+ }
137
143
  }
138
144
  }
139
145
  if (!req.currentAdminAuth &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1216",
3
+ "version": "1.0.1218",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "@aws-sdk/client-s3": "^3.297.0",
27
27
  "@everapi/currencyapi-js": "^1.0.6",
28
28
  "@google-cloud/storage": "^6.9.5",
29
- "@riocrypto/common": "^1.0.1112",
29
+ "@riocrypto/common": "^1.0.1114",
30
30
  "@types/express": "^4.17.13",
31
31
  "axios": "^0.27.2",
32
32
  "ccxt": "^3.0.30",