@riocrypto/common-server 1.0.1016 → 1.0.1017
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/clients/rio-client.d.ts +1 -2
- package/build/clients/rio-client.js +0 -6
- package/build/helpers/get-platform-fees.d.ts +7 -0
- package/build/helpers/{get-platform-and-partner-fees.js → get-platform-fees.js} +4 -32
- package/build/index.d.ts +1 -4
- package/build/index.js +1 -4
- package/build/middlewares/authorize.d.ts +0 -7
- package/build/middlewares/authorize.js +3 -31
- package/build/middlewares/require-priveleges.js +1 -1
- package/build/models/order.d.ts +0 -2
- package/build/models/order.js +0 -9
- package/build/models/quote.d.ts +0 -2
- package/build/models/quote.js +0 -6
- package/build/models/user.d.ts +0 -2
- package/build/models/user.js +0 -3
- package/package.json +2 -2
- package/build/helpers/get-platform-and-partner-fees.d.ts +0 -8
- package/build/middlewares/get-partner.d.ts +0 -10
- package/build/middlewares/get-partner.js +0 -47
- package/build/middlewares/validate-order.d.ts +0 -0
- package/build/middlewares/validate-order.js +0 -20
- package/build/models/partner-auth.d.ts +0 -16
- package/build/models/partner-auth.js +0 -60
- package/build/models/partner.d.ts +0 -29
- package/build/models/partner.js +0 -57
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Admin, Auth, AuthUpdate, BankPayout, CheckedAddress, Country, Fiat, Order, OrderInput,
|
|
1
|
+
import { Admin, Auth, AuthUpdate, BankPayout, CheckedAddress, Country, Fiat, Order, OrderInput, PaymentMethod, PayoutMethod, RioSettings, RioSettingsUpdate, SecurityQuestion, User, UserInput, UserUpdate } from "@riocrypto/common";
|
|
2
2
|
import { AxiosInstance, AxiosStatic } from "axios";
|
|
3
3
|
export declare class RioClient {
|
|
4
4
|
private axios;
|
|
@@ -37,7 +37,6 @@ export declare class RioClient {
|
|
|
37
37
|
checkAddress(address: string, crypto: Crypto): Promise<CheckedAddress>;
|
|
38
38
|
getSupportedPaymentMethods(fiat: Fiat, country: Country): Promise<PaymentMethod[]>;
|
|
39
39
|
getSupportedPayoutMethods(fiat: Fiat, country: Country): Promise<PayoutMethod[]>;
|
|
40
|
-
getPartnerLayout(partnerId: string): Promise<Partner>;
|
|
41
40
|
createClipCardPayment(orderId: string): Promise<{
|
|
42
41
|
paymentId: string;
|
|
43
42
|
paymentRequestUrl: string;
|
|
@@ -204,12 +204,6 @@ class RioClient {
|
|
|
204
204
|
return response.data;
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
|
-
getPartnerLayout(partnerId) {
|
|
208
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
-
const { data } = yield this.axios.get(`/api/partners/${partnerId}/layout`);
|
|
210
|
-
return data;
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
207
|
createClipCardPayment(orderId) {
|
|
214
208
|
return __awaiter(this, void 0, void 0, function* () {
|
|
215
209
|
const { data } = yield this.axios.post(`/api/payments/card/clip`, {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Country, Fiat, Processor, User } from "@riocrypto/common";
|
|
2
|
+
import { Mongoose } from "mongoose";
|
|
3
|
+
export declare const getPlatformFees: (mongoose: Mongoose, conversionRateToUSD: number, amountFiat: number, fiat: Fiat, processor: Processor, country: Country, brokerId?: string, user?: User, markup?: number, discount?: number) => Promise<{
|
|
4
|
+
platformFeeFiat: number;
|
|
5
|
+
platformFeeFiatTax: number;
|
|
6
|
+
feesComped: boolean;
|
|
7
|
+
}>;
|
|
@@ -9,17 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.getPlatformFees = void 0;
|
|
13
13
|
const rio_settings_1 = require("../models/rio-settings");
|
|
14
14
|
const common_1 = require("@riocrypto/common");
|
|
15
|
-
const partner_1 = require("../models/partner");
|
|
16
15
|
const user_1 = require("../models/user");
|
|
17
16
|
const calculate_aggregate_volume_and_revenue_1 = require("./calculate-aggregate-volume-and-revenue");
|
|
18
|
-
const
|
|
17
|
+
const getPlatformFees = (mongoose, conversionRateToUSD, amountFiat, fiat, processor, country, brokerId, user, markup, discount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
18
|
var _a, _b;
|
|
20
19
|
let platformFeeFiat;
|
|
21
20
|
let platformFeeFiatTax = 0;
|
|
22
|
-
let partnerFeeFiat = 0;
|
|
23
21
|
let feesComped = false;
|
|
24
22
|
let amountUSD;
|
|
25
23
|
const RioSettings = (0, rio_settings_1.buildRioSettings)(mongoose);
|
|
@@ -34,29 +32,7 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
|
|
|
34
32
|
if (!amountUSD) {
|
|
35
33
|
throw new common_1.GenericInternalError("Could not convert amount to USD");
|
|
36
34
|
}
|
|
37
|
-
if (
|
|
38
|
-
const Partner = (0, partner_1.buildPartner)(mongoose);
|
|
39
|
-
const partner = yield Partner.findById(partnerId);
|
|
40
|
-
if (!partner) {
|
|
41
|
-
throw new common_1.PartnerNotFoundError();
|
|
42
|
-
}
|
|
43
|
-
if (partner.feesComped) {
|
|
44
|
-
feesComped = true;
|
|
45
|
-
}
|
|
46
|
-
if (discount && discount > partner.platformFee) {
|
|
47
|
-
throw new common_1.GenericInputError("Discount cannot be greater than platform fee");
|
|
48
|
-
}
|
|
49
|
-
let netPlatformFee = partner.platformFee;
|
|
50
|
-
if (discount) {
|
|
51
|
-
netPlatformFee -= discount;
|
|
52
|
-
}
|
|
53
|
-
if (markup) {
|
|
54
|
-
netPlatformFee += markup;
|
|
55
|
-
}
|
|
56
|
-
platformFeeFiat = amountFiat * netPlatformFee;
|
|
57
|
-
partnerFeeFiat = amountFiat * partner.partnerFee;
|
|
58
|
-
}
|
|
59
|
-
else if (brokerId) {
|
|
35
|
+
if (brokerId) {
|
|
60
36
|
const User = (0, user_1.buildUser)(mongoose);
|
|
61
37
|
const broker = yield User.findById(brokerId);
|
|
62
38
|
if (!broker) {
|
|
@@ -107,7 +83,6 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
|
|
|
107
83
|
}
|
|
108
84
|
platformFeeFiat = amountFiat * netPlatformFee;
|
|
109
85
|
}
|
|
110
|
-
partnerFeeFiat = 0;
|
|
111
86
|
}
|
|
112
87
|
else if (user === null || user === void 0 ? void 0 : user.platformFeeRanges) {
|
|
113
88
|
let volume;
|
|
@@ -153,7 +128,6 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
|
|
|
153
128
|
}
|
|
154
129
|
platformFeeFiat = amountFiat * netPlatformFee;
|
|
155
130
|
}
|
|
156
|
-
partnerFeeFiat = 0;
|
|
157
131
|
}
|
|
158
132
|
else {
|
|
159
133
|
let netPlatformFee = rioSettings.platformFee;
|
|
@@ -167,7 +141,6 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
|
|
|
167
141
|
throw new common_1.GenericInputError("Discount cannot be greater than platform fee");
|
|
168
142
|
}
|
|
169
143
|
platformFeeFiat = amountFiat * netPlatformFee;
|
|
170
|
-
partnerFeeFiat = 0;
|
|
171
144
|
}
|
|
172
145
|
if ((fiat === common_1.Fiat.MXN && processor === common_1.Processor.SPEI) ||
|
|
173
146
|
(fiat === common_1.Fiat.USD && processor === common_1.Processor.SPID)) {
|
|
@@ -183,8 +156,7 @@ const getPlatformAndPartnerFees = (mongoose, conversionRateToUSD, amountFiat, fi
|
|
|
183
156
|
return {
|
|
184
157
|
platformFeeFiat: platformFeeFiat,
|
|
185
158
|
platformFeeFiatTax,
|
|
186
|
-
partnerFeeFiat,
|
|
187
159
|
feesComped,
|
|
188
160
|
};
|
|
189
161
|
});
|
|
190
|
-
exports.
|
|
162
|
+
exports.getPlatformFees = getPlatformFees;
|
package/build/index.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export * from "./middlewares/require-admin-api-key";
|
|
|
7
7
|
export * from "./middlewares/current-admin-auth";
|
|
8
8
|
export * from "./middlewares/validate-auth";
|
|
9
9
|
export * from "./middlewares/get-order";
|
|
10
|
-
export * from "./middlewares/get-partner";
|
|
11
10
|
export * from "./middlewares/get-user";
|
|
12
11
|
export * from "./middlewares/require-priveleges";
|
|
13
12
|
export * from "./middlewares/validate-kyc";
|
|
@@ -21,7 +20,6 @@ export * from "./models/auth";
|
|
|
21
20
|
export * from "./models/bank-payout";
|
|
22
21
|
export * from "./models/bank-payment";
|
|
23
22
|
export * from "./models/order";
|
|
24
|
-
export * from "./models/partner";
|
|
25
23
|
export * from "./models/user";
|
|
26
24
|
export * from "./models/ccxt-order";
|
|
27
25
|
export * from "./models/kushki-payment";
|
|
@@ -30,7 +28,6 @@ export * from "./models/checked-address";
|
|
|
30
28
|
export * from "./models/fireblocks-vault";
|
|
31
29
|
export * from "./models/fireblocks-transfer";
|
|
32
30
|
export * from "./models/rio-settings";
|
|
33
|
-
export * from "./models/partner-auth";
|
|
34
31
|
export * from "./models/bank-account";
|
|
35
32
|
export * from "./models/quote";
|
|
36
33
|
export * from "./models/bridge-customer";
|
|
@@ -54,7 +51,7 @@ export * from "./clients/aiprise-client";
|
|
|
54
51
|
export * from "./clients/bridge-client";
|
|
55
52
|
export * from "./clients/google-sheets-api-client";
|
|
56
53
|
export * from "./helpers/get-user-helper";
|
|
57
|
-
export * from "./helpers/get-platform-
|
|
54
|
+
export * from "./helpers/get-platform-fees";
|
|
58
55
|
export * from "./helpers/get-processor-fees";
|
|
59
56
|
export * from "./helpers/get-network-fees";
|
|
60
57
|
export * from "./helpers/calculate-aggregate-volume-and-revenue";
|
package/build/index.js
CHANGED
|
@@ -23,7 +23,6 @@ __exportStar(require("./middlewares/require-admin-api-key"), exports);
|
|
|
23
23
|
__exportStar(require("./middlewares/current-admin-auth"), exports);
|
|
24
24
|
__exportStar(require("./middlewares/validate-auth"), exports);
|
|
25
25
|
__exportStar(require("./middlewares/get-order"), exports);
|
|
26
|
-
__exportStar(require("./middlewares/get-partner"), exports);
|
|
27
26
|
__exportStar(require("./middlewares/get-user"), exports);
|
|
28
27
|
__exportStar(require("./middlewares/require-priveleges"), exports);
|
|
29
28
|
__exportStar(require("./middlewares/validate-kyc"), exports);
|
|
@@ -37,7 +36,6 @@ __exportStar(require("./models/auth"), exports);
|
|
|
37
36
|
__exportStar(require("./models/bank-payout"), exports);
|
|
38
37
|
__exportStar(require("./models/bank-payment"), exports);
|
|
39
38
|
__exportStar(require("./models/order"), exports);
|
|
40
|
-
__exportStar(require("./models/partner"), exports);
|
|
41
39
|
__exportStar(require("./models/user"), exports);
|
|
42
40
|
__exportStar(require("./models/ccxt-order"), exports);
|
|
43
41
|
__exportStar(require("./models/kushki-payment"), exports);
|
|
@@ -46,7 +44,6 @@ __exportStar(require("./models/checked-address"), exports);
|
|
|
46
44
|
__exportStar(require("./models/fireblocks-vault"), exports);
|
|
47
45
|
__exportStar(require("./models/fireblocks-transfer"), exports);
|
|
48
46
|
__exportStar(require("./models/rio-settings"), exports);
|
|
49
|
-
__exportStar(require("./models/partner-auth"), exports);
|
|
50
47
|
__exportStar(require("./models/bank-account"), exports);
|
|
51
48
|
__exportStar(require("./models/quote"), exports);
|
|
52
49
|
__exportStar(require("./models/bridge-customer"), exports);
|
|
@@ -70,7 +67,7 @@ __exportStar(require("./clients/aiprise-client"), exports);
|
|
|
70
67
|
__exportStar(require("./clients/bridge-client"), exports);
|
|
71
68
|
__exportStar(require("./clients/google-sheets-api-client"), exports);
|
|
72
69
|
__exportStar(require("./helpers/get-user-helper"), exports);
|
|
73
|
-
__exportStar(require("./helpers/get-platform-
|
|
70
|
+
__exportStar(require("./helpers/get-platform-fees"), exports);
|
|
74
71
|
__exportStar(require("./helpers/get-processor-fees"), exports);
|
|
75
72
|
__exportStar(require("./helpers/get-network-fees"), exports);
|
|
76
73
|
__exportStar(require("./helpers/calculate-aggregate-volume-and-revenue"), exports);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from "express";
|
|
2
2
|
import { UserDoc } from "../models/user";
|
|
3
3
|
import { Mongoose } from "mongoose";
|
|
4
|
-
import { PartnerDoc } from "../models/partner";
|
|
5
4
|
import { AuthorizationType } from "@riocrypto/common";
|
|
6
5
|
interface AuthPayload {
|
|
7
6
|
id: string;
|
|
@@ -12,18 +11,12 @@ interface AdminAuthPayload {
|
|
|
12
11
|
id: string;
|
|
13
12
|
email: string;
|
|
14
13
|
}
|
|
15
|
-
interface PartnerAuthPayload {
|
|
16
|
-
id: string;
|
|
17
|
-
email: string;
|
|
18
|
-
}
|
|
19
14
|
declare global {
|
|
20
15
|
namespace Express {
|
|
21
16
|
interface Request {
|
|
22
17
|
currentAuth?: AuthPayload;
|
|
23
18
|
currentAdminAuth?: AdminAuthPayload;
|
|
24
|
-
currentPartnerAuth?: PartnerAuthPayload;
|
|
25
19
|
user?: UserDoc;
|
|
26
|
-
partner?: PartnerDoc;
|
|
27
20
|
validAdminApiKey?: boolean;
|
|
28
21
|
session?: any;
|
|
29
22
|
}
|
|
@@ -15,13 +15,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.authorize = void 0;
|
|
16
16
|
const user_1 = require("../models/user");
|
|
17
17
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
18
|
-
const partner_1 = require("../models/partner");
|
|
19
18
|
const common_1 = require("@riocrypto/common");
|
|
20
19
|
const auth_1 = require("../models/auth");
|
|
21
20
|
const apiKey_1 = require("../services/apiKey");
|
|
22
21
|
const secret_manager_client_1 = require("../clients/secret-manager-client");
|
|
23
22
|
const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
23
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
25
24
|
const apiKey = req.header("x-api-key");
|
|
26
25
|
let missingKYC = false;
|
|
27
26
|
if (authorizationTypes.includes(common_1.AuthorizationType.AdminAPI)) {
|
|
@@ -103,30 +102,6 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
|
-
if (authorizationTypes.includes(common_1.AuthorizationType.PartnerAuth) ||
|
|
107
|
-
authorizationTypes.includes(common_1.AuthorizationType.Partner)) {
|
|
108
|
-
if ((_g = req.cookies) === null || _g === void 0 ? void 0 : _g.partnerAccessToken) {
|
|
109
|
-
try {
|
|
110
|
-
const PARTNER_ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("PARTNER_ACCESS_TOKEN_SECRET");
|
|
111
|
-
if (!PARTNER_ACCESS_TOKEN_SECRET) {
|
|
112
|
-
throw new Error("Unable to get PARTNER_ACCESS_TOKEN_SECRET");
|
|
113
|
-
}
|
|
114
|
-
const payload = jsonwebtoken_1.default.verify(req.cookies.partnerAccessToken, PARTNER_ACCESS_TOKEN_SECRET);
|
|
115
|
-
req.currentPartnerAuth = payload;
|
|
116
|
-
}
|
|
117
|
-
catch (err) { }
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (authorizationTypes.includes(common_1.AuthorizationType.Partner) &&
|
|
121
|
-
req.currentPartnerAuth) {
|
|
122
|
-
const Partner = yield (0, partner_1.buildPartner)(mongoose);
|
|
123
|
-
const partner = yield Partner.findOne({
|
|
124
|
-
authId: req.currentPartnerAuth.id,
|
|
125
|
-
});
|
|
126
|
-
if (partner) {
|
|
127
|
-
req.partner = partner;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
105
|
if (authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) {
|
|
131
106
|
let user;
|
|
132
107
|
try {
|
|
@@ -195,16 +170,13 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
195
170
|
// if no auth
|
|
196
171
|
(!req.currentAdminAuth &&
|
|
197
172
|
!req.currentAuth &&
|
|
198
|
-
!req.currentPartnerAuth &&
|
|
199
173
|
!req.user &&
|
|
200
|
-
!req.partner &&
|
|
201
174
|
!req.validAdminApiKey &&
|
|
202
175
|
!authorizationTypes.includes(common_1.AuthorizationType.Public)) ||
|
|
203
176
|
(!req.currentAuth &&
|
|
204
177
|
!authorizationTypes.includes(common_1.AuthorizationType.Auth) &&
|
|
205
178
|
!req.user &&
|
|
206
179
|
!req.validAdminApiKey &&
|
|
207
|
-
!req.currentPartnerAuth &&
|
|
208
180
|
!authorizationTypes.includes(common_1.AuthorizationType.Public))) {
|
|
209
181
|
if (!req.user &&
|
|
210
182
|
authorizationTypes.includes(common_1.AuthorizationType.UserOptional)) {
|
|
@@ -221,12 +193,12 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
221
193
|
}
|
|
222
194
|
if ((authorizationTypes.includes(common_1.AuthorizationType.User) ||
|
|
223
195
|
authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) &&
|
|
224
|
-
((
|
|
196
|
+
((_g = req.cookies) === null || _g === void 0 ? void 0 : _g.accessToken)) {
|
|
225
197
|
throw new common_1.MissingUserError();
|
|
226
198
|
}
|
|
227
199
|
if (authorizationTypes.includes(common_1.AuthorizationType.Admin) &&
|
|
228
200
|
authorizationTypes.length === 1 &&
|
|
229
|
-
((
|
|
201
|
+
((_h = req.cookies) === null || _h === void 0 ? void 0 : _h.accessToken)) {
|
|
230
202
|
throw new common_1.AdminOnlyError();
|
|
231
203
|
}
|
|
232
204
|
if (!req.user && authorizationTypes.includes(common_1.AuthorizationType.Broker)) {
|
|
@@ -6,7 +6,7 @@ const requirePriveleges = (req, res, next) => {
|
|
|
6
6
|
if (req.currentAuth && !req.user) {
|
|
7
7
|
throw new common_1.MissingUserError();
|
|
8
8
|
}
|
|
9
|
-
if (!req.
|
|
9
|
+
if (!req.user && !req.currentAdminAuth) {
|
|
10
10
|
throw new common_1.NotAuthorizedError();
|
|
11
11
|
}
|
|
12
12
|
next();
|
package/build/models/order.d.ts
CHANGED
|
@@ -21,7 +21,6 @@ interface OrderAttrs {
|
|
|
21
21
|
actualFees?: Fees;
|
|
22
22
|
price: number;
|
|
23
23
|
actualPrice?: number;
|
|
24
|
-
partnerId?: string;
|
|
25
24
|
depositAddress?: string;
|
|
26
25
|
depositTxId?: string;
|
|
27
26
|
withdrawalTxId?: string;
|
|
@@ -57,7 +56,6 @@ interface OrderDoc extends Document {
|
|
|
57
56
|
actualFees?: Fees;
|
|
58
57
|
price: number;
|
|
59
58
|
actualPrice: number;
|
|
60
|
-
partnerId?: string;
|
|
61
59
|
depositAddress?: string;
|
|
62
60
|
depositTxId?: string;
|
|
63
61
|
withdrawalTxId?: string;
|
package/build/models/order.js
CHANGED
|
@@ -85,9 +85,6 @@ const buildOrder = (mongoose) => {
|
|
|
85
85
|
platformFeeFiat: {
|
|
86
86
|
type: Number,
|
|
87
87
|
},
|
|
88
|
-
partnerFeeFiat: {
|
|
89
|
-
type: Number,
|
|
90
|
-
},
|
|
91
88
|
platformFeeFiatTax: {
|
|
92
89
|
type: Number,
|
|
93
90
|
},
|
|
@@ -102,9 +99,6 @@ const buildOrder = (mongoose) => {
|
|
|
102
99
|
platformFeeFiat: {
|
|
103
100
|
type: Number,
|
|
104
101
|
},
|
|
105
|
-
partnerFeeFiat: {
|
|
106
|
-
type: Number,
|
|
107
|
-
},
|
|
108
102
|
platformFeeFiatTax: {
|
|
109
103
|
type: Number,
|
|
110
104
|
},
|
|
@@ -116,9 +110,6 @@ const buildOrder = (mongoose) => {
|
|
|
116
110
|
actualPrice: {
|
|
117
111
|
type: Number,
|
|
118
112
|
},
|
|
119
|
-
partnerId: {
|
|
120
|
-
type: String,
|
|
121
|
-
},
|
|
122
113
|
brokerId: {
|
|
123
114
|
type: String,
|
|
124
115
|
},
|
package/build/models/quote.d.ts
CHANGED
|
@@ -18,7 +18,6 @@ interface QuoteAttrs {
|
|
|
18
18
|
price: number;
|
|
19
19
|
createdAt: Date;
|
|
20
20
|
volatilitySafeguard?: boolean;
|
|
21
|
-
partnerId?: string;
|
|
22
21
|
depositAddress?: string;
|
|
23
22
|
brokerId?: string;
|
|
24
23
|
conversionRateUSD: number;
|
|
@@ -44,7 +43,6 @@ interface QuoteDoc extends Document {
|
|
|
44
43
|
fees: Fees;
|
|
45
44
|
price: number;
|
|
46
45
|
volatilitySafeguard?: boolean;
|
|
47
|
-
partnerId?: string;
|
|
48
46
|
depositAddress?: string;
|
|
49
47
|
brokerId?: string;
|
|
50
48
|
conversionRateUSD: number;
|
package/build/models/quote.js
CHANGED
|
@@ -69,9 +69,6 @@ const buildQuote = (mongoose) => {
|
|
|
69
69
|
platformFeeFiat: {
|
|
70
70
|
type: Number,
|
|
71
71
|
},
|
|
72
|
-
partnerFeeFiat: {
|
|
73
|
-
type: Number,
|
|
74
|
-
},
|
|
75
72
|
platformFeeFiatTax: {
|
|
76
73
|
type: Number,
|
|
77
74
|
},
|
|
@@ -82,9 +79,6 @@ const buildQuote = (mongoose) => {
|
|
|
82
79
|
price: {
|
|
83
80
|
type: Number,
|
|
84
81
|
},
|
|
85
|
-
partnerId: {
|
|
86
|
-
type: String,
|
|
87
|
-
},
|
|
88
82
|
brokerId: {
|
|
89
83
|
type: String,
|
|
90
84
|
},
|
package/build/models/user.d.ts
CHANGED
|
@@ -21,7 +21,6 @@ interface UserAttrs {
|
|
|
21
21
|
cpf?: string;
|
|
22
22
|
language?: Language;
|
|
23
23
|
attributes?: UserAttribute[];
|
|
24
|
-
partnerId?: string;
|
|
25
24
|
brokerId?: string;
|
|
26
25
|
curp?: string;
|
|
27
26
|
economicActivity?: string;
|
|
@@ -65,7 +64,6 @@ interface UserDoc extends Document {
|
|
|
65
64
|
birthday?: Date;
|
|
66
65
|
language?: Language;
|
|
67
66
|
attributes?: UserAttribute[];
|
|
68
|
-
partnerId?: string;
|
|
69
67
|
brokerId?: string;
|
|
70
68
|
platformFeeRanges?: PlatformFeeRange[];
|
|
71
69
|
COIFile?: string;
|
package/build/models/user.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1017",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@aws-sdk/client-s3": "^3.297.0",
|
|
25
25
|
"@everapi/currencyapi-js": "^1.0.6",
|
|
26
26
|
"@google-cloud/storage": "^6.9.5",
|
|
27
|
-
"@riocrypto/common": "^1.0.
|
|
27
|
+
"@riocrypto/common": "^1.0.873",
|
|
28
28
|
"@types/express": "^4.17.13",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"ccxt": "^3.0.30",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Country, Fiat, Processor, User } from "@riocrypto/common";
|
|
2
|
-
import { Mongoose } from "mongoose";
|
|
3
|
-
export declare const getPlatformAndPartnerFees: (mongoose: Mongoose, conversionRateToUSD: number, amountFiat: number, fiat: Fiat, processor: Processor, country: Country, partnerId?: string, brokerId?: string, user?: User, markup?: number, discount?: number) => Promise<{
|
|
4
|
-
platformFeeFiat: number;
|
|
5
|
-
platformFeeFiatTax: number;
|
|
6
|
-
partnerFeeFiat: number;
|
|
7
|
-
feesComped: boolean;
|
|
8
|
-
}>;
|
|
@@ -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,47 +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 secret_manager_client_1 = require("../clients/secret-manager-client");
|
|
20
|
-
const common_1 = require("@riocrypto/common");
|
|
21
|
-
const getPartner = (req, res, next, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
-
try {
|
|
23
|
-
if (!req.headers["x-api-key"]) {
|
|
24
|
-
const PARTNER_ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("PARTNER_ACCESS_TOKEN_SECRET");
|
|
25
|
-
if (!PARTNER_ACCESS_TOKEN_SECRET) {
|
|
26
|
-
throw new common_1.SecretManagerError();
|
|
27
|
-
}
|
|
28
|
-
const payload = jsonwebtoken_1.default.verify(req.cookies.partnerAuthJwt, PARTNER_ACCESS_TOKEN_SECRET);
|
|
29
|
-
req.partnerId = payload.partnerId;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
const hashedApiKey = yield apiKey_1.ApiKey.toHash(req.headers["x-api-key"]);
|
|
33
|
-
const Partner = yield (0, partner_1.buildPartner)(mongoose);
|
|
34
|
-
const partner = yield Partner.findOne({
|
|
35
|
-
apiKeys: { $elemMatch: { value: hashedApiKey } },
|
|
36
|
-
});
|
|
37
|
-
if (partner) {
|
|
38
|
-
req.partnerId = partner._id.valueOf();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
next();
|
|
42
|
-
}
|
|
43
|
-
catch (err) {
|
|
44
|
-
next();
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
exports.getPartner = getPartner;
|
|
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,16 +0,0 @@
|
|
|
1
|
-
import { Mongoose, Model, Document } from "mongoose";
|
|
2
|
-
interface PartnerAuthAttrs {
|
|
3
|
-
email: string;
|
|
4
|
-
password: string;
|
|
5
|
-
previousPasswords?: string[];
|
|
6
|
-
}
|
|
7
|
-
interface PartnerAuthDoc extends Document {
|
|
8
|
-
email: string;
|
|
9
|
-
password: string;
|
|
10
|
-
previousPasswords?: string[];
|
|
11
|
-
}
|
|
12
|
-
interface PartnerAuthModel extends Model<PartnerAuthDoc> {
|
|
13
|
-
build(attrs: PartnerAuthAttrs): PartnerAuthDoc;
|
|
14
|
-
}
|
|
15
|
-
declare const buildPartnerAuth: (mongoose: Mongoose) => PartnerAuthModel;
|
|
16
|
-
export { buildPartnerAuth, PartnerAuthDoc };
|
|
@@ -1,60 +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.buildPartnerAuth = void 0;
|
|
13
|
-
const password_1 = require("../services/password");
|
|
14
|
-
const buildPartnerAuth = (mongoose) => {
|
|
15
|
-
// if model is already defined, return it
|
|
16
|
-
if (mongoose.models.PartnerAuth) {
|
|
17
|
-
return mongoose.model("PartnerAuth");
|
|
18
|
-
}
|
|
19
|
-
const PartnerSchema = 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
|
-
delete ret.previousPasswords;
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
PartnerSchema.pre("save", function (done) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
if (this.isModified("password")) {
|
|
48
|
-
const hashed = yield password_1.Password.toHash(this.get("password"));
|
|
49
|
-
this.set("password", hashed);
|
|
50
|
-
}
|
|
51
|
-
done();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
PartnerSchema.statics.build = (attrs) => {
|
|
55
|
-
return new PartnerAuth(attrs);
|
|
56
|
-
};
|
|
57
|
-
const PartnerAuth = mongoose.model("PartnerAuth", PartnerSchema);
|
|
58
|
-
return PartnerAuth;
|
|
59
|
-
};
|
|
60
|
-
exports.buildPartnerAuth = buildPartnerAuth;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { PartnerStatus } from "@riocrypto/common";
|
|
2
|
-
import { Mongoose, Document, Model } from "mongoose";
|
|
3
|
-
interface PartnerAttrs {
|
|
4
|
-
authId: string;
|
|
5
|
-
name: string;
|
|
6
|
-
status: PartnerStatus;
|
|
7
|
-
partnerFee: number;
|
|
8
|
-
platformFee: number;
|
|
9
|
-
color?: string;
|
|
10
|
-
logo?: string;
|
|
11
|
-
logoDark?: string;
|
|
12
|
-
feesComped?: boolean;
|
|
13
|
-
}
|
|
14
|
-
interface PartnerDoc extends Document {
|
|
15
|
-
authId: string;
|
|
16
|
-
name: string;
|
|
17
|
-
status: PartnerStatus;
|
|
18
|
-
partnerFee: number;
|
|
19
|
-
platformFee: number;
|
|
20
|
-
color?: string;
|
|
21
|
-
logo?: string;
|
|
22
|
-
logoDark?: string;
|
|
23
|
-
feesComped?: boolean;
|
|
24
|
-
}
|
|
25
|
-
interface PartnerModel extends Model<PartnerDoc> {
|
|
26
|
-
build(attrs: PartnerAttrs): PartnerDoc;
|
|
27
|
-
}
|
|
28
|
-
declare const buildPartner: (mongoose: Mongoose) => PartnerModel;
|
|
29
|
-
export { buildPartner, PartnerDoc };
|
package/build/models/partner.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildPartner = void 0;
|
|
4
|
-
const buildPartner = (mongoose) => {
|
|
5
|
-
// if model is already defined, return it
|
|
6
|
-
if (mongoose.models.Partner) {
|
|
7
|
-
return mongoose.model("Partner");
|
|
8
|
-
}
|
|
9
|
-
const PartnerSchema = new mongoose.Schema({
|
|
10
|
-
authId: {
|
|
11
|
-
type: String,
|
|
12
|
-
required: true,
|
|
13
|
-
},
|
|
14
|
-
name: {
|
|
15
|
-
type: String,
|
|
16
|
-
required: true,
|
|
17
|
-
},
|
|
18
|
-
status: {
|
|
19
|
-
type: String,
|
|
20
|
-
required: true,
|
|
21
|
-
},
|
|
22
|
-
partnerFee: {
|
|
23
|
-
type: Number,
|
|
24
|
-
required: true,
|
|
25
|
-
},
|
|
26
|
-
platformFee: {
|
|
27
|
-
type: Number,
|
|
28
|
-
required: true,
|
|
29
|
-
},
|
|
30
|
-
color: {
|
|
31
|
-
type: String,
|
|
32
|
-
},
|
|
33
|
-
logo: {
|
|
34
|
-
type: String,
|
|
35
|
-
},
|
|
36
|
-
logoDark: {
|
|
37
|
-
type: String,
|
|
38
|
-
},
|
|
39
|
-
feesComped: {
|
|
40
|
-
type: Boolean,
|
|
41
|
-
},
|
|
42
|
-
}, {
|
|
43
|
-
toJSON: {
|
|
44
|
-
transform(doc, ret) {
|
|
45
|
-
ret.id = ret._id.valueOf();
|
|
46
|
-
delete ret._id;
|
|
47
|
-
delete ret.__v;
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
PartnerSchema.statics.build = (attrs) => {
|
|
52
|
-
return new Partner(attrs);
|
|
53
|
-
};
|
|
54
|
-
const Partner = mongoose.model("Partner", PartnerSchema);
|
|
55
|
-
return Partner;
|
|
56
|
-
};
|
|
57
|
-
exports.buildPartner = buildPartner;
|