shuttlepro-shared 1.3.17 → 1.3.19

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.
Files changed (66) hide show
  1. package/constants/index.js +0 -15
  2. package/index.js +0 -8
  3. package/middlewares/checkPermission/index.js +36 -23
  4. package/models/UserRole.js +119 -1
  5. package/models.js +1 -62
  6. package/package.json +2 -13
  7. package/common/repositories/chatMember.repository.js +0 -9
  8. package/common/repositories/customerProfile.repository.js +0 -147
  9. package/common/repositories/customerTimeline.repository.js +0 -78
  10. package/common/repositories/descriptionTemplates.repository.js +0 -229
  11. package/common/repositories/index.js +0 -34
  12. package/common/repositories/integration.repository.js +0 -210
  13. package/common/repositories/label.repository.js +0 -95
  14. package/common/repositories/notificationSettings.repository.js +0 -95
  15. package/common/repositories/role.repository.js +0 -333
  16. package/common/repositories/settings.repository.js +0 -32
  17. package/common/repositories/shipper.repository.js +0 -77
  18. package/common/repositories/socialMediaSetting.repository.js +0 -33
  19. package/common/repositories/user.repository.js +0 -150
  20. package/common/repositories/userPermission.repository.js +0 -228
  21. package/common/repositories/userRepository.js +0 -31
  22. package/common/repositories/userRole.repository.js +0 -235
  23. package/common/repositories/userRolePermission.repository.js +0 -59
  24. package/common/repositories/workspace.repository.js +0 -147
  25. package/config/bull.js +0 -78
  26. package/config/config.js +0 -14
  27. package/config/database.js +0 -4
  28. package/config/index.js +0 -13
  29. package/config/redis.js +0 -196
  30. package/config/socket.js +0 -172
  31. package/models/AgentActivity.js +0 -192
  32. package/models/Assignment.js +0 -23
  33. package/models/BusinessDistribution.js +0 -23
  34. package/models/Card.js +0 -144
  35. package/models/CardComments.js +0 -33
  36. package/models/ChatMember.js +0 -17
  37. package/models/Chatbot.js +0 -20
  38. package/models/Checkpoint.js +0 -50
  39. package/models/City.js +0 -17
  40. package/models/Column.js +0 -28
  41. package/models/Conversation.js +0 -87
  42. package/models/Customer.js +0 -36
  43. package/models/CustomerProfile.js +0 -30
  44. package/models/CustomerTimeline.js +0 -28
  45. package/models/DefaultRolePermission.js +0 -34
  46. package/models/DescriptionTemplate.js +0 -22
  47. package/models/Integration.js +0 -51
  48. package/models/Label.js +0 -42
  49. package/models/Message.js +0 -47
  50. package/models/NewProduct.js +0 -71
  51. package/models/NotificationSettings.js +0 -130
  52. package/models/Order.js +0 -254
  53. package/models/OrderProduct.js +0 -37
  54. package/models/Profile.js +0 -127
  55. package/models/Report.js +0 -27
  56. package/models/Setting.js +0 -18
  57. package/models/Shipper.js +0 -62
  58. package/models/SocialMediaSetting.js +0 -28
  59. package/models/Status.js +0 -58
  60. package/models/StatusType.js +0 -10
  61. package/models/Step.js +0 -50
  62. package/models/Type.js +0 -25
  63. package/models/UserWorkflow.js +0 -46
  64. package/models/Workspace.js +0 -308
  65. package/utils/decorator-factory.js +0 -264
  66. package/utils/logger.js +0 -41
@@ -23,18 +23,3 @@ exports.GenericMessages = {
23
23
  URL_FETCH_SUCCESS: "Url Fetched successfully!",
24
24
  WORKSPACE_NOT_FOUND: "Workspace not found!",
25
25
  };
26
-
27
- exports.DYNAMIC_FIELD_TYPES = [
28
- "text",
29
- "autocomplete",
30
- "radio",
31
- "text area",
32
- "number",
33
- "date",
34
- "time",
35
- "email",
36
- "range",
37
- "url",
38
- "colour",
39
- "file",
40
- ];
package/index.js CHANGED
@@ -1,15 +1,7 @@
1
1
  const sharedModels = require("./models");
2
2
  const sharedFunctions = require("./functions");
3
- const logger = require("./utils/logger");
4
- const shuttlePro = require("./utils/decorator-factory");
5
- const configs = require("./config");
6
- const repositories = require("./common/repositories");
7
3
 
8
4
  module.exports = {
9
5
  sharedModels,
10
6
  sharedFunctions,
11
- logger,
12
- shuttlePro,
13
- configs,
14
- repositories,
15
7
  };
@@ -31,29 +31,42 @@ exports.checkPermission = async (req, res, next, values) => {
31
31
  const accessToken = token.split(" ")[1];
32
32
  const body = getBodyFromDecodeToken(accessToken);
33
33
  if (body) {
34
- const { module, action } = values;
35
- const moduleObj = getModule(body, module);
36
- if (moduleObj && moduleObj.includes(action)) {
37
- req.user = {
38
- id: body.id,
39
- type: body.type,
40
- email: body.email,
41
- firstName: body.firstName,
42
- lastName: body.lastName,
43
- suspended: body.suspended,
44
- isVerified: body.isVerified,
45
- role: body.role,
46
- isMember: body.isMember,
47
- uuid: body.uuid,
48
- };
49
- req.currentModulePermission = moduleObj;
50
- return next();
51
- } else {
52
- return res.status(HttpStatusCode.UNAUTHORIZED).json({
53
- code: HttpStatusCode.UNAUTHORIZED,
54
- message: GenericMessages.PERMISSION_DENIED,
55
- });
56
- }
34
+ req.user = {
35
+ id: body.id,
36
+ type: body.type,
37
+ email: body.email,
38
+ firstName: body.firstName,
39
+ lastName: body.lastName,
40
+ suspended: body.suspended,
41
+ isVerified: body.isVerified,
42
+ role: body.role,
43
+ isMember: body.isMember,
44
+ uuid: body.uuid,
45
+ };
46
+ return next();
47
+ // const { module, action } = values;
48
+ // const moduleObj = getModule(body, module);
49
+ // if (moduleObj && moduleObj.includes(action)) {
50
+ // req.user = {
51
+ // id: body.id,
52
+ // type: body.type,
53
+ // email: body.email,
54
+ // firstName: body.firstName,
55
+ // lastName: body.lastName,
56
+ // suspended: body.suspended,
57
+ // isVerified: body.isVerified,
58
+ // role: body.role,
59
+ // isMember: body.isMember,
60
+ // uuid: body.uuid,
61
+ // };
62
+ // req.currentModulePermission = moduleObj;
63
+ // return next();
64
+ // } else {
65
+ // return res.status(HttpStatusCode.UNAUTHORIZED).json({
66
+ // code: HttpStatusCode.UNAUTHORIZED,
67
+ // message: GenericMessages.PERMISSION_DENIED,
68
+ // });
69
+ // }
57
70
  }
58
71
  return res.status(HttpStatusCode.UNAUTHORIZED).json({
59
72
  code: HttpStatusCode.UNAUTHORIZED,
@@ -1,6 +1,15 @@
1
1
  const mongoose = require("mongoose");
2
2
  const { Schema } = mongoose;
3
3
 
4
+ const daySchema = new Schema({
5
+ day: { type: String, required: true },
6
+ startTime: { type: String, required: false },
7
+ endTime: { type: String, required: false },
8
+ breakStartTime: { type: String, required: false },
9
+ breakEndTime: { type: String, required: false },
10
+ lateThreshold: { type: String, required: false },
11
+ });
12
+
4
13
  const userRoleSchema = new Schema(
5
14
  {
6
15
  userId: {
@@ -23,7 +32,10 @@ const userRoleSchema = new Schema(
23
32
  default: null,
24
33
  },
25
34
  isOwner: { type: Boolean, default: false },
26
- userShift: { type: Object, default: null },
35
+ userShift: {
36
+ shiftName: { type: String, required: false },
37
+ days: { type: [daySchema], required: false },
38
+ },
27
39
  createdBy: {
28
40
  type: mongoose.Schema.Types.ObjectId,
29
41
  ref: "User",
@@ -40,6 +52,112 @@ const userRoleSchema = new Schema(
40
52
 
41
53
  const UserRole = mongoose.model("UserRole", userRoleSchema);
42
54
 
55
+ const convertPermissionsArrayToObject = (originalArray) => {
56
+ return originalArray?.reduce((acc, item) => {
57
+ const { id, actions, integrationPermissions, ...extras } = item;
58
+ const formattedExtras = {};
59
+ if (extras.deletable !== undefined) {
60
+ formattedExtras.deletable = extras.deletable;
61
+ }
62
+ if (extras.createUpdateable !== undefined) {
63
+ formattedExtras.createUpdateable = extras.createUpdateable;
64
+ }
65
+ acc[id] = {
66
+ actions: Object.keys(actions).filter((action) => actions[action]),
67
+ ...formattedExtras,
68
+ ...(integrationPermissions && {
69
+ integrationPermissions: Object.entries(integrationPermissions)
70
+ .filter(([_, allowed]) => allowed)
71
+ .map(([key]) => key),
72
+ }),
73
+ };
74
+ return acc;
75
+ }, {});
76
+ };
77
+
78
+ const getUserRoleWithPermissions = async (workspaceId, userId) => {
79
+ try {
80
+ let data = await UserRole.findOne({
81
+ workspaceId: workspaceId,
82
+ userId: userId,
83
+ })
84
+ .populate({
85
+ path: "roleId",
86
+ select:
87
+ "id name userId userShift permissionId modulePermissions defaultModule",
88
+ populate: [{ path: "permissionId", select: "id name" }],
89
+ })
90
+ .lean()
91
+ .exec();
92
+ return {
93
+ ...data,
94
+ roleId: data?.roleId?._id?.toString() || "",
95
+ role: data?.roleId?.name || "",
96
+ permissions:
97
+ convertPermissionsArrayToObject(
98
+ data?.roleId?.modulePermissions?.modules
99
+ ) || [],
100
+ parentRole: data?.roleId?.permissionId?.name || "",
101
+ parentRoleId: data?.roleId?.permissionId?._id?.toString() || "",
102
+ defaultModule: data?.roleId?.defaultModule || "",
103
+ };
104
+ } catch (err) {
105
+ console.error("Error in getUserRole:", err);
106
+ return null;
107
+ }
108
+ };
109
+
110
+ const getUserPermissions = async (workspaceId, userId) => {
111
+ try {
112
+ let data = await UserRole.findOne({
113
+ workspaceId: workspaceId,
114
+ userId: userId,
115
+ })
116
+ .select("roleId userId")
117
+ .populate({
118
+ path: "roleId",
119
+ select: "modulePermissions",
120
+ })
121
+ .lean()
122
+ .exec();
123
+ return (
124
+ convertPermissionsArrayToObject(
125
+ data?.roleId?.modulePermissions?.modules
126
+ ) || null
127
+ );
128
+ } catch (err) {
129
+ console.error("Error in getUserRole:", err);
130
+ return null;
131
+ }
132
+ };
133
+
134
+ const getChannelsPermissions = async (workspaceId, userId) => {
135
+ try {
136
+ let data = await UserRole.findOne({
137
+ workspaceId: workspaceId,
138
+ userId: userId,
139
+ })
140
+ .select("roleId userId")
141
+ .populate({
142
+ path: "roleId",
143
+ select: "modulePermissions",
144
+ })
145
+ .lean()
146
+ .exec();
147
+ return (
148
+ convertPermissionsArrayToObject(
149
+ data?.roleId?.modulePermissions?.modules
150
+ )?.["conversations"]?.["integrationPermissions"] || []
151
+ );
152
+ } catch (err) {
153
+ console.error("Error in getUserRole:", err);
154
+ return null;
155
+ }
156
+ };
157
+
43
158
  module.exports = {
44
159
  UserRole,
160
+ getChannelsPermissions,
161
+ getUserPermissions,
162
+ getUserRoleWithPermissions,
45
163
  };
package/models.js CHANGED
@@ -1,6 +1,4 @@
1
1
  const Website = require("./models/Website");
2
- const ChatMember = require("./models/ChatMember");
3
- const DescriptionTemplate = require("./models/DescriptionTemplate");
4
2
  const ProductQueue = require("./models/ProductQueue");
5
3
  const ColumnPreference = require("./models/ColumnPreference");
6
4
  const UserPermission = require("./models/UserPermission");
@@ -14,36 +12,8 @@ const AutoSchedulerSchema = require("./models/AutoScheduler");
14
12
  const ActivityLogs = require("./models/ActivityLogs");
15
13
  const UserRole = require("./models/UserRole");
16
14
  const OrderQueue = require("./models/OrderQueue");
17
- const AgentActivity = require("./models/AgentActivity");
18
- const Assignment = require("./models/Assignment");
19
- const BusinessDistribution = require("./models/BusinessDistribution");
20
- const CardComments = require("./models/CardComments");
21
- const Checkpoint = require("./models/Checkpoint");
22
- const City = require("./models/City");
23
- const Column = require("./models/Column");
24
- const Conversation = require("./models/Conversation");
25
- const Customer = require("./models/Customer");
26
- const Integration = require("./models/Integration");
27
- const Label = require("./models/Label");
28
- const Message = require("./models/Message");
29
- const Order = require("./models/Order");
30
- const OrderProduct = require("./models/OrderProduct");
31
- const Report = require("./models/Report");
32
- const Shipper = require("./models/Shipper");
33
- const Status = require("./models/Status");
34
- const StatusType = require("./models/StatusType");
35
- const Type = require("./models/Type");
36
- const Workspace = require("./models/Workspace");
37
- const Card = require("./models/Card");
38
- const Profile = require("./models/Profile");
39
- const Chatbot = require("./models/Chatbot");
40
- const Step = require("./models/Step");
41
15
  const Role = require("./models/Role");
42
- const NewProduct = require("./models/NewProduct");
43
- const NotificationSettings = require("./models/NotificationSettings");
44
- const UserWorkflow = require("./models/UserWorkflow");
45
- const Setting = require("./models/Setting");
46
- const CustomerProfile = require("./models/CustomerProfile");
16
+
47
17
  module.exports = {
48
18
  Website,
49
19
  ProductQueue,
@@ -59,36 +29,5 @@ module.exports = {
59
29
  ActivityLogs,
60
30
  UserRole,
61
31
  OrderQueue,
62
- AgentActivity,
63
- Assignment,
64
- BusinessDistribution,
65
- CardComments,
66
- Checkpoint,
67
- Column,
68
- Conversation,
69
- City,
70
- Customer,
71
- Integration,
72
- Label,
73
- Message,
74
- Order,
75
- OrderProduct,
76
- Report,
77
- Shipper,
78
- Status,
79
- Type,
80
- Workspace,
81
- StatusType,
82
- Card,
83
- DescriptionTemplate,
84
- Profile,
85
- ChatMember,
86
- Chatbot,
87
- Step,
88
32
  Role,
89
- NewProduct,
90
- NotificationSettings,
91
- UserWorkflow,
92
- Setting,
93
- CustomerProfile,
94
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shuttlepro-shared",
3
- "version": "1.3.17",
3
+ "version": "1.3.19",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,18 +11,7 @@
11
11
  "license": "ISC",
12
12
  "access": "restricted",
13
13
  "dependencies": {
14
- "@babel/core": "^7.22.5",
15
- "@babel/plugin-proposal-class-properties": "^7.18.6",
16
- "@babel/plugin-proposal-decorators": "^7.22.5",
17
- "@babel/preset-env": "^7.22.5",
18
- "@babel/register": "^7.22.5",
19
- "bull": "^4.10.4",
20
- "cors": "^2.8.5",
21
- "express": "^4.17.1",
22
- "helmet": "^8.0.0",
23
14
  "jsonwebtoken": "^9.0.2",
24
- "mongoose": "^8.7.1",
25
- "redis": "^4.6.14",
26
- "socket.io": "^4.8.1"
15
+ "mongoose": "^8.7.1"
27
16
  }
28
17
  }
@@ -1,9 +0,0 @@
1
- const ChatMember = require("../../models/ChatMember");
2
-
3
- const findChatMemberById = async (id) => {
4
- return await ChatMember.findById(id).select("userName phoneNo email");
5
- };
6
-
7
- module.exports = {
8
- findChatMemberById,
9
- };
@@ -1,147 +0,0 @@
1
- const { getRedisData, setRedisData } = require("../../config/redis");
2
- const CustomerProfile = require("../../models/CustomerProfile");
3
-
4
- const CACHE_KEY_ALL = "customer_profiles_all";
5
-
6
- const getCachedAllCustomerProfiles = async () => {
7
- let profiles = await getRedisData(CACHE_KEY_ALL);
8
- if (!profiles) {
9
- profiles = await CustomerProfile.find({}).lean().exec();
10
- await setRedisData(CACHE_KEY_ALL, profiles);
11
- }
12
- return profiles;
13
- };
14
-
15
- const updateCachedAllCustomerProfiles = async () => {
16
- const profiles = await CustomerProfile.find({}).lean().exec();
17
- await setRedisData(CACHE_KEY_ALL, profiles);
18
- };
19
-
20
- const getCachedCustomerProfiles = async (workspaceId) => {
21
- const allProfiles = await getCachedAllCustomerProfiles();
22
- return allProfiles.filter((profile) => profile.workspaceId === workspaceId);
23
- };
24
-
25
- const createCustomerProfile = async (data) => {
26
- const newProfile = new CustomerProfile(data);
27
- const savedProfile = await newProfile.save();
28
-
29
- updateCachedAllCustomerProfiles();
30
- return savedProfile;
31
- };
32
-
33
- const findCustomerProfilesByWorkspaceId = async (workspaceId) => {
34
- return await getCachedCustomerProfiles(workspaceId);
35
- };
36
-
37
- const findCustomerProfilesByWorkspace = async (workspaceId, filter = {}) => {
38
- const profiles = await getCachedCustomerProfiles(workspaceId);
39
- return profiles.filter((profile) =>
40
- Object.entries(filter).every(([key, value]) => profile[key] === value)
41
- );
42
- };
43
-
44
- const findCustomerProfileByFilter = async (
45
- filter = {},
46
- bodyFilter = {},
47
- workspaceId = null
48
- ) => {
49
- const allProfiles = await getCachedAllCustomerProfiles();
50
-
51
- const filtered = workspaceId
52
- ? allProfiles.filter((p) => p.workspaceId === workspaceId)
53
- : allProfiles;
54
-
55
- return (
56
- filtered.find(
57
- (profile) =>
58
- Object.entries(filter).every(
59
- ([key, value]) => profile[key] === value
60
- ) &&
61
- Object.entries(bodyFilter).every(
62
- ([key, value]) => profile.body?.[key] === value
63
- )
64
- ) || null
65
- );
66
- };
67
-
68
- const findAllCustomerProfilesByFilter = async (
69
- filter = {},
70
- bodyFilter = {},
71
- workspaceId = null
72
- ) => {
73
- const allProfiles = await getCachedAllCustomerProfiles();
74
-
75
- const filtered = workspaceId
76
- ? allProfiles.filter((p) => p.workspaceId === workspaceId)
77
- : allProfiles;
78
-
79
- return (
80
- filtered.filter(
81
- (profile) =>
82
- Object.entries(filter).every(
83
- ([key, value]) => profile[key] === value
84
- ) &&
85
- Object.entries(bodyFilter).every(
86
- ([key, value]) => profile.body?.[key] === value
87
- )
88
- ) || []
89
- );
90
- };
91
-
92
- const updateCustomerProfile = async (id, data) => {
93
- const updated = await CustomerProfile.findByIdAndUpdate(id, data, {
94
- new: true,
95
- }).exec();
96
-
97
- if (updated) {
98
- updateCachedAllCustomerProfiles();
99
- }
100
-
101
- return updated;
102
- };
103
-
104
- const updateCustomerProfileByFilter = async (
105
- filter,
106
- data,
107
- workspaceId = null
108
- ) => {
109
- const query = workspaceId ? { ...filter, workspaceId } : filter;
110
-
111
- const updated = await CustomerProfile.findOneAndUpdate(query, data, {
112
- new: true,
113
- }).exec();
114
-
115
- if (updated) {
116
- updateCachedAllCustomerProfiles();
117
- }
118
-
119
- return updated;
120
- };
121
-
122
- const deleteCustomerProfile = async (id) => {
123
- const deleted = await CustomerProfile.findByIdAndDelete(id).exec();
124
-
125
- if (deleted) {
126
- updateCachedAllCustomerProfiles();
127
- }
128
-
129
- return deleted;
130
- };
131
-
132
- const deleteAllCustomerProfilesByWorkspace = async (workspaceId) => {
133
- await CustomerProfile.deleteMany({ workspaceId }).exec();
134
- await updateCachedAllCustomerProfiles();
135
- };
136
-
137
- module.exports = {
138
- createCustomerProfile,
139
- findCustomerProfilesByWorkspaceId,
140
- findCustomerProfilesByWorkspace,
141
- findCustomerProfileByFilter,
142
- updateCustomerProfile,
143
- updateCustomerProfileByFilter,
144
- deleteCustomerProfile,
145
- deleteAllCustomerProfilesByWorkspace,
146
- findAllCustomerProfilesByFilter,
147
- };
@@ -1,78 +0,0 @@
1
- const CustomerTimeline = require("../../models/CustomerTimeline");
2
-
3
- const createCustomerTimeline = async (data) => {
4
- const newTimeline = new CustomerTimeline(data);
5
- return await newTimeline.save();
6
- };
7
-
8
- const findCustomerTimelinesByWorkspaceId = async (workspaceId) => {
9
- return await CustomerTimeline.find({ workspaceId }).lean().exec();
10
- };
11
-
12
- const findCustomerTimelinesByWorkspace = async (workspaceId, filter = {}) => {
13
- return await CustomerTimeline.find({ workspaceId, ...filter })
14
- .lean()
15
- .exec();
16
- };
17
-
18
- const findCustomerTimelineByFilter = async (filter = {}, bodyFilter = {}) => {
19
- const all = await CustomerTimeline.find(filter).lean().exec();
20
-
21
- return (
22
- all.find((item) =>
23
- Object.entries(bodyFilter).every(
24
- ([key, value]) => item.body?.[key] === value
25
- )
26
- ) || null
27
- );
28
- };
29
-
30
- const findAllCustomerTimelinesByFilter = async (
31
- filter = {},
32
- bodyFilter = {}
33
- ) => {
34
- const all = await CustomerTimeline.find(filter).lean().exec();
35
- return all.filter((item) =>
36
- Object.entries(bodyFilter).every(
37
- ([key, value]) => item.body?.[key] === value
38
- )
39
- );
40
- };
41
-
42
- const updateCustomerTimeline = async (id, data) => {
43
- return await CustomerTimeline.findByIdAndUpdate(id, data, {
44
- new: true,
45
- }).exec();
46
- };
47
- const updateManyCustomerTimelinesByFilter = async (filter = {}, data = {}) => {
48
- await CustomerTimeline.updateMany(filter, data).exec();
49
- const updatedDocs = await CustomerTimeline.find(filter).lean().exec();
50
- return updatedDocs;
51
- };
52
-
53
- const updateCustomerTimelineByFilter = async (filter, data) => {
54
- return await CustomerTimeline.findOneAndUpdate(filter, data, {
55
- new: true,
56
- }).exec();
57
- };
58
-
59
- const deleteCustomerTimeline = async (id) => {
60
- return await CustomerTimeline.findByIdAndDelete(id).exec();
61
- };
62
-
63
- const deleteAllCustomerTimelinesByWorkspace = async (workspaceId) => {
64
- return await CustomerTimeline.deleteMany({ workspaceId }).exec();
65
- };
66
-
67
- module.exports = {
68
- createCustomerTimeline,
69
- findCustomerTimelinesByWorkspaceId,
70
- findCustomerTimelinesByWorkspace,
71
- findCustomerTimelineByFilter,
72
- updateCustomerTimeline,
73
- updateCustomerTimelineByFilter,
74
- deleteCustomerTimeline,
75
- deleteAllCustomerTimelinesByWorkspace,
76
- findAllCustomerTimelinesByFilter,
77
- updateManyCustomerTimelinesByFilter,
78
- };