powr-sdk-api 2.5.0 → 2.5.2

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.
@@ -64,10 +64,16 @@ router.get('/conversations', async (req, res) => {
64
64
  isOnline: false // Simple implementation - could be enhanced later
65
65
  };
66
66
  }));
67
- res.success('Conversations fetched successfully', 200, conversationsWithUsers);
67
+ return res.json({
68
+ success: true,
69
+ data: conversationsWithUsers
70
+ });
68
71
  } catch (error) {
69
72
  console.error('Error fetching conversations:', error);
70
- res.error('Failed to fetch conversations', 500, error);
73
+ return res.status(500).json({
74
+ success: false,
75
+ message: "Failed to fetch conversations."
76
+ });
71
77
  }
72
78
  });
73
79
 
@@ -115,10 +121,16 @@ router.get('/conversations/:conversationId/messages', async (req, res) => {
115
121
  timestamp: msg.createdAt,
116
122
  isOwn: msg.senderId === userId
117
123
  }));
118
- res.success('Messages fetched successfully', 200, messagesWithOwnership);
124
+ return res.json({
125
+ success: true,
126
+ data: messagesWithOwnership
127
+ });
119
128
  } catch (error) {
120
129
  console.error('Error fetching messages:', error);
121
- res.error('Failed to fetch messages', 500, error);
130
+ return res.status(500).json({
131
+ success: false,
132
+ message: "Failed to fetch messages."
133
+ });
122
134
  }
123
135
  });
124
136
 
@@ -134,7 +146,10 @@ router.post('/conversations/:conversationId/messages', async (req, res) => {
134
146
  const userId = req.user.powrId;
135
147
  const projectId = req.projectId;
136
148
  if (!content || content.trim() === '') {
137
- return res.error('Message content is required', 400);
149
+ return res.status(400).json({
150
+ success: false,
151
+ message: "Message content is required"
152
+ });
138
153
  }
139
154
  const db = await getDb();
140
155
 
@@ -145,7 +160,10 @@ router.post('/conversations/:conversationId/messages', async (req, res) => {
145
160
  projectId: projectId
146
161
  });
147
162
  if (!conversation) {
148
- return res.error('Conversation not found', 404);
163
+ return res.status(404).json({
164
+ success: false,
165
+ message: "Conversation not found"
166
+ });
149
167
  }
150
168
 
151
169
  // Get current user's name from database
@@ -182,10 +200,16 @@ router.post('/conversations/:conversationId/messages', async (req, res) => {
182
200
  timestamp: message.createdAt,
183
201
  isOwn: true
184
202
  };
185
- res.success('Message sent successfully', 201, responseMessage);
203
+ return res.status(201).json({
204
+ success: true,
205
+ data: responseMessage
206
+ });
186
207
  } catch (error) {
187
208
  console.error('Error sending message:', error);
188
- res.error('Failed to send message', 500, error);
209
+ return res.status(500).json({
210
+ success: false,
211
+ message: "Failed to send message."
212
+ });
189
213
  }
190
214
  });
191
215
 
@@ -199,7 +223,10 @@ router.post('/conversations', async (req, res) => {
199
223
  const userAccess = req.user.access;
200
224
  const projectId = req.projectId;
201
225
  if (!participantId) {
202
- return res.error('Participant ID is required', 400);
226
+ return res.status(400).json({
227
+ success: false,
228
+ message: "Participant ID is required"
229
+ });
203
230
  }
204
231
  const db = await getDb();
205
232
 
@@ -212,7 +239,10 @@ router.post('/conversations', async (req, res) => {
212
239
  }
213
240
  });
214
241
  if (!participant) {
215
- return res.error('Participant not found', 404);
242
+ return res.status(404).json({
243
+ success: false,
244
+ message: "Participant not found"
245
+ });
216
246
  }
217
247
 
218
248
  // Validate access permissions
@@ -228,7 +258,10 @@ router.post('/conversations', async (req, res) => {
228
258
  hasPermission = participant.access === 100 || participant.access === null;
229
259
  }
230
260
  if (!hasPermission) {
231
- return res.error('You do not have permission to chat with this user', 403);
261
+ return res.status(403).json({
262
+ success: false,
263
+ message: "You do not have permission to chat with this user"
264
+ });
232
265
  }
233
266
 
234
267
  // Check if conversation already exists
@@ -239,9 +272,12 @@ router.post('/conversations', async (req, res) => {
239
272
  projectId: projectId
240
273
  });
241
274
  if (existingConversation) {
242
- return res.success('Conversation already exists', 200, {
243
- id: existingConversation._id.toString(),
244
- message: 'Conversation already exists'
275
+ return res.json({
276
+ success: true,
277
+ data: {
278
+ id: existingConversation._id.toString(),
279
+ message: 'Conversation already exists'
280
+ }
245
281
  });
246
282
  }
247
283
  const conversation = {
@@ -251,13 +287,19 @@ router.post('/conversations', async (req, res) => {
251
287
  updatedAt: new Date()
252
288
  };
253
289
  const result = await db.collection('conversations').insertOne(conversation);
254
- res.success('Conversation created successfully', 201, {
255
- id: result.insertedId.toString(),
256
- message: 'Conversation created successfully'
290
+ return res.status(201).json({
291
+ success: true,
292
+ data: {
293
+ id: result.insertedId.toString(),
294
+ message: 'Conversation created successfully'
295
+ }
257
296
  });
258
297
  } catch (error) {
259
298
  console.error('Error creating conversation:', error);
260
- res.error('Failed to create conversation', 500, error);
299
+ return res.status(500).json({
300
+ success: false,
301
+ message: "Failed to create conversation."
302
+ });
261
303
  }
262
304
  });
263
305
 
@@ -323,10 +365,16 @@ router.get('/users', async (req, res) => {
323
365
  access: user.access
324
366
  }));
325
367
  console.log('Available users for chat:', formattedUsers);
326
- res.success('Users fetched successfully', 200, formattedUsers);
368
+ return res.json({
369
+ success: true,
370
+ data: formattedUsers
371
+ });
327
372
  } catch (error) {
328
373
  console.error('Error fetching users:', error);
329
- res.error('Failed to fetch users', 500, error);
374
+ return res.status(500).json({
375
+ success: false,
376
+ message: "Failed to fetch users."
377
+ });
330
378
  }
331
379
  });
332
380
  module.exports = router;
@@ -4,6 +4,9 @@ const express = require('express');
4
4
  const {
5
5
  injectProjectId
6
6
  } = require('../middleware/projectId');
7
+ const {
8
+ verifyToken
9
+ } = require('../middleware/jwtToken');
7
10
 
8
11
  // Import all route modules
9
12
  const commentsRoutes = require('./comments');
@@ -39,8 +42,8 @@ const createPowrRoutes = (options = {}) => {
39
42
  router.use('/auth', authRoutes);
40
43
  router.use('/slides', slidesRoutes);
41
44
  router.use('/notifications', notificationsRoutes);
42
- router.use('/profiles', profilesRoutes);
43
- router.use('/chat', chatRoutes);
45
+ router.use('/profiles', verifyToken, profilesRoutes);
46
+ router.use('/chat', verifyToken, chatRoutes);
44
47
  return router;
45
48
  };
46
49
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powr-sdk-api",
3
- "version": "2.5.0",
3
+ "version": "2.5.2",
4
4
  "description": "Shared API core library for PowrStack projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",