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