@riocrypto/common 1.0.407 → 1.0.409

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,8 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class AdminOnlyError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ }[];
8
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdminOnlyError = void 0;
4
+ const custom_error_1 = require("./custom-error");
5
+ class AdminOnlyError extends custom_error_1.CustomError {
6
+ constructor() {
7
+ super("This endpoint can only be called by admins");
8
+ this.statusCode = 401;
9
+ Object.setPrototypeOf(this, AdminOnlyError.prototype);
10
+ }
11
+ serializeErrors() {
12
+ return [{ message: "This endpoint can only be called by admins" }];
13
+ }
14
+ }
15
+ exports.AdminOnlyError = AdminOnlyError;
package/build/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export * from "./errors/api-key-not-found-error";
20
20
  export * from "./errors/missing-user-error";
21
21
  export * from "./errors/missing-kyc-approval-error";
22
22
  export * from "./errors/wrong-order-state-error";
23
+ export * from "./errors/admin-only-error";
23
24
  export * from "./middlewares/error-handler";
24
25
  export * from "./middlewares/validate-request";
25
26
  export * from "./middlewares/current-auth";
package/build/index.js CHANGED
@@ -36,6 +36,7 @@ __exportStar(require("./errors/api-key-not-found-error"), exports);
36
36
  __exportStar(require("./errors/missing-user-error"), exports);
37
37
  __exportStar(require("./errors/missing-kyc-approval-error"), exports);
38
38
  __exportStar(require("./errors/wrong-order-state-error"), exports);
39
+ __exportStar(require("./errors/admin-only-error"), exports);
39
40
  __exportStar(require("./middlewares/error-handler"), exports);
40
41
  __exportStar(require("./middlewares/validate-request"), exports);
41
42
  __exportStar(require("./middlewares/current-auth"), exports);
@@ -38,7 +38,6 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
38
38
  catch (err) { }
39
39
  }
40
40
  if ((_c = (_b = req.currentAuth) === null || _b === void 0 ? void 0 : _b.missing) === null || _c === void 0 ? void 0 : _c.includes("password")) {
41
- console.log("hit");
42
41
  throw new missing_password_error_1.MissingPasswordError();
43
42
  }
44
43
  if ((_e = (_d = req.currentAuth) === null || _d === void 0 ? void 0 : _d.missing) === null || _e === void 0 ? void 0 : _e.includes("securityQuestion")) {
@@ -63,9 +62,6 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
63
62
  phoneNumber: req.currentAuth.phoneNumber,
64
63
  attributes: { $ne: user_attribute_1.UserAttribute.deleted },
65
64
  });
66
- if (!individualUser) {
67
- throw new missing_user_error_1.MissingUserError();
68
- }
69
65
  }
70
66
  catch (err) {
71
67
  individualUser = null;
@@ -76,9 +72,6 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
76
72
  phoneNumber: req.currentAuth.phoneNumber,
77
73
  attributes: { $ne: user_attribute_1.UserAttribute.deleted },
78
74
  });
79
- if (!businessUser) {
80
- throw new missing_user_error_1.MissingUserError();
81
- }
82
75
  }
83
76
  catch (err) {
84
77
  businessUser = null;
@@ -135,7 +128,9 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
135
128
  if (missingKYC) {
136
129
  throw new missing_kyc_approval_error_1.MissingKYCApprovalError();
137
130
  }
138
- if ((_g = req.cookies) === null || _g === void 0 ? void 0 : _g.jwt) {
131
+ if ((authorizationTypes.includes(authorization_type_1.AuthorizationType.User) ||
132
+ authorizationTypes.includes(authorization_type_1.AuthorizationType.UserNoKYC)) &&
133
+ ((_g = req.cookies) === null || _g === void 0 ? void 0 : _g.jwt)) {
139
134
  throw new missing_user_error_1.MissingUserError();
140
135
  }
141
136
  throw new not_authorized_error_1.NotAuthorizedError();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common",
3
- "version": "1.0.407",
3
+ "version": "1.0.409",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",