shuttlepro-shared 1.3.14 → 1.3.15

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 (65) hide show
  1. package/common/repositories/chatMember.repository.js +9 -0
  2. package/common/repositories/customerProfile.repository.js +147 -0
  3. package/common/repositories/customerTimeline.repository.js +78 -0
  4. package/common/repositories/descriptionTemplates.repository.js +229 -0
  5. package/common/repositories/index.js +34 -0
  6. package/common/repositories/integration.repository.js +210 -0
  7. package/common/repositories/label.repository.js +95 -0
  8. package/common/repositories/notificationSettings.repository.js +95 -0
  9. package/common/repositories/role.repository.js +333 -0
  10. package/common/repositories/settings.repository.js +32 -0
  11. package/common/repositories/shipper.repository.js +77 -0
  12. package/common/repositories/socialMediaSetting.repository.js +33 -0
  13. package/common/repositories/user.repository.js +150 -0
  14. package/common/repositories/userPermission.repository.js +228 -0
  15. package/common/repositories/userRepository.js +31 -0
  16. package/common/repositories/userRole.repository.js +235 -0
  17. package/common/repositories/userRolePermission.repository.js +59 -0
  18. package/common/repositories/workspace.repository.js +147 -0
  19. package/config/bull.js +78 -0
  20. package/config/config.js +14 -0
  21. package/config/database.js +4 -0
  22. package/config/index.js +13 -0
  23. package/config/redis.js +196 -0
  24. package/config/socket.js +172 -0
  25. package/constants/index.js +15 -0
  26. package/index.js +8 -0
  27. package/models/AgentActivity.js +192 -0
  28. package/models/Assignment.js +23 -0
  29. package/models/BusinessDistribution.js +23 -0
  30. package/models/Card.js +144 -0
  31. package/models/CardComments.js +33 -0
  32. package/models/ChatMember.js +17 -0
  33. package/models/Chatbot.js +20 -0
  34. package/models/Checkpoint.js +50 -0
  35. package/models/City.js +17 -0
  36. package/models/Column.js +28 -0
  37. package/models/Conversation.js +87 -0
  38. package/models/Customer.js +36 -0
  39. package/models/CustomerProfile.js +30 -0
  40. package/models/CustomerTimeline.js +28 -0
  41. package/models/DefaultRolePermission.js +34 -0
  42. package/models/DescriptionTemplate.js +22 -0
  43. package/models/Integration.js +51 -0
  44. package/models/Label.js +42 -0
  45. package/models/Message.js +47 -0
  46. package/models/NewProduct.js +71 -0
  47. package/models/NotificationSettings.js +130 -0
  48. package/models/Order.js +254 -0
  49. package/models/OrderProduct.js +37 -0
  50. package/models/Profile.js +127 -0
  51. package/models/Report.js +27 -0
  52. package/models/Setting.js +18 -0
  53. package/models/Shipper.js +62 -0
  54. package/models/SocialMediaSetting.js +28 -0
  55. package/models/Status.js +58 -0
  56. package/models/StatusType.js +10 -0
  57. package/models/Step.js +50 -0
  58. package/models/Type.js +25 -0
  59. package/models/UserRole.js +1 -119
  60. package/models/UserWorkflow.js +46 -0
  61. package/models/Workspace.js +308 -0
  62. package/models.js +62 -1
  63. package/package.json +13 -2
  64. package/utils/decorator-factory.js +264 -0
  65. package/utils/logger.js +41 -0
package/models/Type.js ADDED
@@ -0,0 +1,25 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ const typeSchema = new mongoose.Schema(
4
+ {
5
+ title: {
6
+ type: String,
7
+ required: true,
8
+ },
9
+ deleted: {
10
+ type: Boolean,
11
+ default: false,
12
+ },
13
+ workspaceId: { type: String, default: "" },
14
+ color: { type: String, default: "#4a90e2", required: true },
15
+ },
16
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
17
+ );
18
+
19
+ typeSchema.virtual("cardList", {
20
+ ref: "Card",
21
+ localField: "_id",
22
+ foreignField: "typeId",
23
+ });
24
+
25
+ module.exports = mongoose.model("Type", typeSchema);
@@ -1,15 +1,6 @@
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
-
13
4
  const userRoleSchema = new Schema(
14
5
  {
15
6
  userId: {
@@ -32,10 +23,7 @@ const userRoleSchema = new Schema(
32
23
  default: null,
33
24
  },
34
25
  isOwner: { type: Boolean, default: false },
35
- userShift: {
36
- shiftName: { type: String, required: false },
37
- days: { type: [daySchema], required: false },
38
- },
26
+ userShift: { type: Object, default: null },
39
27
  createdBy: {
40
28
  type: mongoose.Schema.Types.ObjectId,
41
29
  ref: "User",
@@ -52,112 +40,6 @@ const userRoleSchema = new Schema(
52
40
 
53
41
  const UserRole = mongoose.model("UserRole", userRoleSchema);
54
42
 
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
-
158
43
  module.exports = {
159
44
  UserRole,
160
- getChannelsPermissions,
161
- getUserPermissions,
162
- getUserRoleWithPermissions,
163
45
  };
@@ -0,0 +1,46 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const userWorkflow = new Schema(
5
+ {
6
+ workspaceId: {
7
+ type: Schema.Types.ObjectId,
8
+ default: null,
9
+ ref: "Workspace",
10
+ },
11
+ workflow: {},
12
+ receiverId: {
13
+ type: String,
14
+ default: "",
15
+ },
16
+ whatsappTemplateData: {},
17
+ whatsappTemplate: {},
18
+ targetPayload: {},
19
+ business: {},
20
+ sender: {},
21
+ currentRetry: {
22
+ type: Number,
23
+ default: 0,
24
+ },
25
+ currentAction: {
26
+ type: String,
27
+ default: "",
28
+ },
29
+ lastMessage: {
30
+ type: String,
31
+ default: "",
32
+ },
33
+ status: {
34
+ type: String,
35
+ default: "pending",
36
+ },
37
+ otherTypeEvent: {
38
+ type: Boolean,
39
+ default: false,
40
+ },
41
+ allActions: [],
42
+ },
43
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
44
+ );
45
+
46
+ module.exports = mongoose.model("UserWorkflow", userWorkflow);
@@ -0,0 +1,308 @@
1
+ const mongoose = require("mongoose");
2
+ //TODO: task manager and default location creation
3
+ const shiftSchema = new mongoose.Schema(
4
+ {
5
+ shiftName: {
6
+ type: String,
7
+ required: true,
8
+ },
9
+ days: [
10
+ {
11
+ day: { type: String, required: true },
12
+ startTime: { type: String, required: true },
13
+ endTime: { type: String, required: true },
14
+ breakStartTime: { type: String, required: false },
15
+ breakEndTime: { type: String, required: false },
16
+ lateThreshold: { type: String, required: false },
17
+ },
18
+ ],
19
+ },
20
+ { _id: true }
21
+ );
22
+ const scoreThresholdSchema = new mongoose.Schema({
23
+ operator: {
24
+ type: mongoose.Schema.Types.Mixed,
25
+ required: false,
26
+ },
27
+ value: {
28
+ type: mongoose.Schema.Types.Mixed,
29
+ required: true,
30
+ },
31
+ score: {
32
+ type: Number,
33
+ required: false,
34
+ },
35
+ additionalFields: {
36
+ type: mongoose.Schema.Types.Mixed,
37
+ default: {},
38
+ },
39
+ });
40
+ const kpiSchema = new mongoose.Schema({
41
+ weight: {
42
+ type: Number,
43
+ required: true,
44
+ },
45
+ scoreThresholds: {
46
+ type: [scoreThresholdSchema],
47
+ default: [],
48
+ },
49
+ relativeGrading: {
50
+ type: Boolean,
51
+ default: false,
52
+ },
53
+ });
54
+ const ReasonSchema = new mongoose.Schema({
55
+ _id: {
56
+ type: mongoose.Schema.Types.ObjectId,
57
+ default: null,
58
+ },
59
+ reason: { type: String, required: true },
60
+ color: { type: String, default: "#000000" },
61
+ categoryTitle: { type: String, required: true },
62
+ });
63
+ const ResolutionReasonCategorySchema = new mongoose.Schema({
64
+ _id: {
65
+ type: mongoose.Schema.Types.ObjectId,
66
+ default: null,
67
+ },
68
+ title: { type: String, required: true },
69
+ reasons: { type: [ReasonSchema], default: [] },
70
+ });
71
+ const feedbackFormSchema = new mongoose.Schema({
72
+ formName: { type: String, required: true, trim: true },
73
+ brandName: { type: String, default: "" },
74
+ brandLogoUrl: { type: String, default: "", trim: true },
75
+ type: {
76
+ type: String,
77
+ default: "conversation",
78
+ enum: [
79
+ "conversation",
80
+ "shop",
81
+ // "order"
82
+ ],
83
+ },
84
+ qr: [
85
+ {
86
+ type: mongoose.Schema.Types.Mixed,
87
+ default: {
88
+ data: "",
89
+ code: "",
90
+ link: "",
91
+ shopId: "",
92
+ },
93
+ },
94
+ ],
95
+ integrationId: [
96
+ {
97
+ type: mongoose.Schema.Types.ObjectId,
98
+ ref: "Integration",
99
+ default: null,
100
+ },
101
+ ],
102
+ enabled: {
103
+ type: Boolean,
104
+ default: true,
105
+ },
106
+ fields: [
107
+ {
108
+ fieldName: {
109
+ type: String,
110
+ required: true,
111
+ trim: true,
112
+ },
113
+ required: {
114
+ type: Boolean,
115
+ default: false,
116
+ },
117
+ enabled: {
118
+ type: Boolean,
119
+ default: true,
120
+ },
121
+ createdBy: {
122
+ type: mongoose.Schema.Types.ObjectId,
123
+ ref: "User",
124
+ default: null,
125
+ },
126
+ updatedBy: {
127
+ type: mongoose.Schema.Types.ObjectId,
128
+ ref: "User",
129
+ default: null,
130
+ },
131
+ fieldType: {
132
+ type: String,
133
+ enum: [
134
+ "text",
135
+ "autocomplete",
136
+ "radio",
137
+ "text area",
138
+ "number",
139
+ "date",
140
+ "time",
141
+ "email",
142
+ "range",
143
+ "url",
144
+ "colour",
145
+ "file",
146
+ "starRating",
147
+ "heading",
148
+ "paragraph",
149
+ ],
150
+ },
151
+ option: {
152
+ type: mongoose.Schema.Types.Mixed,
153
+ },
154
+ },
155
+ ],
156
+ });
157
+ const workspaceSchema = new mongoose.Schema(
158
+ {
159
+ name: {
160
+ type: String,
161
+ required: true,
162
+ trim: true,
163
+ },
164
+ iconUrl: { type: String, default: "" },
165
+ thumbUrl: { type: String, default: "" },
166
+ createdBy: {
167
+ type: mongoose.Schema.Types.ObjectId,
168
+ ref: "User",
169
+ default: null,
170
+ },
171
+ updatedBy: {
172
+ type: mongoose.Schema.Types.ObjectId,
173
+ ref: "User",
174
+ default: null,
175
+ },
176
+ productsCount: { type: Number, default: 0 },
177
+ ordersCount: { type: Number, default: 0 },
178
+ shippers: [{ type: String, trim: true }],
179
+ socialProfiles: [],
180
+ shiftConfigurations: [shiftSchema],
181
+ kpiConfiguration: {
182
+ type: Map,
183
+ of: kpiSchema,
184
+ default: {},
185
+ },
186
+ members: [],
187
+ contact: String,
188
+ email: String,
189
+ address: String,
190
+ websiteUrl: String,
191
+ facebookUrl: String,
192
+ twitterUrl: String,
193
+ instagramUrl: String,
194
+ isDeleted: { type: Boolean, default: false },
195
+ businessHours: {
196
+ startTime: { type: String, default: "" },
197
+ endTime: { type: String, default: "" },
198
+ },
199
+ remarks: [
200
+ {
201
+ reason: { type: String, default: "" },
202
+ type: { type: String, default: "" },
203
+ color: { type: String, default: "" },
204
+ },
205
+ ],
206
+ chatGptApiKey: String,
207
+ skuSeparator: { type: String, default: "-" },
208
+ uniqueNo: { type: Number, default: 0 },
209
+ webhookStatus: { type: String, default: "" },
210
+ businessCategory: { type: String, default: "" },
211
+ numberOfProducts: { type: Number, default: 0 },
212
+ monthlyOrders: { type: Number, default: 0 },
213
+ queueTracking: { type: Boolean, default: false },
214
+ orderConfiguration: { type: String, default: "" },
215
+ defaultModule: { type: String, default: "dashboard" },
216
+ resolutionReasonCategories: {
217
+ type: [ResolutionReasonCategorySchema],
218
+ default: [],
219
+ },
220
+ feedbackDynamicFields: [feedbackFormSchema],
221
+ dynamicFieldsTemplate: [
222
+ {
223
+ groupName: { type: String, required: true, trim: true },
224
+ fields: [
225
+ {
226
+ fieldName: {
227
+ type: String,
228
+ required: true,
229
+ trim: true,
230
+ },
231
+ required: {
232
+ type: Boolean,
233
+ default: false,
234
+ },
235
+ enabled: {
236
+ type: Boolean,
237
+ default: true,
238
+ },
239
+ createdBy: {
240
+ type: mongoose.Schema.Types.ObjectId,
241
+ ref: "User",
242
+ default: null,
243
+ },
244
+ updatedBy: {
245
+ type: mongoose.Schema.Types.ObjectId,
246
+ ref: "User",
247
+ default: null,
248
+ },
249
+ fieldType: {
250
+ type: String,
251
+ enum: [
252
+ "text",
253
+ "autocomplete",
254
+ "radio",
255
+ "text area",
256
+ "number",
257
+ "date",
258
+ "time",
259
+ "email",
260
+ "range",
261
+ "url",
262
+ "colour",
263
+ "file",
264
+ ],
265
+ },
266
+ option: {
267
+ type: mongoose.Schema.Types.Mixed,
268
+ },
269
+ isPublic: {
270
+ type: Boolean,
271
+ default: false,
272
+ },
273
+ },
274
+ ],
275
+ },
276
+ ],
277
+ crmVisibility: {
278
+ type: String,
279
+ enum: ["everyone", "assignee"],
280
+ default: "everyone",
281
+ },
282
+ defaultShift: { type: String, default: "" },
283
+ },
284
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
285
+ );
286
+ const commonOptions = {
287
+ type: String,
288
+ trim: true,
289
+ default: "",
290
+ };
291
+ workspaceSchema.add({
292
+ contact: commonOptions,
293
+ email: commonOptions,
294
+ address: commonOptions,
295
+ websiteUrl: commonOptions,
296
+ facebookUrl: commonOptions,
297
+ twitterUrl: commonOptions,
298
+ instagramUrl: commonOptions,
299
+ chatGptApiKey: commonOptions,
300
+ });
301
+
302
+ workspaceSchema.virtual("integrations", {
303
+ ref: "Integration",
304
+ localField: "_id",
305
+ foreignField: "workspaceId",
306
+ });
307
+ const Workspace = mongoose.model("Workspace", workspaceSchema);
308
+ module.exports = Workspace;
package/models.js CHANGED
@@ -1,4 +1,6 @@
1
1
  const Website = require("./models/Website");
2
+ const ChatMember = require("./models/ChatMember");
3
+ const DescriptionTemplate = require("./models/DescriptionTemplate");
2
4
  const ProductQueue = require("./models/ProductQueue");
3
5
  const ColumnPreference = require("./models/ColumnPreference");
4
6
  const UserPermission = require("./models/UserPermission");
@@ -12,8 +14,36 @@ const AutoSchedulerSchema = require("./models/AutoScheduler");
12
14
  const ActivityLogs = require("./models/ActivityLogs");
13
15
  const UserRole = require("./models/UserRole");
14
16
  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");
15
41
  const Role = require("./models/Role");
16
-
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");
17
47
  module.exports = {
18
48
  Website,
19
49
  ProductQueue,
@@ -29,5 +59,36 @@ module.exports = {
29
59
  ActivityLogs,
30
60
  UserRole,
31
61
  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,
32
88
  Role,
89
+ NewProduct,
90
+ NotificationSettings,
91
+ UserWorkflow,
92
+ Setting,
93
+ CustomerProfile,
33
94
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shuttlepro-shared",
3
- "version": "1.3.14",
3
+ "version": "1.3.15",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,7 +11,18 @@
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",
14
23
  "jsonwebtoken": "^9.0.2",
15
- "mongoose": "^8.7.1"
24
+ "mongoose": "^8.7.1",
25
+ "redis": "^4.6.14",
26
+ "socket.io": "^4.8.1"
16
27
  }
17
28
  }