shuttlepro-shared 1.1.81 → 1.1.82

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.
@@ -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
  };
package/models/Role.js ADDED
@@ -0,0 +1,29 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const RoleSchema = new Schema(
5
+ {
6
+ name: {
7
+ type: String,
8
+ default: "",
9
+ },
10
+ workspaceId: {
11
+ type: Schema.Types.ObjectId,
12
+ ref: "Workspace",
13
+ default: null,
14
+ },
15
+ description: {
16
+ type: String,
17
+ default: "",
18
+ },
19
+ status: {
20
+ type: String,
21
+ default: "active",
22
+ enum: ["active", "inactive"],
23
+ },
24
+ logs: [],
25
+ },
26
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
27
+ );
28
+
29
+ module.exports = mongoose.model("Role", RoleSchema);
@@ -16,6 +16,11 @@ const UserPermissionsSchema = new Schema(
16
16
  type: String,
17
17
  default: "",
18
18
  },
19
+ roleId: {
20
+ type: Schema.Types.ObjectId,
21
+ ref: "Role",
22
+ default: null,
23
+ },
19
24
  },
20
25
  { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
21
26
  );
@@ -1,6 +1,7 @@
1
1
  const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
2
3
 
3
- const daySchema = new mongoose.Schema({
4
+ const daySchema = new Schema({
4
5
  day: { type: String, required: true },
5
6
  startTime: { type: String, required: false },
6
7
  endTime: { type: String, required: false },
@@ -9,7 +10,7 @@ const daySchema = new mongoose.Schema({
9
10
  lateThreshold: { type: String, required: false },
10
11
  });
11
12
 
12
- const userRoleSchema = new mongoose.Schema(
13
+ const userRoleSchema = new Schema(
13
14
  {
14
15
  userId: {
15
16
  type: mongoose.Schema.Types.ObjectId,
@@ -23,7 +24,12 @@ const userRoleSchema = new mongoose.Schema(
23
24
  },
24
25
  role: {
25
26
  type: String,
26
- enum: ["admin", "agent", "storeManager", "socialMediaManager"],
27
+ default: "",
28
+ },
29
+ roleId: {
30
+ type: Schema.Types.ObjectId,
31
+ ref: "Role",
32
+ default: null,
27
33
  },
28
34
  isOwner: { type: Boolean, default: false },
29
35
  userShift: {
@@ -45,6 +51,7 @@ const userRoleSchema = new mongoose.Schema(
45
51
  );
46
52
 
47
53
  const UserRole = mongoose.model("UserRole", userRoleSchema);
54
+
48
55
  module.exports = {
49
56
  UserRole,
50
57
  };
package/models.js CHANGED
@@ -1,5 +1,4 @@
1
1
  const Website = require("./models/Website");
2
- const DescriptionTemplate = require("./models/DescriptionTemplate");
3
2
  const ProductQueue = require("./models/ProductQueue");
4
3
  const ColumnPreference = require("./models/ColumnPreference");
5
4
  const UserPermission = require("./models/UserPermission");
@@ -13,28 +12,7 @@ const AutoSchedulerSchema = require("./models/AutoScheduler");
13
12
  const ActivityLogs = require("./models/ActivityLogs");
14
13
  const UserRole = require("./models/UserRole");
15
14
  const OrderQueue = require("./models/OrderQueue");
16
- const AgentActivity = require("./models/AgentActivity");
17
- const Assignment = require("./models/Assignment");
18
- const BusinessDistribution = require("./models/BusinessDistribution");
19
- const CardComments = require("./models/CardComments");
20
- const Checkpoint = require("./models/Checkpoint");
21
- const City = require("./models/City");
22
- const Column = require("./models/Column");
23
- const Conversation = require("./models/Conversation");
24
- const Customer = require("./models/Customer");
25
- const Integration = require("./models/Integration");
26
- const Label = require("./models/Label");
27
- const Message = require("./models/Message");
28
- const Order = require("./models/Order");
29
- const OrderProduct = require("./models/OrderProduct");
30
- const Report = require("./models/Report");
31
- const Shipper = require("./models/Shipper");
32
- const Status = require("./models/Status");
33
- const StatusType = require("./models/StatusType");
34
- const Type = require("./models/Type");
35
- const Workspace = require("./models/Workspace");
36
- const Card = require("./models/Card");
37
- const Profile = require("./models/Profile");
15
+ const Role = require("./models/Role");
38
16
 
39
17
  module.exports = {
40
18
  Website,
@@ -51,27 +29,5 @@ module.exports = {
51
29
  ActivityLogs,
52
30
  UserRole,
53
31
  OrderQueue,
54
- AgentActivity,
55
- Assignment,
56
- BusinessDistribution,
57
- CardComments,
58
- Checkpoint,
59
- Column,
60
- Conversation,
61
- City,
62
- Customer,
63
- Integration,
64
- Label,
65
- Message,
66
- Order,
67
- OrderProduct,
68
- Report,
69
- Shipper,
70
- Status,
71
- Type,
72
- Workspace,
73
- StatusType,
74
- Card,
75
- DescriptionTemplate,
76
- Profile,
32
+ Role,
77
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shuttlepro-shared",
3
- "version": "1.1.81",
3
+ "version": "1.1.82",
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
- "redis": "^4.6.14",
20
- "express": "^4.17.1",
21
14
  "jsonwebtoken": "^9.0.2",
22
- "mongoose": "^8.7.1",
23
- "cors": "^2.8.5",
24
- "helmet": "^8.0.0",
25
- "bull": "^4.10.4",
26
- "socket.io": "^4.8.1"
15
+ "mongoose": "^8.7.1"
27
16
  }
28
17
  }
@@ -1,4 +0,0 @@
1
- const workspaceRepository = require("./workspace.repository");
2
- const integrationRepository = require("./integration.repository");
3
-
4
- exports.module = { workspaceRepository, integrationRepository };
@@ -1,168 +0,0 @@
1
- const { getRedisData, setRedisData } = require("../../config/redis");
2
- const Integration = require("../../models/Integration");
3
-
4
- const CACHE_KEY_ALL = "integrations_all";
5
-
6
- /**
7
- * Get cached integrations for all workspaces.
8
- */
9
- const getCachedAllIntegrations = async () => {
10
- let integrations = await getRedisData(CACHE_KEY_ALL);
11
- if (!integrations) {
12
- integrations = await Integration.find({}).exec();
13
- await setRedisData(CACHE_KEY_ALL, integrations);
14
- }
15
- return integrations;
16
- };
17
-
18
- /**
19
- * Update cached integrations for all workspaces.
20
- */
21
- const updateCachedAllIntegrations = async () => {
22
- const integrations = await Integration.find({}).exec();
23
- await setRedisData(CACHE_KEY_ALL, integrations);
24
- };
25
-
26
- /**
27
- * Get cached integrations for a specific workspace.
28
- * Now uses the all integrations cache and filters by workspaceId.
29
- */
30
- const getCachedIntegrations = async (workspaceId) => {
31
- const allIntegrations = await getCachedAllIntegrations();
32
- return allIntegrations.filter((intg) => intg.workspaceId === workspaceId);
33
- };
34
-
35
- /**
36
- * Create a new integration and update cache.
37
- */
38
- const createIntegration = async (data) => {
39
- const newIntegration = new Integration(data);
40
- const savedIntegration = await newIntegration.save();
41
-
42
- // Update only the main cache
43
- await updateCachedAllIntegrations();
44
-
45
- return savedIntegration;
46
- };
47
-
48
- /**
49
- * Find an integration by ID.
50
- */
51
- const findIntegrationsByWorkspaceId = async (workspaceId) => {
52
- return await getCachedIntegrations(workspaceId);
53
- };
54
-
55
- /**
56
- * Find integrations by workspace.
57
- */
58
- const findIntegrationsByWorkspace = async (workspaceId, filter = {}) => {
59
- const allIntegrations = await getCachedIntegrations(workspaceId);
60
-
61
- return allIntegrations.filter(
62
- (intg) =>
63
- intg.workspaceId === workspaceId &&
64
- Object.entries(filter).every(([key, value]) => intg[key] === value)
65
- );
66
- };
67
-
68
- /**
69
- * Find integration by filter (supports both workspace & non-workspace).
70
- */
71
- const findIntegrationByFilter = async (filter, workspaceId = null) => {
72
- const allIntegrations = await getCachedAllIntegrations();
73
-
74
- let filteredIntegrations = allIntegrations;
75
- if (workspaceId) {
76
- filteredIntegrations = allIntegrations.filter(
77
- (intg) => intg.workspaceId === workspaceId
78
- );
79
- }
80
-
81
- return (
82
- filteredIntegrations.find((item) =>
83
- Object.entries(filter).every(([key, value]) => item.body?.[key] === value)
84
- ) || null
85
- );
86
- };
87
-
88
- /**
89
- * Find all integrations (without workspace filtering).
90
- */
91
- const findAllIntegrations = async () => {
92
- return await getCachedAllIntegrations();
93
- };
94
-
95
- /**
96
- * Update an integration by ID.
97
- */
98
- const updateIntegration = async (id, data) => {
99
- const updatedIntegration = await Integration.findByIdAndUpdate(id, data, {
100
- new: true,
101
- }).exec();
102
-
103
- if (updatedIntegration) {
104
- // Update only the main cache
105
- await updateCachedAllIntegrations();
106
- }
107
-
108
- return updatedIntegration;
109
- };
110
-
111
- /**
112
- * Update an integration by filter.
113
- */
114
- const updateIntegrationByFilter = async (filter, data, workspaceId = null) => {
115
- // Add workspace filter if provided
116
- const queryFilter = workspaceId ? { ...filter, workspaceId } : filter;
117
-
118
- const updatedIntegration = await Integration.findOneAndUpdate(
119
- queryFilter,
120
- data,
121
- {
122
- new: true,
123
- }
124
- ).exec();
125
-
126
- if (updatedIntegration) {
127
- // Update only the main cache
128
- await updateCachedAllIntegrations();
129
- }
130
-
131
- return updatedIntegration;
132
- };
133
-
134
- /**
135
- * Delete an integration by ID.
136
- */
137
- const deleteIntegration = async (id) => {
138
- const deletedIntegration = await Integration.findByIdAndDelete(id).exec();
139
-
140
- if (deletedIntegration) {
141
- // Update only the main cache
142
- await updateCachedAllIntegrations();
143
- }
144
-
145
- return deletedIntegration;
146
- };
147
-
148
- /**
149
- * Delete all integrations for a specific workspace.
150
- */
151
- const deleteAllIntegrationsByWorkspace = async (workspaceId) => {
152
- await Integration.deleteMany({ workspaceId }).exec();
153
-
154
- // Update only the main cache
155
- await updateCachedAllIntegrations();
156
- };
157
-
158
- module.exports = {
159
- createIntegration,
160
- findIntegrationsByWorkspaceId,
161
- findIntegrationsByWorkspace,
162
- findIntegrationByFilter,
163
- findAllIntegrations,
164
- updateIntegration,
165
- updateIntegrationByFilter,
166
- deleteIntegration,
167
- deleteAllIntegrationsByWorkspace,
168
- };
@@ -1,95 +0,0 @@
1
- const { getRedisData, setRedisData } = require("../../config/redis");
2
- const Workspace = require("../../models/Workspace");
3
-
4
- const CACHE_KEY_ALL = "workspaces_all";
5
-
6
- const getCachedWorkspaces = async () => {
7
- let workspaces = await getRedisData(CACHE_KEY_ALL);
8
- if (!workspaces) {
9
- workspaces = await Workspace.find().exec();
10
- await setRedisData(CACHE_KEY_ALL, JSON.stringify(workspaces));
11
- } else {
12
- workspaces = JSON.parse(workspaces);
13
- }
14
- return workspaces;
15
- };
16
-
17
- const updateCachedWorkspaces = async () => {
18
- const workspaces = await Workspace.find().exec();
19
- await setRedisData(CACHE_KEY_ALL, JSON.stringify(workspaces));
20
- };
21
-
22
- const createWorkspace = async (data) => {
23
- const newWorkspace = new Workspace(data);
24
- const savedWorkspace = await newWorkspace.save();
25
- await updateCachedWorkspaces();
26
- return savedWorkspace;
27
- };
28
-
29
- const findWorkspaceById = async (id, select = []) => {
30
- const workspaces = await getCachedWorkspaces();
31
- const workspace = workspaces.find((ws) => ws._id.toString() === id) || null;
32
-
33
- if (workspace && select.length > 0) {
34
- return select.reduce((result, field) => {
35
- if (workspace[field] !== undefined) {
36
- result[field] = workspace[field];
37
- }
38
- return result;
39
- }, {});
40
- }
41
-
42
- return workspace;
43
- };
44
-
45
- const findWorkspace = async (filter) => {
46
- const workspaces = await getCachedWorkspaces();
47
- return (
48
- workspaces.find((ws) =>
49
- Object.entries(filter).every(([key, value]) => ws[key] === value)
50
- ) || null
51
- );
52
- };
53
-
54
- const findWorkspaceByIdAndQueueTracking = async (id) => {
55
- const workspaces = await getCachedWorkspaces();
56
- return (
57
- workspaces.find((ws) => ws._id.toString() === id && ws.queueTracking) ||
58
- null
59
- );
60
- };
61
-
62
- const findAllWorkspaces = async (filter = {}) => {
63
- const workspaces = await getCachedWorkspaces();
64
- return workspaces.filter((ws) =>
65
- Object.entries(filter).every(([key, value]) => ws[key] === value)
66
- );
67
- };
68
-
69
- const updateWorkspace = async (id, data) => {
70
- const updatedWorkspace = await Workspace.findByIdAndUpdate(id, data, {
71
- new: true,
72
- }).exec();
73
- if (updatedWorkspace) {
74
- await updateCachedWorkspaces();
75
- }
76
- return updatedWorkspace;
77
- };
78
-
79
- const deleteWorkspace = async (id) => {
80
- const deletedWorkspace = await Workspace.findByIdAndDelete(id).exec();
81
- if (deletedWorkspace) {
82
- await updateCachedWorkspaces();
83
- }
84
- return deletedWorkspace;
85
- };
86
-
87
- module.exports = {
88
- createWorkspace,
89
- findWorkspaceById,
90
- findWorkspace,
91
- findWorkspaceByIdAndQueueTracking,
92
- findAllWorkspaces,
93
- updateWorkspace,
94
- deleteWorkspace,
95
- };
package/config/bull.js DELETED
@@ -1,78 +0,0 @@
1
- const Queue = require("bull");
2
- const config = require("./config");
3
-
4
- /**
5
- * Create a new queue.
6
- * @param {string} queueName - The name of the queue.
7
- * @param {Object} [redisConfig=config.redis] - Redis configuration.
8
- * @returns {Object} - A collection of queue-related functions.
9
- */
10
- const createQueue = (queueName, redisConfig = config.redis) => {
11
- const queue = new Queue(queueName, { redis: redisConfig });
12
-
13
- // Attach event listeners for logging
14
- queue.on("completed", (job) => console.log(`Job ${job.id} completed.`));
15
- queue.on("failed", (job, err) => console.error(`Job ${job.id} failed:`, err));
16
-
17
- /**
18
- * Add a job to the queue.
19
- * @param {Object} data - Data to be processed by the job.
20
- * @param {Object} [options] - Bull job options (e.g., delay, attempts).
21
- * @returns {Promise<Job>} - The created job.
22
- */
23
- const addJob = async (
24
- data,
25
- options = {
26
- attempts: 3,
27
- removeOnComplete: true,
28
- }
29
- ) => {
30
- return await queue.add(data, options);
31
- };
32
-
33
- /**
34
- * Process jobs in the queue.
35
- * @param {Function} processor - The function to process each job.
36
- */
37
- const processJobs = (processor) => {
38
- queue.process(processor);
39
- };
40
-
41
- /**
42
- * Close the queue connection.
43
- * @returns {Promise<void>}
44
- */
45
- const closeConnection = async () => {
46
- await queue.close();
47
- console.log(`Queue "${queue.name}" connection closed.`);
48
- };
49
-
50
- /**
51
- * Pause the queue.
52
- * @returns {Promise<void>}
53
- */
54
- const pauseQueue = async () => {
55
- await queue.pause();
56
- console.log(`Queue "${queue.name}" paused.`);
57
- };
58
-
59
- /**
60
- * Resume the queue.
61
- * @returns {Promise<void>}
62
- */
63
- const resumeQueue = async () => {
64
- await queue.resume();
65
- console.log(`Queue "${queue.name}" resumed.`);
66
- };
67
-
68
- // Return the functional interface
69
- return {
70
- addJob,
71
- processJobs,
72
- closeConnection,
73
- pauseQueue,
74
- resumeQueue,
75
- };
76
- };
77
-
78
- module.exports = { createQueue };
package/config/config.js DELETED
@@ -1,14 +0,0 @@
1
- const ALLOWED_URLS = process.env.ALLOWED_ORIGIN.split(",");
2
- const WEBHOOK_API_KEY = process.env.API_KEY || process.env.WEBHOOK_API_KEY;
3
- const mode = process.env.MODE || "production";
4
-
5
- const redis = {
6
- url: process.env.REDIS_URI,
7
- };
8
-
9
- module.exports = {
10
- WEBHOOK_API_KEY,
11
- ALLOWED_URLS,
12
- mode,
13
- redis,
14
- };
@@ -1,7 +0,0 @@
1
- /* eslint-disable no-undef */
2
- module.exports = {
3
- url:
4
- process.env.NODE_ENV === "test"
5
- ? process.env.TEST_DB_URL
6
- : process.env.DB_URL,
7
- };
package/config/index.js DELETED
@@ -1,13 +0,0 @@
1
- const bullConfig = require("./bull");
2
- const redisConfig = require("./redis");
3
- const config = require("./config");
4
- const databaseConfig = require("./database");
5
- const socketConfig = require("./socket");
6
-
7
- module.exports = {
8
- bullConfig,
9
- redisConfig,
10
- config,
11
- databaseConfig,
12
- socketConfig,
13
- };