@riocrypto/common-server 1.0.1495 → 1.0.1500

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.
@@ -19,7 +19,7 @@ const getUser = (mongoose, req, userId) => __awaiter(void 0, void 0, void 0, fun
19
19
  else {
20
20
  const User = (0, user_1.buildUser)(mongoose);
21
21
  const user = yield User.findById(userId);
22
- if (req.admin ||
22
+ if (req.adminAuth ||
23
23
  req.validClusterApiKey ||
24
24
  (user === null || user === void 0 ? void 0 : user.id) === ((_a = req.user) === null || _a === void 0 ? void 0 : _a.id) ||
25
25
  (user === null || user === void 0 ? void 0 : user.brokerId) === ((_b = req.user) === null || _b === void 0 ? void 0 : _b.id)) {
package/build/index.d.ts CHANGED
@@ -9,7 +9,6 @@ export * from "./services/apiKey";
9
9
  export * from "./services/password";
10
10
  export * from "./services/logger";
11
11
  export * from "./models/admin-auth";
12
- export * from "./models/admin";
13
12
  export * from "./models/auth";
14
13
  export * from "./models/bank-payout";
15
14
  export * from "./models/bank-payment";
package/build/index.js CHANGED
@@ -25,7 +25,6 @@ __exportStar(require("./services/apiKey"), exports);
25
25
  __exportStar(require("./services/password"), exports);
26
26
  __exportStar(require("./services/logger"), exports);
27
27
  __exportStar(require("./models/admin-auth"), exports);
28
- __exportStar(require("./models/admin"), exports);
29
28
  __exportStar(require("./models/auth"), exports);
30
29
  __exportStar(require("./models/bank-payout"), exports);
31
30
  __exportStar(require("./models/bank-payment"), exports);
@@ -3,7 +3,6 @@ import { UserDoc } from "../models/user";
3
3
  import { Mongoose } from "mongoose";
4
4
  import { AuthorizationType } from "@riocrypto/common";
5
5
  import { AuthDoc } from "../models/auth";
6
- import { AdminDoc } from "../models/admin";
7
6
  import { AdminAuthDoc } from "../models/admin-auth";
8
7
  declare global {
9
8
  namespace Express {
@@ -11,7 +10,6 @@ declare global {
11
10
  auth?: AuthDoc;
12
11
  adminAuth?: AdminAuthDoc;
13
12
  user?: UserDoc;
14
- admin?: AdminDoc;
15
13
  validClusterApiKey?: boolean;
16
14
  }
17
15
  }
@@ -19,10 +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_1 = require("../models/admin");
23
22
  const admin_auth_1 = require("../models/admin-auth");
24
23
  const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(void 0, void 0, void 0, function* () {
25
- var _a, _b, _c, _d, _e, _f, _g, _h;
24
+ var _a, _b, _c, _d, _e, _f, _g;
26
25
  if (authorizationTypes.includes(common_1.AuthorizationType.Cluster)) {
27
26
  let apiKey = req.header("x-cluster-api-key");
28
27
  const CLUSTER_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("CLUSTER_API_KEY");
@@ -33,8 +32,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
33
32
  req.validClusterApiKey = true;
34
33
  }
35
34
  }
36
- if (authorizationTypes.includes(common_1.AuthorizationType.AdminAuth) ||
37
- authorizationTypes.includes(common_1.AuthorizationType.Admin)) {
35
+ if (authorizationTypes.includes(common_1.AuthorizationType.AdminAuth)) {
38
36
  const adminApiKey = req.header("x-admin-api-key");
39
37
  const AdminAuth = yield (0, admin_auth_1.buildAdminAuth)(mongoose);
40
38
  if (adminApiKey) {
@@ -66,21 +64,6 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
66
64
  catch (err) { }
67
65
  }
68
66
  }
69
- if (authorizationTypes.includes(common_1.AuthorizationType.Admin)) {
70
- if (req.adminAuth) {
71
- let admin;
72
- try {
73
- const Admin = yield (0, admin_1.buildAdmin)(mongoose);
74
- admin = yield Admin.findOne({
75
- authIds: { $in: [(_b = req.adminAuth) === null || _b === void 0 ? void 0 : _b.id] },
76
- });
77
- if (admin) {
78
- req.admin = admin;
79
- }
80
- }
81
- catch (err) { }
82
- }
83
- }
84
67
  if (authorizationTypes.includes(common_1.AuthorizationType.Auth) ||
85
68
  authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC) ||
86
69
  authorizationTypes.includes(common_1.AuthorizationType.User)) {
@@ -98,7 +81,7 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
98
81
  }
99
82
  catch (err) { }
100
83
  }
101
- else if ((_c = req.cookies) === null || _c === void 0 ? void 0 : _c.accessToken) {
84
+ else if ((_b = req.cookies) === null || _b === void 0 ? void 0 : _b.accessToken) {
102
85
  try {
103
86
  const ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ACCESS_TOKEN_SECRET");
104
87
  if (!ACCESS_TOKEN_SECRET) {
@@ -119,15 +102,15 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
119
102
  try {
120
103
  const User = yield (0, user_1.buildUser)(mongoose);
121
104
  const user = yield User.findOne({
122
- authIds: { $in: [(_d = req.auth) === null || _d === void 0 ? void 0 : _d.id] },
105
+ authIds: { $in: [(_c = req.auth) === null || _c === void 0 ? void 0 : _c.id] },
123
106
  });
124
107
  if (user) {
125
108
  if (authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) {
126
109
  req.user = user;
127
110
  }
128
111
  else {
129
- if (((_f = (_e = user.onboarding) === null || _e === void 0 ? void 0 : _e.MX) === null || _f === void 0 ? void 0 : _f.status) === common_1.OnboardingStatus.Approved ||
130
- ((_h = (_g = user.onboarding) === null || _g === void 0 ? void 0 : _g.PE) === null || _h === void 0 ? void 0 : _h.status) === common_1.OnboardingStatus.Approved) {
112
+ if (((_e = (_d = user.onboarding) === null || _d === void 0 ? void 0 : _d.MX) === null || _e === void 0 ? void 0 : _e.status) === common_1.OnboardingStatus.Approved ||
113
+ ((_g = (_f = user.onboarding) === null || _f === void 0 ? void 0 : _f.PE) === null || _g === void 0 ? void 0 : _g.status) === common_1.OnboardingStatus.Approved) {
131
114
  req.user = user;
132
115
  }
133
116
  }
@@ -160,7 +143,8 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
160
143
  next();
161
144
  return;
162
145
  }
163
- if (authorizationTypes.includes(common_1.AuthorizationType.Admin) && req.admin) {
146
+ if (authorizationTypes.includes(common_1.AuthorizationType.AdminAuth) &&
147
+ req.adminAuth) {
164
148
  next();
165
149
  return;
166
150
  }
@@ -51,7 +51,7 @@ const getOrder = (req, res, next, mongoose, onlyBankOrders) => __awaiter(void 0,
51
51
  const User = yield (0, user_1.buildUser)(mongoose);
52
52
  const user = yield User.findById(order.userId);
53
53
  if (req.order.userId !== ((_a = req.user) === null || _a === void 0 ? void 0 : _a.toJSON().id) &&
54
- !req.admin &&
54
+ !req.adminAuth &&
55
55
  (user === null || user === void 0 ? void 0 : user.brokerId) !== ((_b = req.user) === null || _b === void 0 ? void 0 : _b.toJSON().id)) {
56
56
  throw new common_1.NotAuthorizedError();
57
57
  }
@@ -19,11 +19,12 @@ const adminRoleOrder = [
19
19
  ];
20
20
  const requireMinAdminRole = (req, res, next, minRole) => __awaiter(void 0, void 0, void 0, function* () {
21
21
  var _a;
22
- if (!req.admin) {
22
+ if (!req.adminAuth) {
23
23
  throw new common_1.AdminOnlyError();
24
24
  }
25
25
  else {
26
- if (adminRoleOrder.indexOf((_a = req.admin) === null || _a === void 0 ? void 0 : _a.role) < adminRoleOrder.indexOf(minRole)) {
26
+ if (adminRoleOrder.indexOf((_a = req.adminAuth) === null || _a === void 0 ? void 0 : _a.role) <
27
+ adminRoleOrder.indexOf(minRole)) {
27
28
  throw new common_1.GenericInputError(`Insufficient permissions. This endpoint requires at least the ${minRole} role. Contact Javier to change your access role.`);
28
29
  }
29
30
  next();
@@ -18,7 +18,7 @@ const authRoleOrder = [
18
18
  ];
19
19
  const requireMinRole = (req, res, next, minRole) => __awaiter(void 0, void 0, void 0, function* () {
20
20
  var _a;
21
- if (!req.admin && !req.validClusterApiKey) {
21
+ if (!req.adminAuth && !req.validClusterApiKey) {
22
22
  if (authRoleOrder.indexOf((_a = req.auth) === null || _a === void 0 ? void 0 : _a.role) < authRoleOrder.indexOf(minRole)) {
23
23
  throw new common_1.GenericInputError(`Insufficient permissions. This endpoint requires at least the ${minRole} role. Contact your account owner to change your access role.`);
24
24
  }
@@ -21,9 +21,8 @@ const setTrace = (req, res, next) => __awaiter(void 0, void 0, void 0, function*
21
21
  phoneNumber: (_b = req.auth) === null || _b === void 0 ? void 0 : _b.phoneNumber,
22
22
  });
23
23
  }
24
- else if (req.admin) {
24
+ else if (req.adminAuth) {
25
25
  (0, node_opentelemetry_1.setTraceAttributes)({
26
- adminId: req.admin.id,
27
26
  adminAuthId: (_c = req.adminAuth) === null || _c === void 0 ? void 0 : _c.id,
28
27
  email: (_d = req.adminAuth) === null || _d === void 0 ? void 0 : _d.email,
29
28
  });
@@ -1,16 +1,37 @@
1
- import { APIKey } from "@riocrypto/common";
1
+ import { APIKey, AdminTaskType } from "@riocrypto/common";
2
2
  import { Mongoose, Model, Document } from "mongoose";
3
+ import { AdminRole } from "@riocrypto/common/build/types/admin-role";
3
4
  interface AdminAuthAttrs {
4
- email: string;
5
5
  password: string;
6
+ email: string;
7
+ slackWebhookUrl: string;
8
+ acceptingTasks?: boolean;
9
+ assignedTaskTypes: AdminTaskType[];
10
+ privileges: string[];
11
+ userAuthId?: string;
12
+ firstName: string;
13
+ middleName?: string;
14
+ lastName: string;
15
+ secondLastName?: string;
16
+ role: AdminRole;
6
17
  previousPasswords?: string[];
7
18
  authenticatorSecret?: string;
8
19
  apiKeys?: APIKey[];
9
20
  isDisabled?: boolean;
10
21
  }
11
22
  interface AdminAuthDoc extends Document {
12
- email: string;
13
23
  password: string;
24
+ email: string;
25
+ slackWebhookUrl: string;
26
+ acceptingTasks?: boolean;
27
+ assignedTaskTypes: AdminTaskType[];
28
+ privileges: string[];
29
+ userAuthId?: string;
30
+ role: AdminRole;
31
+ firstName?: string;
32
+ middleName?: string;
33
+ lastName?: string;
34
+ secondLastName?: string;
14
35
  previousPasswords?: string[];
15
36
  authenticatorSecret?: string;
16
37
  apiKeys?: APIKey[];
@@ -31,6 +31,43 @@ const buildAdminAuth = (mongoose) => {
31
31
  required: false,
32
32
  },
33
33
  ],
34
+ firstName: {
35
+ type: String,
36
+ },
37
+ middleName: {
38
+ type: String,
39
+ },
40
+ lastName: {
41
+ type: String,
42
+ },
43
+ secondLastName: {
44
+ type: String,
45
+ },
46
+ role: {
47
+ type: String,
48
+ },
49
+ slackWebhookUrl: {
50
+ type: String,
51
+ required: true,
52
+ },
53
+ privileges: [
54
+ {
55
+ type: String,
56
+ required: true,
57
+ },
58
+ ],
59
+ acceptingTasks: {
60
+ type: Boolean,
61
+ },
62
+ assignedTaskTypes: [
63
+ {
64
+ type: String,
65
+ required: true,
66
+ },
67
+ ],
68
+ userAuthId: {
69
+ type: String,
70
+ },
34
71
  authenticatorSecret: {
35
72
  type: String,
36
73
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1495",
3
+ "version": "1.0.1500",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "@google-cloud/storage": "^6.9.5",
29
29
  "@google-cloud/vision": "^4.0.2",
30
30
  "@hyperdx/node-opentelemetry": "^0.4.2",
31
- "@riocrypto/common": "^1.0.1336",
31
+ "@riocrypto/common": "^1.0.1338",
32
32
  "@types/express": "^4.17.13",
33
33
  "axios": "^0.27.2",
34
34
  "ccxt": "^3.0.30",
@@ -1,33 +0,0 @@
1
- import { AdminTaskType } from "@riocrypto/common";
2
- import { AdminRole } from "@riocrypto/common/build/types/admin-role";
3
- import { Mongoose, Model, Document } from "mongoose";
4
- interface AdminAttrs {
5
- createdAt: Date;
6
- adminAuthIds?: string[];
7
- name: string;
8
- email: string;
9
- slackWebhookUrl: string;
10
- acceptingTasks?: boolean;
11
- assignedTaskTypes: AdminTaskType[];
12
- privileges: string[];
13
- userAuthId?: string;
14
- role: AdminRole;
15
- }
16
- interface AdminModel extends Model<AdminDoc> {
17
- build(attrs: AdminAttrs): AdminDoc;
18
- }
19
- interface AdminDoc extends Document {
20
- _id: string;
21
- createdAt: Date;
22
- adminAuthIds?: string[];
23
- name: string;
24
- email: string;
25
- slackWebhookUrl: string;
26
- acceptingTasks?: boolean;
27
- assignedTaskTypes: AdminTaskType[];
28
- privileges: string[];
29
- userAuthId?: string;
30
- role: AdminRole;
31
- }
32
- declare const buildAdmin: (mongoose: Mongoose) => AdminModel;
33
- export { buildAdmin, AdminDoc };
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildAdmin = void 0;
4
- const buildAdmin = (mongoose) => {
5
- // if model is already defined, return it
6
- if (mongoose.models.Admin) {
7
- return mongoose.model("Admin");
8
- }
9
- const AdminSchema = new mongoose.Schema({
10
- adminAuthIds: [
11
- {
12
- type: String,
13
- },
14
- ],
15
- createdAt: {
16
- type: mongoose.Schema.Types.Date,
17
- required: true,
18
- },
19
- name: {
20
- type: String,
21
- required: true,
22
- },
23
- email: {
24
- type: String,
25
- required: true,
26
- },
27
- role: {
28
- type: String,
29
- },
30
- slackWebhookUrl: {
31
- type: String,
32
- required: true,
33
- },
34
- privileges: [
35
- {
36
- type: String,
37
- required: true,
38
- },
39
- ],
40
- acceptingTasks: {
41
- type: Boolean,
42
- },
43
- assignedTaskTypes: [
44
- {
45
- type: String,
46
- required: true,
47
- },
48
- ],
49
- userAuthId: {
50
- type: String,
51
- },
52
- }, {
53
- toJSON: {
54
- transform(doc, ret) {
55
- ret.id = ret._id.valueOf();
56
- delete ret._id;
57
- delete ret.__v;
58
- },
59
- },
60
- });
61
- AdminSchema.statics.build = (attrs) => {
62
- return new Admin(attrs);
63
- };
64
- const Admin = mongoose.model("Admin", AdminSchema);
65
- return Admin;
66
- };
67
- exports.buildAdmin = buildAdmin;