@riocrypto/common-server 1.0.1819 → 1.0.1821

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