@riocrypto/common-server 1.0.1209 → 1.0.1212

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.
package/build/index.d.ts CHANGED
@@ -1,15 +1,10 @@
1
1
  export * from "./middlewares/error-handler";
2
2
  export * from "./middlewares/validate-request";
3
- export * from "./middlewares/current-auth";
4
3
  export * from "./middlewares/require-auth";
5
4
  export * from "./middlewares/verify-admin-api-key";
6
5
  export * from "./middlewares/require-admin-api-key";
7
- export * from "./middlewares/current-admin-auth";
8
- export * from "./middlewares/validate-auth";
9
6
  export * from "./middlewares/get-order";
10
- export * from "./middlewares/get-user";
11
7
  export * from "./middlewares/require-priveleges";
12
- export * from "./middlewares/validate-kyc";
13
8
  export * from "./middlewares/authorize";
14
9
  export * from "./middlewares/not-sandbox";
15
10
  export * from "./services/apiKey";
package/build/index.js CHANGED
@@ -16,16 +16,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./middlewares/error-handler"), exports);
18
18
  __exportStar(require("./middlewares/validate-request"), exports);
19
- __exportStar(require("./middlewares/current-auth"), exports);
20
19
  __exportStar(require("./middlewares/require-auth"), exports);
21
20
  __exportStar(require("./middlewares/verify-admin-api-key"), exports);
22
21
  __exportStar(require("./middlewares/require-admin-api-key"), exports);
23
- __exportStar(require("./middlewares/current-admin-auth"), exports);
24
- __exportStar(require("./middlewares/validate-auth"), exports);
25
22
  __exportStar(require("./middlewares/get-order"), exports);
26
- __exportStar(require("./middlewares/get-user"), exports);
27
23
  __exportStar(require("./middlewares/require-priveleges"), exports);
28
- __exportStar(require("./middlewares/validate-kyc"), exports);
29
24
  __exportStar(require("./middlewares/authorize"), exports);
30
25
  __exportStar(require("./middlewares/not-sandbox"), exports);
31
26
  __exportStar(require("./services/apiKey"), exports);
@@ -1,27 +1,17 @@
1
1
  import { Request, Response, NextFunction } from "express";
2
2
  import { UserDoc } from "../models/user";
3
3
  import { Mongoose } from "mongoose";
4
- import { AuthorizationType } from "@riocrypto/common";
5
- interface AuthPayload {
6
- id: string;
7
- phoneNumber: string;
8
- missing: string[];
9
- }
10
- interface AdminAuthPayload {
11
- id: string;
12
- email: string;
13
- }
4
+ import { AuthorizationType, AuthPayload, AdminAuthPayload } from "@riocrypto/common";
5
+ import { AdminDoc } from "../models/admin";
14
6
  declare global {
15
7
  namespace Express {
16
8
  interface Request {
17
9
  currentAuth?: AuthPayload;
18
10
  currentAdminAuth?: AdminAuthPayload;
19
11
  user?: UserDoc;
20
- validAdminApiKey?: boolean;
12
+ admin?: AdminDoc;
21
13
  validClusterApiKey?: boolean;
22
- session?: any;
23
14
  }
24
15
  }
25
16
  }
26
17
  export declare const authorize: (req: Request, res: Response, next: NextFunction, mongoose: Mongoose, authorizationTypes: AuthorizationType[]) => Promise<void>;
27
- export {};
@@ -19,20 +19,9 @@ 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_auth_1 = require("../models/admin-auth");
22
23
  const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
23
- var _a, _b, _c, _d, _e, _f, _g, _h;
24
- const apiKey = req.header("x-api-key");
25
- let missingKYC = false;
26
- if (authorizationTypes.includes(common_1.AuthorizationType.AdminAPI)) {
27
- let apiKey = req.header("x-api-key");
28
- const ADMIN_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("ADMIN_API_KEY");
29
- if (!ADMIN_API_KEY) {
30
- throw new common_1.SecretManagerError();
31
- }
32
- if (apiKey === ADMIN_API_KEY) {
33
- req.validAdminApiKey = true;
34
- }
35
- }
24
+ var _a, _b, _c, _d;
36
25
  if (authorizationTypes.includes(common_1.AuthorizationType.Cluster)) {
37
26
  let apiKey = req.header("x-api-key");
38
27
  const CLUSTER_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("CLUSTER_API_KEY");
@@ -43,11 +32,58 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
43
32
  req.validClusterApiKey = true;
44
33
  }
45
34
  }
35
+ if (authorizationTypes.includes(common_1.AuthorizationType.AdminAuth) ||
36
+ authorizationTypes.includes(common_1.AuthorizationType.Admin)) {
37
+ const adminApiKey = req.header("x-admin-api-key");
38
+ if (adminApiKey) {
39
+ try {
40
+ const hashedAdminApiKey = yield apiKey_1.ApiKey.toHash(adminApiKey);
41
+ const AdminAuth = yield (0, admin_auth_1.buildAdminAuth)(mongoose);
42
+ const adminAuth = yield AdminAuth.findOne({
43
+ "apiKeys.value": hashedAdminApiKey,
44
+ });
45
+ if (adminAuth) {
46
+ const payload = {
47
+ id: adminAuth.id,
48
+ email: adminAuth.email,
49
+ };
50
+ req.currentAdminAuth = payload;
51
+ }
52
+ }
53
+ catch (err) {
54
+ console.log(err);
55
+ }
56
+ }
57
+ else if ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.adminAccessToken) {
58
+ try {
59
+ const ADMIN_ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ADMIN_ACCESS_TOKEN_SECRET");
60
+ if (!ADMIN_ACCESS_TOKEN_SECRET) {
61
+ throw new Error("Unable to get ADMIN_ACCESS_TOKEN_SECRET");
62
+ }
63
+ const payload = jsonwebtoken_1.default.verify(req.cookies.adminAccessToken, ADMIN_ACCESS_TOKEN_SECRET);
64
+ req.currentAdminAuth = payload;
65
+ }
66
+ catch (err) { }
67
+ }
68
+ }
69
+ if (authorizationTypes.includes(common_1.AuthorizationType.Admin)) {
70
+ if ((_b = req.cookies) === null || _b === void 0 ? void 0 : _b.adminAccessToken) {
71
+ 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;
78
+ }
79
+ catch (err) {
80
+ console.log(err);
81
+ }
82
+ }
83
+ }
46
84
  if (authorizationTypes.includes(common_1.AuthorizationType.Auth) ||
47
85
  authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC) ||
48
- authorizationTypes.includes(common_1.AuthorizationType.User) ||
49
- authorizationTypes.includes(common_1.AuthorizationType.UserOptional) ||
50
- authorizationTypes.includes(common_1.AuthorizationType.Broker)) {
86
+ authorizationTypes.includes(common_1.AuthorizationType.User)) {
51
87
  const apiKey = req.header("x-api-key");
52
88
  if (apiKey) {
53
89
  try {
@@ -57,17 +93,9 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
57
93
  "apiKeys.value": hashedApiKey,
58
94
  });
59
95
  if (auth) {
60
- const missing = [];
61
- if (!auth.password) {
62
- missing.push("password");
63
- }
64
- if (!auth.securityAnswer || !auth.securityQuestion) {
65
- missing.push("securityQuestion");
66
- }
67
96
  const payload = {
68
97
  id: auth.id,
69
98
  phoneNumber: auth.phoneNumber,
70
- missing,
71
99
  };
72
100
  req.currentAuth = payload;
73
101
  }
@@ -76,7 +104,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
76
104
  console.log(err);
77
105
  }
78
106
  }
79
- else if ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.accessToken) {
107
+ else if ((_c = req.cookies) === null || _c === void 0 ? void 0 : _c.accessToken) {
80
108
  try {
81
109
  const ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ACCESS_TOKEN_SECRET");
82
110
  if (!ACCESS_TOKEN_SECRET) {
@@ -87,38 +115,14 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
87
115
  }
88
116
  catch (err) { }
89
117
  }
90
- if (!authorizationTypes.includes(common_1.AuthorizationType.UserOptional)) {
91
- if ((_c = (_b = req.currentAuth) === null || _b === void 0 ? void 0 : _b.missing) === null || _c === void 0 ? void 0 : _c.includes("password")) {
92
- throw new common_1.MissingPasswordError();
93
- }
94
- if ((_e = (_d = req.currentAuth) === null || _d === void 0 ? void 0 : _d.missing) === null || _e === void 0 ? void 0 : _e.includes("securityQuestion")) {
95
- throw new common_1.MissingSecurityQuestionError();
96
- }
97
- }
98
- }
99
- if (authorizationTypes.includes(common_1.AuthorizationType.Admin) ||
100
- authorizationTypes.includes(common_1.AuthorizationType.AdminOptional)) {
101
- if ((_f = req.cookies) === null || _f === void 0 ? void 0 : _f.adminAccessToken) {
102
- try {
103
- const ADMIN_ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ADMIN_ACCESS_TOKEN_SECRET");
104
- if (!ADMIN_ACCESS_TOKEN_SECRET) {
105
- throw new Error("Unable to get ADMIN_ACCESS_TOKEN_SECRET");
106
- }
107
- const payload = jsonwebtoken_1.default.verify(req.cookies.adminAccessToken, ADMIN_ACCESS_TOKEN_SECRET);
108
- req.currentAdminAuth = payload;
109
- }
110
- catch (err) {
111
- console.log(err);
112
- }
113
- }
114
118
  }
115
- if (authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) {
119
+ if (authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC) ||
120
+ authorizationTypes.includes(common_1.AuthorizationType.User)) {
116
121
  let user;
117
122
  try {
118
123
  const User = yield (0, user_1.buildUser)(mongoose);
119
124
  user = yield User.findOne({
120
125
  authIds: { $in: [req.currentAuth.id] },
121
- attributes: { $ne: common_1.UserAttribute.deleted },
122
126
  });
123
127
  }
124
128
  catch (err) {
@@ -127,96 +131,19 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
127
131
  if (user) {
128
132
  req.user = user;
129
133
  }
130
- }
131
- if (authorizationTypes.includes(common_1.AuthorizationType.User) ||
132
- authorizationTypes.includes(common_1.AuthorizationType.UserOptional)) {
133
- let user;
134
- try {
135
- const User = yield (0, user_1.buildUser)(mongoose);
136
- user = yield User.findOne({
137
- authIds: { $in: [req.currentAuth.id] },
138
- attributes: { $ne: common_1.UserAttribute.deleted },
139
- });
140
- if (!user) {
141
- throw new Error();
142
- }
143
- if ((user === null || user === void 0 ? void 0 : user.kycStatus) !== common_1.KYCStatus.Approved) {
144
- missingKYC = true;
145
- throw new Error();
146
- }
147
- }
148
- catch (err) {
149
- user = null;
150
- }
151
- if (user) {
152
- req.user = user;
153
- }
154
- }
155
- if (authorizationTypes.includes(common_1.AuthorizationType.Broker)) {
156
- let brokerUser;
157
- try {
158
- const User = yield (0, user_1.buildUser)(mongoose);
159
- brokerUser = yield User.findOne({
160
- authIds: { $in: [req.currentAuth.id] },
161
- attributes: { $in: [common_1.UserAttribute.broker] },
162
- });
163
- if (!brokerUser) {
164
- throw new Error();
165
- }
166
- if ((brokerUser === null || brokerUser === void 0 ? void 0 : brokerUser.kycStatus) !== common_1.KYCStatus.Approved) {
167
- missingKYC = true;
168
- throw new Error();
169
- }
170
- }
171
- catch (err) {
172
- brokerUser = null;
173
- }
174
- const user = brokerUser;
175
- if (user) {
176
- req.user = user;
134
+ if (((_d = req.user) === null || _d === void 0 ? void 0 : _d.kycStatus) !== common_1.KYCStatus.Approved &&
135
+ authorizationTypes.includes(common_1.AuthorizationType.User)) {
136
+ throw new common_1.MissingKYCApprovalError();
177
137
  }
178
138
  }
179
- if (
180
- // if no auth
181
- (!req.currentAdminAuth &&
139
+ if (!req.currentAdminAuth &&
140
+ !req.admin &&
182
141
  !req.currentAuth &&
183
142
  !req.user &&
184
- !req.validAdminApiKey &&
185
- !req.validClusterApiKey &&
186
- !authorizationTypes.includes(common_1.AuthorizationType.Public)) ||
187
- (!req.currentAuth &&
188
- !authorizationTypes.includes(common_1.AuthorizationType.Auth) &&
189
- !req.user &&
190
- !req.validAdminApiKey &&
191
- !req.validClusterApiKey &&
192
- !authorizationTypes.includes(common_1.AuthorizationType.Public))) {
193
- if (!req.user &&
194
- authorizationTypes.includes(common_1.AuthorizationType.UserOptional)) {
195
- next();
196
- return;
197
- }
198
- if (req.currentAdminAuth &&
199
- authorizationTypes.includes(common_1.AuthorizationType.Admin)) {
200
- next();
201
- return;
202
- }
203
- if (missingKYC) {
204
- throw new common_1.MissingKYCApprovalError();
205
- }
206
- if ((authorizationTypes.includes(common_1.AuthorizationType.User) ||
207
- authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) &&
208
- ((_g = req.cookies) === null || _g === void 0 ? void 0 : _g.accessToken)) {
209
- throw new common_1.MissingUserError();
210
- }
211
- if (authorizationTypes.includes(common_1.AuthorizationType.Admin) &&
212
- authorizationTypes.length === 1 &&
213
- ((_h = req.cookies) === null || _h === void 0 ? void 0 : _h.accessToken)) {
214
- throw new common_1.AdminOnlyError();
215
- }
216
- if (!req.user && authorizationTypes.includes(common_1.AuthorizationType.Broker)) {
217
- throw new common_1.NotBrokerError();
143
+ !req.validClusterApiKey) {
144
+ if (!authorizationTypes.includes(common_1.AuthorizationType.Public)) {
145
+ throw new common_1.NotAuthorizedError();
218
146
  }
219
- throw new common_1.NotAuthorizedError();
220
147
  }
221
148
  next();
222
149
  });
@@ -2,7 +2,7 @@ import { APIKey, SecurityQuestion } from "@riocrypto/common";
2
2
  import { Mongoose, Model, Document } from "mongoose";
3
3
  interface AuthAttrs {
4
4
  phoneNumber: string;
5
- password?: string;
5
+ password: string;
6
6
  securityQuestion?: SecurityQuestion;
7
7
  securityAnswer?: string;
8
8
  previousPasswords?: string[];
@@ -11,7 +11,7 @@ interface AuthAttrs {
11
11
  }
12
12
  interface AuthDoc extends Document {
13
13
  phoneNumber: string;
14
- password?: string;
14
+ password: string;
15
15
  securityQuestion?: SecurityQuestion;
16
16
  securityAnswer?: string;
17
17
  previousPasswords?: string[];
@@ -23,6 +23,7 @@ const buildAuth = (mongoose) => {
23
23
  },
24
24
  password: {
25
25
  type: String,
26
+ required: true,
26
27
  },
27
28
  securityQuestion: {
28
29
  type: String,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1209",
3
+ "version": "1.0.1212",
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.1097",
29
+ "@riocrypto/common": "^1.0.1109",
30
30
  "@types/express": "^4.17.13",
31
31
  "axios": "^0.27.2",
32
32
  "ccxt": "^3.0.30",
@@ -1,15 +0,0 @@
1
- import { Request, Response, NextFunction } from "express";
2
- interface AuthPayload {
3
- id: string;
4
- email: string;
5
- }
6
- declare global {
7
- namespace Express {
8
- interface Request {
9
- currentAdminAuth?: AuthPayload;
10
- session?: any;
11
- }
12
- }
13
- }
14
- export declare const currentAdminAuth: (req: Request, res: Response, next: NextFunction) => Promise<void>;
15
- export {};
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.currentAdminAuth = void 0;
16
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
17
- const secret_manager_client_1 = require("../clients/secret-manager-client");
18
- const common_1 = require("@riocrypto/common");
19
- const currentAdminAuth = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
20
- var _a;
21
- if (!((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.adminAccesToken)) {
22
- return next();
23
- }
24
- try {
25
- const ADMIN_ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ADMIN_ACCESS_TOKEN_SECRET");
26
- if (!ADMIN_ACCESS_TOKEN_SECRET) {
27
- throw new common_1.SecretManagerError();
28
- }
29
- const payload = jsonwebtoken_1.default.verify(req.cookies.adminAccesToken, ADMIN_ACCESS_TOKEN_SECRET);
30
- req.currentAdminAuth = payload;
31
- }
32
- catch (err) { }
33
- next();
34
- });
35
- exports.currentAdminAuth = currentAdminAuth;
@@ -1,16 +0,0 @@
1
- import { Request, Response, NextFunction } from "express";
2
- interface AuthPayload {
3
- id: string;
4
- phoneNumber: string;
5
- missing: string[];
6
- }
7
- declare global {
8
- namespace Express {
9
- interface Request {
10
- currentAuth?: AuthPayload;
11
- session?: any;
12
- }
13
- }
14
- }
15
- export declare const currentAuth: (req: Request, res: Response, next: NextFunction) => Promise<void>;
16
- export {};
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.currentAuth = void 0;
16
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
17
- const secret_manager_client_1 = require("../clients/secret-manager-client");
18
- const common_1 = require("@riocrypto/common");
19
- const currentAuth = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
20
- var _a;
21
- if (!((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.accessToken)) {
22
- return next();
23
- }
24
- try {
25
- const ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ACCESS_TOKEN_SECRET");
26
- if (!ACCESS_TOKEN_SECRET) {
27
- throw new common_1.SecretManagerError();
28
- }
29
- const payload = jsonwebtoken_1.default.verify(req.cookies.accessToken, ACCESS_TOKEN_SECRET);
30
- req.currentAuth = payload;
31
- }
32
- catch (err) { }
33
- next();
34
- });
35
- exports.currentAuth = currentAuth;
@@ -1,11 +0,0 @@
1
- import { Request, Response, NextFunction } from "express";
2
- import { UserDoc } from "../models/user";
3
- import { Mongoose } from "mongoose";
4
- declare global {
5
- namespace Express {
6
- interface Request {
7
- user?: UserDoc;
8
- }
9
- }
10
- }
11
- export declare const getUser: (req: Request, res: Response, next: NextFunction, mongoose: Mongoose) => Promise<void>;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getUser = void 0;
13
- const user_1 = require("../models/user");
14
- const common_1 = require("@riocrypto/common");
15
- const getUser = (req, res, next, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
16
- let user;
17
- try {
18
- const User = yield (0, user_1.buildUser)(mongoose);
19
- user = yield User.findOne({
20
- phoneNumber: req.currentAuth.phoneNumber,
21
- attributes: { $ne: common_1.UserAttribute.deleted },
22
- });
23
- }
24
- catch (err) {
25
- user = null;
26
- }
27
- if (user) {
28
- req.user = user;
29
- }
30
- next();
31
- });
32
- exports.getUser = getUser;
@@ -1,2 +0,0 @@
1
- import { Request, Response, NextFunction } from "express";
2
- export declare const validateAuth: (req: Request, res: Response, next: NextFunction) => Promise<void>;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.validateAuth = void 0;
13
- const common_1 = require("@riocrypto/common");
14
- const validateAuth = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
15
- const auth = req.currentAuth;
16
- if (auth) {
17
- if (auth.missing.includes("password")) {
18
- throw new common_1.MissingPasswordError();
19
- }
20
- if (auth.missing.includes("securityQuestion")) {
21
- throw new common_1.MissingSecurityQuestionError();
22
- }
23
- if (auth.missing.includes("securityAnswer")) {
24
- throw new common_1.MissingSecurityQuestionError();
25
- }
26
- }
27
- next();
28
- });
29
- exports.validateAuth = validateAuth;
@@ -1,2 +0,0 @@
1
- import { Request, Response, NextFunction } from "express";
2
- export declare const validateKYC: (req: Request, res: Response, next: NextFunction) => Promise<void>;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.validateKYC = void 0;
13
- const common_1 = require("@riocrypto/common");
14
- const validateKYC = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
15
- const user = req.user;
16
- if (!user || user.kycStatus !== common_1.KYCStatus.Approved) {
17
- throw new common_1.MissingKYCApprovalError();
18
- }
19
- next();
20
- });
21
- exports.validateKYC = validateKYC;