shuttlepro-shared 1.3.17 → 1.3.18
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.
- package/common/repositories/index.js +0 -2
- package/config/redis.js +72 -73
- package/models/Customer.js +1 -0
- package/models/CustomerProfile.js +0 -3
- package/models/Order.js +8 -18
- package/models/Workspace.js +10 -0
- package/package.json +1 -1
- package/common/repositories/customerTimeline.repository.js +0 -78
- package/models/CustomerTimeline.js +0 -28
|
@@ -13,7 +13,6 @@ const userPermissionRepository = require("./userPermission.repository");
|
|
|
13
13
|
const userRolePermissionRepository = require("./userRolePermission.repository");
|
|
14
14
|
const notificationSettingsRepository = require("./notificationSettings.repository");
|
|
15
15
|
const customerProfileRepository = require("./customerProfile.repository");
|
|
16
|
-
const customerTimelineRepository = require("./customerTimeline.repository");
|
|
17
16
|
exports.module = {
|
|
18
17
|
workspaceRepository,
|
|
19
18
|
integrationRepository,
|
|
@@ -30,5 +29,4 @@ exports.module = {
|
|
|
30
29
|
userPermissionRepository,
|
|
31
30
|
userRolePermissionRepository,
|
|
32
31
|
customerProfileRepository,
|
|
33
|
-
customerTimelineRepository,
|
|
34
32
|
};
|
package/config/redis.js
CHANGED
|
@@ -8,53 +8,51 @@ const client = createClient({
|
|
|
8
8
|
url: REDIS_URL,
|
|
9
9
|
socket: { reconnectStrategy: (retries) => Math.min(retries * 50, 1000) }, // Exponential backoff
|
|
10
10
|
});
|
|
11
|
-
|
|
12
|
-
// ✅ Create separate Pub/Sub clients
|
|
13
11
|
const publisher = client.duplicate();
|
|
14
12
|
const subscriber = client.duplicate();
|
|
15
13
|
|
|
16
|
-
// ✅
|
|
17
|
-
client
|
|
18
|
-
client.on("
|
|
19
|
-
client.on("
|
|
20
|
-
client.on("
|
|
14
|
+
// ✅ Redis Events
|
|
15
|
+
const handleEvents = (client, label = "Redis") => {
|
|
16
|
+
client.on("error", (err) => console.error(`❌ ${label} Error:`, err));
|
|
17
|
+
client.on("connect", () => console.log(`✅ ${label} Connected`));
|
|
18
|
+
client.on("ready", () => console.log(`🚀 ${label} Ready to use`));
|
|
19
|
+
client.on("end", () => console.log(`❗ ${label} Connection Closed`));
|
|
20
|
+
client.on("reconnecting", () => console.warn(`🔄 ${label} Reconnecting...`));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
handleEvents(client, "Main Redis");
|
|
24
|
+
handleEvents(publisher, "Publisher Redis");
|
|
25
|
+
handleEvents(subscriber, "Subscriber Redis");
|
|
21
26
|
|
|
22
|
-
// ✅ Ensure Redis is connected
|
|
27
|
+
// ✅ Ensure Redis is connected once during app startup
|
|
23
28
|
const connectRedis = async () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
try {
|
|
30
|
+
if (!client.isOpen) await client.connect();
|
|
31
|
+
if (!publisher.isOpen) await publisher.connect();
|
|
32
|
+
if (!subscriber.isOpen) await subscriber.connect();
|
|
33
|
+
|
|
34
|
+
// Set keyspace events only once
|
|
35
|
+
const config = await client.configGet("notify-keyspace-events");
|
|
36
|
+
if (!config["notify-keyspace-events"]?.includes("Ex")) {
|
|
37
|
+
await client.configSet("notify-keyspace-events", "Ex");
|
|
31
38
|
}
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.error("❌ Failed to connect to Redis:", err);
|
|
32
41
|
}
|
|
33
|
-
await client.configSet("notify-keyspace-events", "Ex");
|
|
34
42
|
};
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
* ✅ Publish Data to a Channel
|
|
38
|
-
* @param {string} channel - The Redis Pub/Sub channel
|
|
39
|
-
* @param {any} message - The message to send
|
|
40
|
-
*/
|
|
44
|
+
// ✅ Publish Data to a Channel
|
|
41
45
|
const publishToChannel = async (channel, message) => {
|
|
42
46
|
try {
|
|
43
|
-
await connectRedis();
|
|
44
47
|
await publisher.publish(channel, JSON.stringify(message));
|
|
45
48
|
} catch (err) {
|
|
46
49
|
console.error("❌ Error publishing message:", err);
|
|
47
50
|
}
|
|
48
51
|
};
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
* ✅ Subscribe & Listen for Messages
|
|
52
|
-
* @param {string} channel - The Redis Pub/Sub channel
|
|
53
|
-
* @param {function} callback - Callback function to handle messages
|
|
54
|
-
*/
|
|
53
|
+
// ✅ Subscribe & Listen for Messages
|
|
55
54
|
const subscribeToChannel = async (channel, callback, expiry = false) => {
|
|
56
55
|
try {
|
|
57
|
-
await connectRedis();
|
|
58
56
|
await subscriber.subscribe(channel, (message) => {
|
|
59
57
|
if (expiry) callback(message);
|
|
60
58
|
else callback(JSON.parse(message));
|
|
@@ -64,13 +62,7 @@ const subscribeToChannel = async (channel, callback, expiry = false) => {
|
|
|
64
62
|
}
|
|
65
63
|
};
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
* ✅ Set Data in Redis (Supports String & Hash)
|
|
69
|
-
* @param {string} key - The Redis key
|
|
70
|
-
* @param {any} value - The value to store
|
|
71
|
-
* @param {string|null} field - Optional field for Hash storage
|
|
72
|
-
* @param {number} expiryInSeconds - Expiry time in seconds (default: 3600)
|
|
73
|
-
*/
|
|
65
|
+
// ✅ Set Data in Redis (Supports String & Hash)
|
|
74
66
|
const setRedisData = async (
|
|
75
67
|
key,
|
|
76
68
|
value,
|
|
@@ -78,7 +70,6 @@ const setRedisData = async (
|
|
|
78
70
|
expiryInSeconds = 3600
|
|
79
71
|
) => {
|
|
80
72
|
try {
|
|
81
|
-
await connectRedis();
|
|
82
73
|
const stringifiedValue = JSON.stringify(value);
|
|
83
74
|
let result;
|
|
84
75
|
|
|
@@ -99,43 +90,27 @@ const setRedisData = async (
|
|
|
99
90
|
}
|
|
100
91
|
};
|
|
101
92
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
await connectRedis();
|
|
105
|
-
await client.sAdd(key, value);
|
|
106
|
-
return true;
|
|
107
|
-
} catch (err) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const removeDataFromRedisSet = async (key, value) => {
|
|
113
|
-
try {
|
|
114
|
-
await connectRedis();
|
|
115
|
-
await client.sRem(key, value);
|
|
116
|
-
return true;
|
|
117
|
-
} catch (err) {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
const isMemberOfRedisSet = async (key, value) => {
|
|
93
|
+
// ✅ Get Data from Redis (Supports String & Hash)
|
|
94
|
+
const getRedisData = async (key, field = null) => {
|
|
122
95
|
try {
|
|
123
|
-
|
|
124
|
-
|
|
96
|
+
const result = field
|
|
97
|
+
? await client.hGet(key, field)
|
|
98
|
+
: await client.get(key);
|
|
99
|
+
return result ? JSON.parse(result) : null;
|
|
125
100
|
} catch (err) {
|
|
126
|
-
console.
|
|
127
|
-
return
|
|
101
|
+
console.error("❌ Error getting Redis data:", err);
|
|
102
|
+
return null;
|
|
128
103
|
}
|
|
129
104
|
};
|
|
130
105
|
/**
|
|
131
|
-
* ✅ Get
|
|
106
|
+
* ✅ Get Expiry Time from Redis
|
|
132
107
|
* @param {string} key - The Redis key
|
|
133
108
|
* @param {string|null} field - Optional field for Hash retrieval
|
|
134
109
|
*/
|
|
135
|
-
const
|
|
110
|
+
const getRedisDataTime = async (key) => {
|
|
136
111
|
try {
|
|
137
112
|
await connectRedis();
|
|
138
|
-
let result =
|
|
113
|
+
let result = await client.ttl(key);
|
|
139
114
|
return result ? JSON.parse(result) : null;
|
|
140
115
|
} catch (err) {
|
|
141
116
|
console.error("❌ Error getting Redis data:", err);
|
|
@@ -143,14 +118,9 @@ const getRedisData = async (key, field = null) => {
|
|
|
143
118
|
}
|
|
144
119
|
};
|
|
145
120
|
|
|
146
|
-
|
|
147
|
-
* ✅ Delete Data from Redis (Supports String & Hash)
|
|
148
|
-
* @param {string} key - The Redis key
|
|
149
|
-
* @param {string|null} field - Optional field for Hash deletion
|
|
150
|
-
*/
|
|
121
|
+
// ✅ Delete Data from Redis (Supports String & Hash)
|
|
151
122
|
const deleteRedisData = async (key, field = null) => {
|
|
152
123
|
try {
|
|
153
|
-
await connectRedis();
|
|
154
124
|
return field ? await client.hDel(key, field) : await client.del(key);
|
|
155
125
|
} catch (err) {
|
|
156
126
|
console.error("❌ Error deleting Redis data:", err);
|
|
@@ -158,9 +128,37 @@ const deleteRedisData = async (key, field = null) => {
|
|
|
158
128
|
}
|
|
159
129
|
};
|
|
160
130
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
131
|
+
// ✅ Redis Set Operations
|
|
132
|
+
const addDataToRedisSet = async (key, value) => {
|
|
133
|
+
try {
|
|
134
|
+
await client.sAdd(key, value);
|
|
135
|
+
return true;
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.error("❌ Error adding to Redis set:", err);
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const removeDataFromRedisSet = async (key, value) => {
|
|
143
|
+
try {
|
|
144
|
+
await client.sRem(key, value);
|
|
145
|
+
return true;
|
|
146
|
+
} catch (err) {
|
|
147
|
+
console.error("❌ Error removing from Redis set:", err);
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const isMemberOfRedisSet = async (key, value) => {
|
|
153
|
+
try {
|
|
154
|
+
return await client.sIsMember(key, value);
|
|
155
|
+
} catch (err) {
|
|
156
|
+
console.error("❌ Error checking membership in Redis set:", err);
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// ✅ Graceful Shutdown
|
|
164
162
|
const closeClients = async () => {
|
|
165
163
|
if (client.isOpen) await client.quit();
|
|
166
164
|
if (publisher.isOpen) await publisher.quit();
|
|
@@ -184,12 +182,13 @@ module.exports = {
|
|
|
184
182
|
client,
|
|
185
183
|
publisher,
|
|
186
184
|
subscriber,
|
|
185
|
+
connectRedis,
|
|
187
186
|
setRedisData,
|
|
187
|
+
getRedisDataTime,
|
|
188
188
|
getRedisData,
|
|
189
189
|
deleteRedisData,
|
|
190
190
|
publishToChannel,
|
|
191
191
|
subscribeToChannel,
|
|
192
|
-
connectRedis,
|
|
193
192
|
addDataToRedisSet,
|
|
194
193
|
removeDataFromRedisSet,
|
|
195
194
|
isMemberOfRedisSet,
|
package/models/Customer.js
CHANGED
|
@@ -8,9 +8,6 @@ const CustomerProfileSchema = new Schema(
|
|
|
8
8
|
picture: { type: String, default: "" },
|
|
9
9
|
fbId: { type: String, default: "" },
|
|
10
10
|
igId: { type: String, default: "" },
|
|
11
|
-
totalOrders: { type: Number, default: 0 },
|
|
12
|
-
totalConversations: { type: Number, default: 0 },
|
|
13
|
-
totalTickets: { type: Number, default: 0 },
|
|
14
11
|
blackList: { type: Boolean, default: false },
|
|
15
12
|
workspaceId: {
|
|
16
13
|
type: Schema.Types.ObjectId,
|
package/models/Order.js
CHANGED
|
@@ -136,27 +136,17 @@ const OrderSchema = new Schema(
|
|
|
136
136
|
paymentDate: { type: String, default: "" },
|
|
137
137
|
paymentDetails: {},
|
|
138
138
|
},
|
|
139
|
+
merged: {
|
|
140
|
+
status: { type: String, default: "open" },
|
|
141
|
+
webOrderNumbers: [],
|
|
142
|
+
orderNumbers: [],
|
|
143
|
+
localOrderIds: [],
|
|
144
|
+
webOrderIds: [],
|
|
145
|
+
details: [],
|
|
146
|
+
},
|
|
139
147
|
credentials: {},
|
|
140
148
|
ticketId: { type: String, default: "" },
|
|
141
149
|
sender: { type: String, default: "" },
|
|
142
|
-
shipperAdvice: {
|
|
143
|
-
reAttempt: {
|
|
144
|
-
made: { type: Boolean, default: false },
|
|
145
|
-
details: {
|
|
146
|
-
attempt: { type: String, default: "0" },
|
|
147
|
-
remarks: { type: String, default: "" },
|
|
148
|
-
date: { type: String, default: "" },
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
return: {
|
|
152
|
-
made: { type: Boolean, default: false },
|
|
153
|
-
details: {
|
|
154
|
-
attempt: { type: String, default: "0" },
|
|
155
|
-
remarks: { type: String, default: "" },
|
|
156
|
-
date: { type: String, default: "" },
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
150
|
orderName: { type: String, default: "" },
|
|
161
151
|
totalWeight: { type: String, default: "" },
|
|
162
152
|
},
|
package/models/Workspace.js
CHANGED
|
@@ -280,6 +280,16 @@ const workspaceSchema = new mongoose.Schema(
|
|
|
280
280
|
default: "everyone",
|
|
281
281
|
},
|
|
282
282
|
defaultShift: { type: String, default: "" },
|
|
283
|
+
automationManager: {
|
|
284
|
+
delayThreshold: {
|
|
285
|
+
type: Number,
|
|
286
|
+
default: 5,
|
|
287
|
+
},
|
|
288
|
+
messageCount: {
|
|
289
|
+
type: Number,
|
|
290
|
+
default: 3,
|
|
291
|
+
},
|
|
292
|
+
},
|
|
283
293
|
},
|
|
284
294
|
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
285
295
|
);
|
package/package.json
CHANGED
|
@@ -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
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const mongoose = require("mongoose");
|
|
2
|
-
const { Schema } = mongoose;
|
|
3
|
-
const CustomerTimelineSchema = new Schema(
|
|
4
|
-
{
|
|
5
|
-
type: { type: String, default: "" },
|
|
6
|
-
referenceId: { type: String, default: "" },
|
|
7
|
-
timestamp: { type: String, default: "" },
|
|
8
|
-
platformId: {
|
|
9
|
-
type: Schema.Types.ObjectId,
|
|
10
|
-
ref: "Integration",
|
|
11
|
-
default: null,
|
|
12
|
-
},
|
|
13
|
-
workspaceId: {
|
|
14
|
-
type: Schema.Types.ObjectId,
|
|
15
|
-
ref: "Workspace",
|
|
16
|
-
default: null,
|
|
17
|
-
},
|
|
18
|
-
profileId: {
|
|
19
|
-
type: Schema.Types.ObjectId,
|
|
20
|
-
ref: "CustomerProfile",
|
|
21
|
-
default: null,
|
|
22
|
-
},
|
|
23
|
-
body: {},
|
|
24
|
-
},
|
|
25
|
-
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
module.exports = mongoose.model("CustomerTimeline", CustomerTimelineSchema);
|