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