@sendhome/common 1.0.168 → 1.0.170

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.
@@ -1,6 +1,6 @@
1
1
  import { Subjects } from "../subjects/subjects";
2
2
  import { OrderStatus } from "../types/order-status";
3
- import { CompanyType } from "../types/company-type";
3
+ import { Category } from "../types/category";
4
4
  import { ReceiveCountry } from "../types/receive-country";
5
5
  import { SendCountry } from "../types/send-country";
6
6
  interface CardPaymentDetails {
@@ -23,7 +23,7 @@ export interface OrderCreatedEvent {
23
23
  data: {
24
24
  id: string;
25
25
  order_number: number;
26
- order_type: CompanyType;
26
+ order_type: Category;
27
27
  items: string[];
28
28
  pay_amount: number;
29
29
  receive_amount: number;
@@ -1,6 +1,6 @@
1
1
  import { Subjects } from "../subjects/subjects";
2
2
  import { OrderStatus } from "../types/order-status";
3
- import { CompanyType } from "../types/company-type";
3
+ import { Category } from "../types/category";
4
4
  import { ReceiveCountry } from "../types/receive-country";
5
5
  import { SendCountry } from "../types/send-country";
6
6
  interface CardPaymentDetails {
@@ -23,7 +23,7 @@ export interface OrderUpdatedEvent {
23
23
  data: {
24
24
  id: string;
25
25
  order_number: number;
26
- order_type: CompanyType;
26
+ order_type: Category;
27
27
  items: string[];
28
28
  pay_amount: number;
29
29
  receive_amount: number;
@@ -1,7 +1,6 @@
1
1
  import { Subjects } from "../subjects/subjects";
2
- import { ProductClass } from "../types/product_class";
3
2
  import { ProductStatus } from "../types/product-status";
4
- import { CompanyType } from "../types/company-type";
3
+ import { Category } from "../types/category";
5
4
  import { UnitType } from "../types/unit-type";
6
5
  import { ReceiveCountry } from "../types/receive-country";
7
6
  interface IGroceriesFields {
@@ -42,8 +41,7 @@ export interface ProductCreatedEvent {
42
41
  product_id: number;
43
42
  name: string;
44
43
  description: string;
45
- product_type: CompanyType;
46
- product_class: ProductClass;
44
+ product_category: Category;
47
45
  brand: string;
48
46
  unit: UnitType;
49
47
  unit_value: number;
@@ -1,7 +1,6 @@
1
1
  import { Subjects } from "../subjects/subjects";
2
- import { ProductClass } from "../types/product_class";
3
2
  import { ProductStatus } from "../types/product-status";
4
- import { CompanyType } from "../types/company-type";
3
+ import { Category } from "../types/category";
5
4
  import { UnitType } from "../types/unit-type";
6
5
  import { ReceiveCountry } from "../types/receive-country";
7
6
  interface IGroceriesFields {
@@ -42,8 +41,7 @@ export interface ProductUpdatedEvent {
42
41
  product_id: number;
43
42
  name: string;
44
43
  description: string;
45
- product_type: CompanyType;
46
- product_class: ProductClass;
44
+ product_category: Category;
47
45
  brand: string;
48
46
  unit: UnitType;
49
47
  unit_value: number;
@@ -1,8 +1,7 @@
1
1
  import { Subjects } from "../subjects/subjects";
2
2
  import { ProductStatus } from "../types/product-status";
3
3
  import { ReceiveCountry } from "../types/receive-country";
4
- import { CompanyType } from "../types/company-type";
5
- import { ProductClass } from "../types/product_class";
4
+ import { Category } from "../types/category";
6
5
  import { UnitType } from "../types/unit-type";
7
6
  interface IGroceriesFields {
8
7
  expiration_date?: Date;
@@ -39,8 +38,7 @@ interface ProductAttrs {
39
38
  product_id: number;
40
39
  name: string;
41
40
  description: string;
42
- product_type: CompanyType;
43
- product_class: ProductClass;
41
+ product_category: Category;
44
42
  brand?: string;
45
43
  unit?: UnitType;
46
44
  unit_value?: number;
@@ -55,7 +53,7 @@ export interface ProductItemCreatedEvent {
55
53
  data: {
56
54
  id: string;
57
55
  price: number;
58
- product_type: CompanyType;
56
+ product_category: Category;
59
57
  category: string;
60
58
  brand: string;
61
59
  product: ProductAttrs | string;
@@ -1,8 +1,7 @@
1
1
  import { Subjects } from "../subjects/subjects";
2
2
  import { ProductStatus } from "../types/product-status";
3
3
  import { ReceiveCountry } from "../types/receive-country";
4
- import { CompanyType } from "../types/company-type";
5
- import { ProductClass } from "../types/product_class";
4
+ import { Category } from "../types/category";
6
5
  import { UnitType } from "../types/unit-type";
7
6
  interface IGroceriesFields {
8
7
  expiration_date?: Date;
@@ -39,8 +38,7 @@ interface ProductAttrs {
39
38
  product_id: number;
40
39
  name: string;
41
40
  description: string;
42
- product_type: CompanyType;
43
- product_class: ProductClass;
41
+ product_category: Category;
44
42
  brand?: string;
45
43
  unit?: UnitType;
46
44
  unit_value?: number;
@@ -55,7 +53,7 @@ export interface ProductItemUpdatedEvent {
55
53
  data: {
56
54
  id: string;
57
55
  price: number;
58
- product_type: CompanyType;
56
+ product_category: Category;
59
57
  category: string;
60
58
  brand: string;
61
59
  product: ProductAttrs | string;
@@ -13,8 +13,9 @@ declare global {
13
13
  }
14
14
  }
15
15
  }
16
- export declare const checkUserAccess: (requiredAccountType: string, requiredLevels?: {
17
- provider?: string[] | undefined;
18
- admin?: string[] | undefined;
19
- } | undefined) => (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
16
+ export declare const checkUserAccess: (allowedRoles: {
17
+ client?: string[];
18
+ provider?: string[];
19
+ admin?: string[];
20
+ }) => (req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
20
21
  export {};
@@ -1,28 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkUserAccess = void 0;
4
- const checkUserAccess = (requiredAccountType, requiredLevels) => {
4
+ const checkUserAccess = (allowedRoles) => {
5
5
  return (req, res, next) => {
6
- const { account_type, provider_level = '', admin_level = '' } = req.currentUser; // Default to empty string if undefined
6
+ const { account_type, provider_level = "", admin_level = "", } = req.currentUser || {};
7
7
  console.log("req.currentUser", req.currentUser);
8
- console.log("requiredLevels", requiredLevels);
9
- // Check if the user's account_type matches the required account_type
10
- if (account_type !== requiredAccountType) {
11
- return res.status(403).send({ error: 'You do not have the necessary permissions to access this resource' });
8
+ console.log("allowedRoles", allowedRoles);
9
+ // Check for client access if account_type is 'client' and client level is in allowedRoles.client
10
+ if (account_type === "client" && allowedRoles.client) {
11
+ if (allowedRoles.client.includes("client")) {
12
+ return next(); // Client is allowed to access this route
13
+ }
14
+ else {
15
+ return res
16
+ .status(403)
17
+ .send({ error: "Clinet level not authorized for this resource" });
18
+ }
12
19
  }
13
- // Check provider levels for 'provider' users
14
- if (account_type === 'provider' && (requiredLevels === null || requiredLevels === void 0 ? void 0 : requiredLevels.provider)) {
15
- if (!requiredLevels.provider.includes(provider_level)) {
16
- return res.status(403).send({ error: 'Provider level not authorized for this resource' });
20
+ // Check for provider access if account_type is 'provider' and provider level is in allowedRoles.provider
21
+ if (account_type === "provider" && allowedRoles.provider) {
22
+ if (allowedRoles.provider.includes(provider_level)) {
23
+ return next(); // Provider level is authorized
24
+ }
25
+ else {
26
+ return res
27
+ .status(403)
28
+ .send({ error: "Provider level not authorized for this resource" });
17
29
  }
18
30
  }
19
- // Check admin levels for 'admin' users
20
- if (account_type === 'admin' && (requiredLevels === null || requiredLevels === void 0 ? void 0 : requiredLevels.admin)) {
21
- if (!requiredLevels.admin.includes(admin_level)) {
22
- return res.status(403).send({ error: 'Admin level not authorized for this resource' });
31
+ // Check for admin access if account_type is 'admin' and admin level is in allowedRoles.admin
32
+ if (account_type === "admin" && allowedRoles.admin) {
33
+ if (allowedRoles.admin.includes(admin_level)) {
34
+ return next(); // Admin level is authorized
35
+ }
36
+ else {
37
+ return res
38
+ .status(403)
39
+ .send({ error: "Admin level not authorized for this resource" });
23
40
  }
24
41
  }
25
- next();
42
+ // If none of the conditions match, deny access
43
+ return res
44
+ .status(403)
45
+ .send({
46
+ error: "You do not have the necessary permissions to access this resource",
47
+ });
26
48
  };
27
49
  };
28
50
  exports.checkUserAccess = checkUserAccess;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sendhome/common",
3
- "version": "1.0.168",
3
+ "version": "1.0.170",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",