@riocrypto/common-server 1.0.537 → 1.0.539

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
@@ -19,6 +19,7 @@ export * from "./models/admin-auth";
19
19
  export * from "./models/auth";
20
20
  export * from "./models/business-user";
21
21
  export * from "./models/bank-payout";
22
+ export * from "./models/bank-payment";
22
23
  export * from "./models/order";
23
24
  export * from "./models/partner";
24
25
  export * from "./models/user";
package/build/index.js CHANGED
@@ -35,6 +35,7 @@ __exportStar(require("./models/admin-auth"), exports);
35
35
  __exportStar(require("./models/auth"), exports);
36
36
  __exportStar(require("./models/business-user"), exports);
37
37
  __exportStar(require("./models/bank-payout"), exports);
38
+ __exportStar(require("./models/bank-payment"), exports);
38
39
  __exportStar(require("./models/order"), exports);
39
40
  __exportStar(require("./models/partner"), exports);
40
41
  __exportStar(require("./models/user"), exports);
@@ -18,6 +18,8 @@ const user_1 = require("../models/user");
18
18
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
19
19
  const partner_1 = require("../models/partner");
20
20
  const common_1 = require("@riocrypto/common");
21
+ const auth_1 = require("../models/auth");
22
+ const apiKey_1 = require("../services/apiKey");
21
23
  const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
22
24
  var _a, _b, _c, _d, _e, _f, _g, _h;
23
25
  let missingKYC = false;
@@ -33,7 +35,33 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
33
35
  authorizationTypes.includes(common_1.AuthorizationType.UserOptional) ||
34
36
  authorizationTypes.includes(common_1.AuthorizationType.Broker) ||
35
37
  authorizationTypes.includes(common_1.AuthorizationType.Partner)) {
36
- if ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.accessToken) {
38
+ const apiKey = req.header("x-api-key");
39
+ if (apiKey) {
40
+ try {
41
+ const hashedApiKey = yield apiKey_1.ApiKey.toHash(apiKey);
42
+ const Auth = yield (0, auth_1.buildAuth)(mongoose);
43
+ const auth = yield Auth.findOne({
44
+ apiKeys: { $in: [hashedApiKey] },
45
+ });
46
+ if (auth) {
47
+ const missing = [];
48
+ if (!auth.password) {
49
+ missing.push("password");
50
+ }
51
+ if (!auth.securityAnswer || !auth.securityQuestion) {
52
+ missing.push("securityQuestion");
53
+ }
54
+ const payload = {
55
+ id: auth.id,
56
+ phoneNumber: auth.phoneNumber,
57
+ missing,
58
+ };
59
+ req.currentAuth = payload;
60
+ }
61
+ }
62
+ catch (err) { }
63
+ }
64
+ else if ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.accessToken) {
37
65
  try {
38
66
  const payload = jsonwebtoken_1.default.verify(req.cookies.accessToken, process.env.JWT_KEY);
39
67
  req.currentAuth = payload;
@@ -0,0 +1,30 @@
1
+ import { Mongoose, Model, Document } from "mongoose";
2
+ interface BankPaymentAttrs {
3
+ orderId: string;
4
+ bankName: string;
5
+ companyName: string;
6
+ bankAddress: string;
7
+ accountNumber: string;
8
+ clabe?: string;
9
+ ruc?: string;
10
+ rfc?: string;
11
+ swiftCode?: string;
12
+ status: string;
13
+ }
14
+ interface BankPaymentDoc extends Document {
15
+ orderId: string;
16
+ bankName: string;
17
+ companyName: string;
18
+ bankAddress: string;
19
+ accountNumber: string;
20
+ clabe?: string;
21
+ ruc?: string;
22
+ rfc?: string;
23
+ swiftCode?: string;
24
+ status: string;
25
+ }
26
+ interface BankPaymentModel extends Model<BankPaymentDoc> {
27
+ build(attrs: BankPaymentAttrs): BankPaymentDoc;
28
+ }
29
+ declare const buildBankPayment: (mongoose: Mongoose) => BankPaymentModel;
30
+ export { buildBankPayment, BankPaymentDoc };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildBankPayment = void 0;
4
+ const buildBankPayment = (mongoose) => {
5
+ // if model is already defined, return it
6
+ if (mongoose.models.BankPayment) {
7
+ return mongoose.model("BankPayment");
8
+ }
9
+ const BankPaymentSchema = new mongoose.Schema({
10
+ orderId: {
11
+ type: String,
12
+ required: true,
13
+ },
14
+ bankName: {
15
+ type: String,
16
+ required: true,
17
+ },
18
+ companyName: {
19
+ type: String,
20
+ required: true,
21
+ },
22
+ bankAddress: {
23
+ type: String,
24
+ required: true,
25
+ },
26
+ accountNumber: {
27
+ type: String,
28
+ required: true,
29
+ },
30
+ status: {
31
+ type: String,
32
+ required: true,
33
+ },
34
+ clabe: {
35
+ type: String,
36
+ },
37
+ ruc: {
38
+ type: String,
39
+ },
40
+ rfc: {
41
+ type: String,
42
+ },
43
+ swiftCode: {
44
+ type: String,
45
+ },
46
+ }, {
47
+ toJSON: {
48
+ transform(doc, ret) {
49
+ ret.id = ret._id.valueOf();
50
+ delete ret._id;
51
+ delete ret.__v;
52
+ },
53
+ },
54
+ });
55
+ BankPaymentSchema.statics.build = (attrs) => {
56
+ return new BankPayment(attrs);
57
+ };
58
+ const BankPayment = mongoose.model("BankPayment", BankPaymentSchema);
59
+ return BankPayment;
60
+ };
61
+ exports.buildBankPayment = buildBankPayment;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.537",
3
+ "version": "1.0.539",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@aws-sdk/client-s3": "^3.297.0",
25
- "@riocrypto/common": "^1.0.538",
25
+ "@riocrypto/common": "^1.0.539",
26
26
  "@types/express": "^4.17.13",
27
27
  "axios": "^0.27.2",
28
28
  "ccxt": "^3.0.30",