@riocrypto/common 1.0.504 → 1.0.506
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 +0 -41
- package/build/index.js +0 -41
- package/package.json +2 -2
- package/build/clients/bitstamp-client.d.ts +0 -16
- package/build/clients/bitstamp-client.js +0 -83
- package/build/clients/ccxt-client.d.ts +0 -48
- package/build/clients/ccxt-client.js +0 -201
- package/build/clients/etherscan-client.d.ts +0 -6
- package/build/clients/etherscan-client.js +0 -24
- package/build/clients/fireblocks-client.d.ts +0 -15
- package/build/clients/fireblocks-client.js +0 -140
- package/build/clients/fixer-client.d.ts +0 -8
- package/build/clients/fixer-client.js +0 -34
- package/build/clients/gueno-client.d.ts +0 -10
- package/build/clients/gueno-client.js +0 -44
- package/build/clients/kapstar-client.d.ts +0 -6
- package/build/clients/kapstar-client.js +0 -26
- package/build/clients/kushki-client.d.ts +0 -14
- package/build/clients/kushki-client.js +0 -150
- package/build/clients/rio-client.d.ts +0 -82
- package/build/clients/rio-client.js +0 -315
- package/build/clients/slack-client.d.ts +0 -7
- package/build/clients/slack-client.js +0 -34
- package/build/helpers/get-user-from-client-helper.d.ts +0 -4
- package/build/helpers/get-user-from-client-helper.js +0 -41
- package/build/helpers/get-user-helper.d.ts +0 -4
- package/build/helpers/get-user-helper.js +0 -35
- package/build/middlewares/authorize.d.ts +0 -28
- package/build/middlewares/authorize.js +0 -195
- package/build/middlewares/current-admin-auth.d.ts +0 -15
- package/build/middlewares/current-admin-auth.js +0 -20
- package/build/middlewares/current-auth.d.ts +0 -16
- package/build/middlewares/current-auth.js +0 -20
- package/build/middlewares/error-handler.d.ts +0 -2
- package/build/middlewares/error-handler.js +0 -14
- package/build/middlewares/get-order.d.ts +0 -11
- package/build/middlewares/get-order.js +0 -57
- package/build/middlewares/get-partner.d.ts +0 -10
- package/build/middlewares/get-partner.js +0 -41
- package/build/middlewares/get-user.d.ts +0 -12
- package/build/middlewares/get-user.js +0 -45
- package/build/middlewares/require-admin-api-key.d.ts +0 -2
- package/build/middlewares/require-admin-api-key.js +0 -11
- package/build/middlewares/require-auth.d.ts +0 -2
- package/build/middlewares/require-auth.js +0 -11
- package/build/middlewares/require-priveleges.d.ts +0 -2
- package/build/middlewares/require-priveleges.js +0 -15
- package/build/middlewares/validate-auth.d.ts +0 -2
- package/build/middlewares/validate-auth.js +0 -30
- package/build/middlewares/validate-kyc.d.ts +0 -2
- package/build/middlewares/validate-kyc.js +0 -30
- package/build/middlewares/validate-order.d.ts +0 -0
- package/build/middlewares/validate-order.js +0 -20
- package/build/middlewares/validate-request.d.ts +0 -2
- package/build/middlewares/validate-request.js +0 -13
- package/build/middlewares/verify-admin-api-key.d.ts +0 -9
- package/build/middlewares/verify-admin-api-key.js +0 -11
- package/build/models/admin-auth.d.ts +0 -16
- package/build/models/admin-auth.js +0 -59
- package/build/models/auth.d.ts +0 -24
- package/build/models/auth.js +0 -83
- package/build/models/bank-payout.d.ts +0 -20
- package/build/models/bank-payout.js +0 -44
- package/build/models/business-user.d.ts +0 -57
- package/build/models/business-user.js +0 -111
- package/build/models/ccxt-order.d.ts +0 -16
- package/build/models/ccxt-order.js +0 -37
- package/build/models/checked-address.d.ts +0 -17
- package/build/models/checked-address.js +0 -37
- package/build/models/kushki-payment.d.ts +0 -16
- package/build/models/kushki-payment.js +0 -37
- package/build/models/kyc.d.ts +0 -20
- package/build/models/kyc.js +0 -45
- package/build/models/order.d.ts +0 -67
- package/build/models/order.js +0 -123
- package/build/models/partner.d.ts +0 -35
- package/build/models/partner.js +0 -69
- package/build/models/rio-settings.d.ts +0 -12
- package/build/models/rio-settings.js +0 -29
- package/build/models/user.d.ts +0 -53
- package/build/models/user.js +0 -94
- package/build/services/apiKey.d.ts +0 -3
- package/build/services/apiKey.js +0 -24
- package/build/services/password.d.ts +0 -4
- package/build/services/password.js +0 -32
- package/build/services/s3.d.ts +0 -5
- package/build/services/s3.js +0 -21
- package/build/types.d.ts +0 -93
- package/build/types.js +0 -109
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.currentAdminAuth = void 0;
|
|
7
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
-
const currentAdminAuth = (req, res, next) => {
|
|
9
|
-
var _a;
|
|
10
|
-
if (!((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.adminJwt)) {
|
|
11
|
-
return next();
|
|
12
|
-
}
|
|
13
|
-
try {
|
|
14
|
-
const payload = jsonwebtoken_1.default.verify(req.cookies.adminJwt, process.env.JWT_KEY_ADMIN);
|
|
15
|
-
req.currentAdminAuth = payload;
|
|
16
|
-
}
|
|
17
|
-
catch (err) { }
|
|
18
|
-
next();
|
|
19
|
-
};
|
|
20
|
-
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) => void;
|
|
16
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.currentAuth = void 0;
|
|
7
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
-
const currentAuth = (req, res, next) => {
|
|
9
|
-
var _a;
|
|
10
|
-
if (!((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.jwt)) {
|
|
11
|
-
return next();
|
|
12
|
-
}
|
|
13
|
-
try {
|
|
14
|
-
const payload = jsonwebtoken_1.default.verify(req.cookies.jwt, process.env.JWT_KEY);
|
|
15
|
-
req.currentAuth = payload;
|
|
16
|
-
}
|
|
17
|
-
catch (err) { }
|
|
18
|
-
next();
|
|
19
|
-
};
|
|
20
|
-
exports.currentAuth = currentAuth;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.errorHandler = void 0;
|
|
4
|
-
const custom_error_1 = require("../errors/custom-error");
|
|
5
|
-
const errorHandler = (err, req, res, next) => {
|
|
6
|
-
if (err instanceof custom_error_1.CustomError) {
|
|
7
|
-
return res.status(err.statusCode).send({ errors: err.serializeErrors() });
|
|
8
|
-
}
|
|
9
|
-
console.error(err);
|
|
10
|
-
res.status(400).send({
|
|
11
|
-
errors: [{ message: "Something went wrong" }],
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
exports.errorHandler = errorHandler;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
import { Mongoose } from "mongoose";
|
|
3
|
-
import { OrderDoc } from "../models/order";
|
|
4
|
-
declare global {
|
|
5
|
-
namespace Express {
|
|
6
|
-
interface Request {
|
|
7
|
-
order?: OrderDoc;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export declare const getOrder: (req: Request, res: Response, next: NextFunction, mongoose: Mongoose, onlyBankOrders?: boolean) => Promise<void>;
|
|
@@ -1,57 +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.getOrder = void 0;
|
|
13
|
-
const not_authorized_error_1 = require("../errors/not-authorized-error");
|
|
14
|
-
const wrong_processor_error_1 = require("../errors/wrong-processor-error");
|
|
15
|
-
const order_1 = require("../models/order");
|
|
16
|
-
const processor_1 = require("../types/processor");
|
|
17
|
-
const getOrder = (req, res, next, mongoose, onlyBankOrders) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
var _a;
|
|
19
|
-
let orderId = "";
|
|
20
|
-
if (req.body.orderId) {
|
|
21
|
-
orderId = req.body.orderId;
|
|
22
|
-
}
|
|
23
|
-
else if (req.params.orderId) {
|
|
24
|
-
orderId = req.params.orderId;
|
|
25
|
-
}
|
|
26
|
-
else if (req.query.orderId) {
|
|
27
|
-
orderId = req.query.orderId;
|
|
28
|
-
}
|
|
29
|
-
if (orderId) {
|
|
30
|
-
const Order = yield (0, order_1.buildOrder)(mongoose);
|
|
31
|
-
const order = yield Order.findById(orderId);
|
|
32
|
-
if (!order) {
|
|
33
|
-
throw new Error();
|
|
34
|
-
}
|
|
35
|
-
if (onlyBankOrders) {
|
|
36
|
-
if ([
|
|
37
|
-
processor_1.Processor.Interbank,
|
|
38
|
-
processor_1.Processor.SPEI,
|
|
39
|
-
processor_1.Processor.SWIFT,
|
|
40
|
-
processor_1.Processor.SPID,
|
|
41
|
-
].includes(order.processor)) {
|
|
42
|
-
req.order = order;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
throw new wrong_processor_error_1.WrongProcessorError();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
req.order = order;
|
|
50
|
-
}
|
|
51
|
-
if (req.order.userId !== ((_a = req.user) === null || _a === void 0 ? void 0 : _a.toJSON().id) && !req.currentAdminAuth) {
|
|
52
|
-
throw new not_authorized_error_1.NotAuthorizedError();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
next();
|
|
56
|
-
});
|
|
57
|
-
exports.getOrder = getOrder;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
import { Mongoose } from "mongoose";
|
|
3
|
-
declare global {
|
|
4
|
-
namespace Express {
|
|
5
|
-
interface Request {
|
|
6
|
-
partnerId?: string;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export declare const getPartner: (req: Request, res: Response, next: NextFunction, mongoose: Mongoose) => Promise<void>;
|
|
@@ -1,41 +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.getPartner = void 0;
|
|
16
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
17
|
-
const partner_1 = require("../models/partner");
|
|
18
|
-
const apiKey_1 = require("../services/apiKey");
|
|
19
|
-
const getPartner = (req, res, next, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
try {
|
|
21
|
-
if (!req.headers["x-api-key"]) {
|
|
22
|
-
const payload = jsonwebtoken_1.default.verify(req.cookies.partnerAuthJwt, process.env.JWT_KEY_PARTNER);
|
|
23
|
-
req.partnerId = payload.partnerId;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
const hashedApiKey = yield apiKey_1.ApiKey.toHash(req.headers["x-api-key"]);
|
|
27
|
-
const Partner = yield (0, partner_1.buildPartner)(mongoose);
|
|
28
|
-
const partner = yield Partner.findOne({
|
|
29
|
-
apiKeys: { $elemMatch: { value: hashedApiKey } },
|
|
30
|
-
});
|
|
31
|
-
if (partner) {
|
|
32
|
-
req.partnerId = partner._id.valueOf();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
next();
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
next();
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
exports.getPartner = getPartner;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
import { BusinessUserDoc } from "../models/business-user";
|
|
3
|
-
import { UserDoc } from "../models/user";
|
|
4
|
-
import { Mongoose } from "mongoose";
|
|
5
|
-
declare global {
|
|
6
|
-
namespace Express {
|
|
7
|
-
interface Request {
|
|
8
|
-
user?: UserDoc | BusinessUserDoc;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export declare const getUser: (req: Request, res: Response, next: NextFunction, mongoose: Mongoose) => Promise<void>;
|
|
@@ -1,45 +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 business_user_1 = require("../models/business-user");
|
|
14
|
-
const user_1 = require("../models/user");
|
|
15
|
-
const user_attribute_1 = require("../types/user-attribute");
|
|
16
|
-
const getUser = (req, res, next, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
let individualUser;
|
|
18
|
-
let businessUser;
|
|
19
|
-
try {
|
|
20
|
-
const User = yield (0, user_1.buildUser)(mongoose);
|
|
21
|
-
individualUser = yield User.findOne({
|
|
22
|
-
phoneNumber: req.currentAuth.phoneNumber,
|
|
23
|
-
attributes: { $ne: user_attribute_1.UserAttribute.deleted },
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
catch (err) {
|
|
27
|
-
individualUser = null;
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
const BusinessUser = yield (0, business_user_1.buildBusinessUser)(mongoose);
|
|
31
|
-
businessUser = yield BusinessUser.findOne({
|
|
32
|
-
phoneNumber: req.currentAuth.phoneNumber,
|
|
33
|
-
attributes: { $ne: user_attribute_1.UserAttribute.deleted },
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
catch (err) {
|
|
37
|
-
businessUser = null;
|
|
38
|
-
}
|
|
39
|
-
const user = individualUser || businessUser;
|
|
40
|
-
if (user) {
|
|
41
|
-
req.user = user;
|
|
42
|
-
}
|
|
43
|
-
next();
|
|
44
|
-
});
|
|
45
|
-
exports.getUser = getUser;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requireAdminApiKey = void 0;
|
|
4
|
-
const not_authorized_error_1 = require("../errors/not-authorized-error");
|
|
5
|
-
const requireAdminApiKey = (req, res, next) => {
|
|
6
|
-
if (!req.validAdminApiKey) {
|
|
7
|
-
throw new not_authorized_error_1.NotAuthorizedError();
|
|
8
|
-
}
|
|
9
|
-
next();
|
|
10
|
-
};
|
|
11
|
-
exports.requireAdminApiKey = requireAdminApiKey;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requireAuth = void 0;
|
|
4
|
-
const not_authorized_error_1 = require("../errors/not-authorized-error");
|
|
5
|
-
const requireAuth = (req, res, next) => {
|
|
6
|
-
if (!req.currentAuth) {
|
|
7
|
-
throw new not_authorized_error_1.NotAuthorizedError();
|
|
8
|
-
}
|
|
9
|
-
next();
|
|
10
|
-
};
|
|
11
|
-
exports.requireAuth = requireAuth;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requirePriveleges = void 0;
|
|
4
|
-
const missing_user_error_1 = require("../errors/missing-user-error");
|
|
5
|
-
const not_authorized_error_1 = require("../errors/not-authorized-error");
|
|
6
|
-
const requirePriveleges = (req, res, next) => {
|
|
7
|
-
if (req.currentAuth && !req.user) {
|
|
8
|
-
throw new missing_user_error_1.MissingUserError();
|
|
9
|
-
}
|
|
10
|
-
if (!req.partnerId && !req.user && !req.currentAdminAuth) {
|
|
11
|
-
throw new not_authorized_error_1.NotAuthorizedError();
|
|
12
|
-
}
|
|
13
|
-
next();
|
|
14
|
-
};
|
|
15
|
-
exports.requirePriveleges = requirePriveleges;
|
|
@@ -1,30 +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 missing_password_error_1 = require("../errors/missing-password-error");
|
|
14
|
-
const missing_security_question_error_1 = require("../errors/missing-security-question-error");
|
|
15
|
-
const validateAuth = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const auth = req.currentAuth;
|
|
17
|
-
if (auth) {
|
|
18
|
-
if (auth.missing.includes("password")) {
|
|
19
|
-
throw new missing_password_error_1.MissingPasswordError();
|
|
20
|
-
}
|
|
21
|
-
if (auth.missing.includes("securityQuestion")) {
|
|
22
|
-
throw new missing_security_question_error_1.MissingSecurityQuestionError();
|
|
23
|
-
}
|
|
24
|
-
if (auth.missing.includes("securityAnswer")) {
|
|
25
|
-
throw new missing_security_question_error_1.MissingSecurityQuestionError();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
next();
|
|
29
|
-
});
|
|
30
|
-
exports.validateAuth = validateAuth;
|
|
@@ -1,30 +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 missing_kyc_approval_error_1 = require("../errors/missing-kyc-approval-error");
|
|
14
|
-
const kyc_status_1 = require("../types/kyc-status");
|
|
15
|
-
const user_type_1 = require("../types/user-type");
|
|
16
|
-
const validateKYC = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
const user = req.user;
|
|
18
|
-
if ((user === null || user === void 0 ? void 0 : user.type) === user_type_1.UserType.Individual) {
|
|
19
|
-
if (user.kycStatus !== kyc_status_1.KYCStatus.Passed) {
|
|
20
|
-
throw new missing_kyc_approval_error_1.MissingKYCApprovalError();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if ((user === null || user === void 0 ? void 0 : user.type) === user_type_1.UserType.Business) {
|
|
24
|
-
if (user.kycStatus !== kyc_status_1.KYCStatus.businessApproved) {
|
|
25
|
-
throw new missing_kyc_approval_error_1.MissingKYCApprovalError();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
next();
|
|
29
|
-
});
|
|
30
|
-
exports.validateKYC = validateKYC;
|
|
File without changes
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import { Request, Response, NextFunction } from "express";
|
|
3
|
-
// import { NotAuthorizedError } from "../errors/not-authorized-error";
|
|
4
|
-
// export const validateOrder = async (
|
|
5
|
-
// req: Request,
|
|
6
|
-
// res: Response,
|
|
7
|
-
// next: NextFunction
|
|
8
|
-
// ) => {
|
|
9
|
-
// const order = req.order;
|
|
10
|
-
// if (!order) {
|
|
11
|
-
// throw new NotAuthorizedError();
|
|
12
|
-
// }
|
|
13
|
-
// if (req.partnerId && req.partnerId !== order.partnerId) {
|
|
14
|
-
// throw new NotAuthorizedError();
|
|
15
|
-
// }
|
|
16
|
-
// if (req.user && req.user._id.valueOf() !== order.userId) {
|
|
17
|
-
// throw new NotAuthorizedError();
|
|
18
|
-
// }
|
|
19
|
-
// next();
|
|
20
|
-
// };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateRequest = void 0;
|
|
4
|
-
const express_validator_1 = require("express-validator");
|
|
5
|
-
const request_validation_error_1 = require("../errors/request-validation-error");
|
|
6
|
-
const validateRequest = (req, res, next) => {
|
|
7
|
-
const errors = (0, express_validator_1.validationResult)(req);
|
|
8
|
-
if (!errors.isEmpty()) {
|
|
9
|
-
throw new request_validation_error_1.RequestValidationError(errors.array());
|
|
10
|
-
}
|
|
11
|
-
next();
|
|
12
|
-
};
|
|
13
|
-
exports.validateRequest = validateRequest;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
declare global {
|
|
3
|
-
namespace Express {
|
|
4
|
-
interface Request {
|
|
5
|
-
validAdminApiKey?: boolean;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export declare const verifyAdminApiKey: (req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.verifyAdminApiKey = void 0;
|
|
4
|
-
const verifyAdminApiKey = (req, res, next) => {
|
|
5
|
-
let apiKey = req.header("x-api-key");
|
|
6
|
-
if (apiKey === process.env.ORIGINAL_ADMIN_API_KEY) {
|
|
7
|
-
req.validAdminApiKey = true;
|
|
8
|
-
}
|
|
9
|
-
next();
|
|
10
|
-
};
|
|
11
|
-
exports.verifyAdminApiKey = verifyAdminApiKey;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Mongoose, Model, Document } from "mongoose";
|
|
2
|
-
interface AdminAuthAttrs {
|
|
3
|
-
email: string;
|
|
4
|
-
password: string;
|
|
5
|
-
previousPasswords?: string[];
|
|
6
|
-
}
|
|
7
|
-
interface AdminAuthDoc extends Document {
|
|
8
|
-
email: string;
|
|
9
|
-
password: string;
|
|
10
|
-
previousPasswords?: string[];
|
|
11
|
-
}
|
|
12
|
-
interface AdminAuthModel extends Model<AdminAuthDoc> {
|
|
13
|
-
build(attrs: AdminAuthAttrs): AdminAuthDoc;
|
|
14
|
-
}
|
|
15
|
-
declare const buildAdminAuth: (mongoose: Mongoose) => AdminAuthModel;
|
|
16
|
-
export { buildAdminAuth, AdminAuthDoc };
|
|
@@ -1,59 +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.buildAdminAuth = void 0;
|
|
13
|
-
const password_1 = require("../services/password");
|
|
14
|
-
const buildAdminAuth = (mongoose) => {
|
|
15
|
-
// if model is already defined, return it
|
|
16
|
-
if (mongoose.models.AdminAuth) {
|
|
17
|
-
return mongoose.model("AdminAuth");
|
|
18
|
-
}
|
|
19
|
-
const AdminSchema = new mongoose.Schema({
|
|
20
|
-
email: {
|
|
21
|
-
type: String,
|
|
22
|
-
required: true,
|
|
23
|
-
},
|
|
24
|
-
password: {
|
|
25
|
-
type: String,
|
|
26
|
-
required: true,
|
|
27
|
-
},
|
|
28
|
-
previousPasswords: [
|
|
29
|
-
{
|
|
30
|
-
type: String,
|
|
31
|
-
required: false,
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
}, {
|
|
35
|
-
toJSON: {
|
|
36
|
-
transform(doc, ret) {
|
|
37
|
-
ret.id = ret._id.valueOf();
|
|
38
|
-
delete ret._id;
|
|
39
|
-
delete ret.__v;
|
|
40
|
-
delete ret.password;
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
AdminSchema.pre("save", function (done) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
if (this.isModified("password")) {
|
|
47
|
-
const hashed = yield password_1.Password.toHash(this.get("password"));
|
|
48
|
-
this.set("password", hashed);
|
|
49
|
-
}
|
|
50
|
-
done();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
AdminSchema.statics.build = (attrs) => {
|
|
54
|
-
return new AdminAuth(attrs);
|
|
55
|
-
};
|
|
56
|
-
const AdminAuth = mongoose.model("AdminAuth", AdminSchema);
|
|
57
|
-
return AdminAuth;
|
|
58
|
-
};
|
|
59
|
-
exports.buildAdminAuth = buildAdminAuth;
|
package/build/models/auth.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { APIKey } from "../types/api-key";
|
|
2
|
-
import { SecurityQuestion } from "../types/security-question";
|
|
3
|
-
import { Mongoose, Model, Document } from "mongoose";
|
|
4
|
-
interface AuthAttrs {
|
|
5
|
-
phoneNumber: string;
|
|
6
|
-
password?: string;
|
|
7
|
-
securityQuestion?: SecurityQuestion;
|
|
8
|
-
securityAnswer?: string;
|
|
9
|
-
previousPasswords?: string[];
|
|
10
|
-
apiKeys?: APIKey[];
|
|
11
|
-
}
|
|
12
|
-
interface AuthDoc extends Document {
|
|
13
|
-
phoneNumber: string;
|
|
14
|
-
password?: string;
|
|
15
|
-
securityQuestion?: SecurityQuestion;
|
|
16
|
-
securityAnswer?: string;
|
|
17
|
-
previousPasswords?: string[];
|
|
18
|
-
apiKeys?: APIKey[];
|
|
19
|
-
}
|
|
20
|
-
interface AuthModel extends Model<AuthDoc> {
|
|
21
|
-
build(attrs: AuthAttrs): AuthDoc;
|
|
22
|
-
}
|
|
23
|
-
declare const buildAuth: (mongoose: Mongoose) => AuthModel;
|
|
24
|
-
export { buildAuth, AuthDoc };
|
package/build/models/auth.js
DELETED
|
@@ -1,83 +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.buildAuth = void 0;
|
|
13
|
-
const password_1 = require("../services/password");
|
|
14
|
-
const buildAuth = (mongoose) => {
|
|
15
|
-
// if model is already defined, return it
|
|
16
|
-
if (mongoose.models.Auth) {
|
|
17
|
-
return mongoose.model("Auth");
|
|
18
|
-
}
|
|
19
|
-
const AuthSchema = new mongoose.Schema({
|
|
20
|
-
phoneNumber: {
|
|
21
|
-
type: String,
|
|
22
|
-
required: true,
|
|
23
|
-
},
|
|
24
|
-
password: {
|
|
25
|
-
type: String,
|
|
26
|
-
},
|
|
27
|
-
securityQuestion: {
|
|
28
|
-
type: String,
|
|
29
|
-
},
|
|
30
|
-
securityAnswer: {
|
|
31
|
-
type: String,
|
|
32
|
-
},
|
|
33
|
-
previousPasswords: [
|
|
34
|
-
{
|
|
35
|
-
type: String,
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
apiKeys: [
|
|
39
|
-
{
|
|
40
|
-
value: {
|
|
41
|
-
type: String,
|
|
42
|
-
required: true,
|
|
43
|
-
},
|
|
44
|
-
label: {
|
|
45
|
-
type: String,
|
|
46
|
-
},
|
|
47
|
-
id: {
|
|
48
|
-
type: String,
|
|
49
|
-
required: true,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
}, {
|
|
54
|
-
toJSON: {
|
|
55
|
-
transform(doc, ret) {
|
|
56
|
-
ret.id = ret._id.valueOf();
|
|
57
|
-
delete ret._id;
|
|
58
|
-
delete ret.__v;
|
|
59
|
-
delete ret.password;
|
|
60
|
-
delete ret.securityAnswer;
|
|
61
|
-
delete ret.previousPasswords;
|
|
62
|
-
for (let apiKey of ret.apiKeys) {
|
|
63
|
-
delete apiKey.value;
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
AuthSchema.pre("save", function (done) {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
if (this.isModified("password")) {
|
|
71
|
-
const hashed = yield password_1.Password.toHash(this.get("password"));
|
|
72
|
-
this.set("password", hashed);
|
|
73
|
-
}
|
|
74
|
-
done();
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
AuthSchema.statics.build = (attrs) => {
|
|
78
|
-
return new Auth(attrs);
|
|
79
|
-
};
|
|
80
|
-
const Auth = mongoose.model("Auth", AuthSchema);
|
|
81
|
-
return Auth;
|
|
82
|
-
};
|
|
83
|
-
exports.buildAuth = buildAuth;
|