@riocrypto/common-server 1.0.1819 → 1.0.1820

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.
@@ -22,125 +22,87 @@ const secret_manager_client_1 = require("../clients/secret-manager-client");
22
22
  const admin_auth_1 = require("../models/admin-auth");
23
23
  const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
24
24
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
25
- console.log("Checkpoint A.1.1: ", new Date().getTime());
26
25
  if (authorizationTypes.includes(common_1.AuthorizationType.GenesisAdmin) &&
27
26
  req.header("x-genesis-api-key")) {
28
- console.log("Checkpoint A.1.2: ", new Date().getTime());
29
27
  let apiKey = req.header("x-genesis-api-key");
30
- console.log("Checkpoint A.1.3: ", new Date().getTime());
31
28
  const GENESIS_ADMIN_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("GENESIS_ADMIN_KEY");
32
- console.log("Checkpoint A.1.4: ", new Date().getTime());
33
29
  if (!GENESIS_ADMIN_KEY) {
34
30
  throw new common_1.SecretManagerError();
35
31
  }
36
32
  if (apiKey === GENESIS_ADMIN_KEY) {
37
33
  req.validGenisisAdminKey = true;
38
34
  }
39
- console.log("Checkpoint A.1.5: ", new Date().getTime());
40
35
  }
41
- console.log("Checkpoint A.1.6: ", new Date().getTime());
42
36
  if (authorizationTypes.includes(common_1.AuthorizationType.Cluster) &&
43
37
  req.header("x-cluster-api-key")) {
44
- console.log("Checkpoint A.1.7: ", new Date().getTime());
45
38
  let apiKey = req.header("x-cluster-api-key");
46
- console.log("Checkpoint A.1.8: ", new Date().getTime());
47
39
  const CLUSTER_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("CLUSTER_API_KEY");
48
- console.log("Checkpoint A.1.9: ", new Date().getTime());
49
40
  if (!CLUSTER_API_KEY) {
50
41
  throw new common_1.SecretManagerError();
51
42
  }
52
43
  if (apiKey === CLUSTER_API_KEY) {
53
44
  req.validClusterApiKey = true;
54
45
  }
55
- console.log("Checkpoint A.1.9.1: ", new Date().getTime());
56
46
  }
57
- console.log("Checkpoint A.1.9.2: ", new Date().getTime());
58
47
  if (authorizationTypes.includes(common_1.AuthorizationType.AdminAuth) &&
59
48
  req.header("x-admin-api-key")) {
60
- console.log("Checkpoint A.1.9.3: ", new Date().getTime());
61
49
  const adminApiKey = req.header("x-admin-api-key");
62
- console.log("Checkpoint A.1.9.4: ", new Date().getTime());
63
50
  const AdminAuth = yield (0, admin_auth_1.buildAdminAuth)(mongoose);
64
- console.log("Checkpoint A.1.9.5: ", new Date().getTime());
65
51
  if (adminApiKey) {
66
52
  try {
67
53
  const hashedAdminApiKey = yield apiKey_1.ApiKey.toHash(adminApiKey);
68
- console.log("Checkpoint A.1.9.6: ", new Date().getTime());
69
54
  const adminAuth = yield AdminAuth.findOne({
70
55
  "apiKeys.value": hashedAdminApiKey,
71
56
  });
72
- console.log("Checkpoint A.1.9.7: ", new Date().getTime());
73
57
  if (adminAuth) {
74
58
  req.adminAuth = adminAuth;
75
59
  }
76
- console.log("Checkpoint A.1.9.8: ", new Date().getTime());
77
60
  }
78
61
  catch (err) {
79
62
  console.log(err);
80
63
  }
81
- console.log("Checkpoint A.1.9.9: ", new Date().getTime());
82
64
  }
83
65
  else if ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.adminAccessToken) {
84
- console.log("Checkpoint A.1.9.9.1: ", new Date().getTime());
85
66
  try {
86
67
  const ADMIN_ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ADMIN_ACCESS_TOKEN_SECRET");
87
- console.log("Checkpoint A.1.9.9.2: ", new Date().getTime());
88
68
  if (!ADMIN_ACCESS_TOKEN_SECRET) {
89
69
  throw new Error("Unable to get ADMIN_ACCESS_TOKEN_SECRET");
90
70
  }
91
- console.log("Checkpoint A.1.9.9.3: ", new Date().getTime());
92
71
  const payload = jsonwebtoken_1.default.verify(req.cookies.adminAccessToken, ADMIN_ACCESS_TOKEN_SECRET);
93
- console.log("Checkpoint A.1.9.9.4: ", new Date().getTime());
94
72
  const adminAuth = yield AdminAuth.findById(payload.id);
95
- console.log("Checkpoint A.1.9.9.5: ", new Date().getTime());
96
73
  if (adminAuth) {
97
74
  req.adminAuth = adminAuth;
98
75
  }
99
- console.log("Checkpoint A.1.9.9.6: ", new Date().getTime());
100
76
  }
101
77
  catch (err) { }
102
78
  }
103
79
  }
104
- console.log("Checkpoint A.1.9.9.7: ", new Date().getTime());
105
80
  if (authorizationTypes.includes(common_1.AuthorizationType.Auth) ||
106
81
  authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC) ||
107
82
  authorizationTypes.includes(common_1.AuthorizationType.User)) {
108
- console.log("Checkpoint A.1.9.9.8: ", new Date().getTime());
109
83
  const apiKey = req.header("x-api-key");
110
- console.log("Checkpoint A.1.9.9.9: ", new Date().getTime());
111
84
  if (apiKey) {
112
- console.log("Checkpoint A.1.9.9.9.1: ", new Date().getTime());
113
85
  const Auth = yield (0, auth_1.buildAuth)(mongoose);
114
- console.log("Checkpoint A.1.9.9.9.2: ", new Date().getTime());
115
86
  try {
116
87
  const hashedApiKey = yield apiKey_1.ApiKey.toHash(apiKey);
117
- console.log("Checkpoint A.1.9.9.9.3: ", new Date().getTime());
118
88
  const auth = yield Auth.findOne({
119
89
  "apiKeys.value": hashedApiKey,
120
90
  });
121
- console.log("Checkpoint A.1.9.9.9.4: ", new Date().getTime());
122
91
  if (auth) {
123
92
  req.auth = auth;
124
93
  }
125
- console.log("Checkpoint A.1.9.9.9.5: ", new Date().getTime());
126
94
  }
127
95
  catch (err) { }
128
96
  }
129
97
  else if ((_b = req.cookies) === null || _b === void 0 ? void 0 : _b.accessToken) {
130
- console.log("Checkpoint A.1.9.9.9.6: ", new Date().getTime());
131
98
  const Auth = yield (0, auth_1.buildAuth)(mongoose);
132
- console.log("Checkpoint A.1.9.9.9.7: ", new Date().getTime());
133
99
  try {
134
100
  const ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ACCESS_TOKEN_SECRET");
135
- console.log("Checkpoint A.1.9.9.9.8: ", new Date().getTime());
136
101
  if (!ACCESS_TOKEN_SECRET) {
137
102
  throw new common_1.SecretManagerError();
138
103
  }
139
- console.log("Checkpoint A.1.9.9.9.9: ", new Date().getTime());
140
104
  const payload = jsonwebtoken_1.default.verify(req.cookies.accessToken, ACCESS_TOKEN_SECRET);
141
- console.log("Checkpoint A.1.9.9.9.9.1: ", new Date().getTime());
142
105
  const auth = yield Auth.findById(payload.id);
143
- console.log("Checkpoint A.1.9.9.9.9.2: ", new Date().getTime());
144
106
  if (auth) {
145
107
  req.auth = auth;
146
108
  }
@@ -148,17 +110,14 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
148
110
  catch (err) { }
149
111
  }
150
112
  }
151
- console.log("Checkpoint A.1.9.9.9.9.3: ", new Date().getTime());
152
113
  if (authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC) ||
153
114
  authorizationTypes.includes(common_1.AuthorizationType.User)) {
154
- console.log("Checkpoint A.1.9.9.9.9.4: ", new Date().getTime());
155
115
  if (req.auth) {
156
116
  try {
157
117
  const User = yield (0, user_1.buildUser)(mongoose);
158
118
  const user = yield User.findOne({
159
119
  authIds: { $in: [(_c = req.auth) === null || _c === void 0 ? void 0 : _c.id] },
160
120
  });
161
- console.log("Checkpoint A.1.9.9.9.9.5: ", new Date().getTime());
162
121
  if (user) {
163
122
  if (authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) {
164
123
  req.user = user;
@@ -175,7 +134,6 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
175
134
  catch (err) { }
176
135
  }
177
136
  }
178
- console.log("Checkpoint A.1.9.9.9.9.6: ", new Date().getTime());
179
137
  if (authorizationTypes.includes(common_1.AuthorizationType.Public)) {
180
138
  next();
181
139
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1819",
3
+ "version": "1.0.1820",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",