@riocrypto/common-server 1.0.1215 → 1.0.1217

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.
@@ -24,6 +24,7 @@ const getUser = (req, userId) => __awaiter(void 0, void 0, void 0, function* ()
24
24
  const User = (0, user_1.buildUser)(mongoose_1.default);
25
25
  const user = yield User.findById(userId);
26
26
  if (req.admin ||
27
+ req.validClusterApiKey ||
27
28
  (user === null || user === void 0 ? void 0 : user.id) === ((_a = req.user) === null || _a === void 0 ? void 0 : _a.id) ||
28
29
  (user === null || user === void 0 ? void 0 : user.brokerId) === ((_b = req.user) === null || _b === void 0 ? void 0 : _b.id)) {
29
30
  return user;
@@ -19,11 +19,12 @@ 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, _c;
25
26
  if (authorizationTypes.includes(common_1.AuthorizationType.Cluster)) {
26
- let apiKey = req.header("x-api-key");
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");
28
29
  if (!CLUSTER_API_KEY) {
29
30
  throw new common_1.SecretManagerError();
@@ -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) {
@@ -131,7 +134,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
131
134
  if (user) {
132
135
  req.user = user;
133
136
  }
134
- if (((_d = req.user) === null || _d === void 0 ? void 0 : _d.kycStatus) !== common_1.KYCStatus.Approved &&
137
+ if (((_c = req.user) === null || _c === void 0 ? void 0 : _c.kycStatus) !== common_1.KYCStatus.Approved &&
135
138
  authorizationTypes.includes(common_1.AuthorizationType.User)) {
136
139
  throw new common_1.MissingKYCApprovalError();
137
140
  }
@@ -21,7 +21,6 @@ interface OrderAttrs {
21
21
  fees: Fees;
22
22
  actualFees?: Fees;
23
23
  price: number;
24
- actualPrice?: number;
25
24
  depositAddress?: string;
26
25
  depositTxId?: string;
27
26
  withdrawalTxId?: string;
@@ -37,7 +36,6 @@ interface OrderAttrs {
37
36
  partner?: Partner;
38
37
  imported?: boolean;
39
38
  managedWallet?: boolean;
40
- amountFixed?: number;
41
39
  exchangeRateOrders?: ExchangeRateOrder[];
42
40
  autoFXDisabled?: boolean;
43
41
  USBankTransferMethod?: "wire" | "ach_push";
@@ -63,7 +61,6 @@ interface OrderDoc extends Document {
63
61
  fees: Fees;
64
62
  actualFees?: Fees;
65
63
  price: number;
66
- actualPrice: number;
67
64
  depositAddress?: string;
68
65
  depositTxId?: string;
69
66
  withdrawalTxId?: string;
@@ -79,7 +76,6 @@ interface OrderDoc extends Document {
79
76
  partner?: Partner;
80
77
  imported?: boolean;
81
78
  managedWallet?: boolean;
82
- amountFixed?: number;
83
79
  exchangeRateOrders?: ExchangeRateOrder[];
84
80
  autoFXDisabled?: boolean;
85
81
  USBankTransferMethod?: "wire" | "ach_push";
@@ -111,9 +111,6 @@ const buildOrder = (mongoose) => {
111
111
  type: Number,
112
112
  required: true,
113
113
  },
114
- actualPrice: {
115
- type: Number,
116
- },
117
114
  brokerId: {
118
115
  type: String,
119
116
  },
@@ -154,9 +151,6 @@ const buildOrder = (mongoose) => {
154
151
  managedWallet: {
155
152
  type: Boolean,
156
153
  },
157
- amountFixed: {
158
- type: Number,
159
- },
160
154
  autoFXDisabled: {
161
155
  type: Boolean,
162
156
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1215",
3
+ "version": "1.0.1217",
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.1111",
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",