@riocrypto/common-server 1.0.1214 → 1.0.1216

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.
@@ -0,0 +1,3 @@
1
+ import { Request } from "express";
2
+ import { UserDoc } from "../models/user";
3
+ export declare const getUser: (req: Request, userId?: string) => Promise<UserDoc | undefined | null>;
@@ -0,0 +1,37 @@
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.getUser = void 0;
16
+ const user_1 = require("../models/user");
17
+ const mongoose_1 = __importDefault(require("mongoose"));
18
+ const getUser = (req, userId) => __awaiter(void 0, void 0, void 0, function* () {
19
+ var _a, _b;
20
+ if (!userId) {
21
+ return req.user;
22
+ }
23
+ else {
24
+ const User = (0, user_1.buildUser)(mongoose_1.default);
25
+ const user = yield User.findById(userId);
26
+ if (req.admin ||
27
+ req.validClusterApiKey ||
28
+ (user === null || user === void 0 ? void 0 : user.id) === ((_a = req.user) === null || _a === void 0 ? void 0 : _a.id) ||
29
+ (user === null || user === void 0 ? void 0 : user.brokerId) === ((_b = req.user) === null || _b === void 0 ? void 0 : _b.id)) {
30
+ return user;
31
+ }
32
+ else {
33
+ return null;
34
+ }
35
+ }
36
+ });
37
+ exports.getUser = getUser;
package/build/index.d.ts CHANGED
@@ -64,5 +64,5 @@ export * from "./helpers/get-network-fees";
64
64
  export * from "./helpers/calculate-aggregate-volume-and-revenue";
65
65
  export * from "./helpers/calculate-weekly-volume-and-revenue";
66
66
  export * from "./helpers/get-exchange-rates";
67
- export * from "./helpers/can-access-user";
67
+ export * from "./helpers/get-user";
68
68
  export * from "./helpers/unescape";
package/build/index.js CHANGED
@@ -80,5 +80,5 @@ __exportStar(require("./helpers/get-network-fees"), exports);
80
80
  __exportStar(require("./helpers/calculate-aggregate-volume-and-revenue"), exports);
81
81
  __exportStar(require("./helpers/calculate-weekly-volume-and-revenue"), exports);
82
82
  __exportStar(require("./helpers/get-exchange-rates"), exports);
83
- __exportStar(require("./helpers/can-access-user"), exports);
83
+ __exportStar(require("./helpers/get-user"), exports);
84
84
  __exportStar(require("./helpers/unescape"), exports);
@@ -23,7 +23,7 @@ const admin_auth_1 = require("../models/admin-auth");
23
23
  const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
24
24
  var _a, _b, _c, _d;
25
25
  if (authorizationTypes.includes(common_1.AuthorizationType.Cluster)) {
26
- let apiKey = req.header("x-api-key");
26
+ let apiKey = req.header("x-cluster-api-key");
27
27
  const CLUSTER_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("CLUSTER_API_KEY");
28
28
  if (!CLUSTER_API_KEY) {
29
29
  throw new common_1.SecretManagerError();
@@ -21,7 +21,6 @@ interface OrderAttrs {
21
21
  fees: Fees;
22
22
  actualFees?: Fees;
23
23
  price: number;
24
- actualPrice?: number;
25
24
  depositAddress?: string;
26
25
  depositTxId?: string;
27
26
  withdrawalTxId?: string;
@@ -37,7 +36,6 @@ interface OrderAttrs {
37
36
  partner?: Partner;
38
37
  imported?: boolean;
39
38
  managedWallet?: boolean;
40
- amountFixed?: number;
41
39
  exchangeRateOrders?: ExchangeRateOrder[];
42
40
  autoFXDisabled?: boolean;
43
41
  USBankTransferMethod?: "wire" | "ach_push";
@@ -63,7 +61,6 @@ interface OrderDoc extends Document {
63
61
  fees: Fees;
64
62
  actualFees?: Fees;
65
63
  price: number;
66
- actualPrice: number;
67
64
  depositAddress?: string;
68
65
  depositTxId?: string;
69
66
  withdrawalTxId?: string;
@@ -79,7 +76,6 @@ interface OrderDoc extends Document {
79
76
  partner?: Partner;
80
77
  imported?: boolean;
81
78
  managedWallet?: boolean;
82
- amountFixed?: number;
83
79
  exchangeRateOrders?: ExchangeRateOrder[];
84
80
  autoFXDisabled?: boolean;
85
81
  USBankTransferMethod?: "wire" | "ach_push";
@@ -111,9 +111,6 @@ const buildOrder = (mongoose) => {
111
111
  type: Number,
112
112
  required: true,
113
113
  },
114
- actualPrice: {
115
- type: Number,
116
- },
117
114
  brokerId: {
118
115
  type: String,
119
116
  },
@@ -154,9 +151,6 @@ const buildOrder = (mongoose) => {
154
151
  managedWallet: {
155
152
  type: Boolean,
156
153
  },
157
- amountFixed: {
158
- type: Number,
159
- },
160
154
  autoFXDisabled: {
161
155
  type: Boolean,
162
156
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1214",
3
+ "version": "1.0.1216",
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.1111",
29
+ "@riocrypto/common": "^1.0.1112",
30
30
  "@types/express": "^4.17.13",
31
31
  "axios": "^0.27.2",
32
32
  "ccxt": "^3.0.30",
@@ -1,3 +0,0 @@
1
- import { User } from "@riocrypto/common";
2
- import { Request } from "express";
3
- export declare const canAccessUser: (userToAccess: User, req: Request) => boolean;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.canAccessUser = void 0;
4
- const canAccessUser = (userToAccess, req) => {
5
- var _a, _b;
6
- if (!req.admin &&
7
- userToAccess.id !== ((_a = req.user) === null || _a === void 0 ? void 0 : _a.id) &&
8
- userToAccess.brokerId !== ((_b = req.user) === null || _b === void 0 ? void 0 : _b.id)) {
9
- return false;
10
- }
11
- else {
12
- return true;
13
- }
14
- };
15
- exports.canAccessUser = canAccessUser;