@peopl-health/nexus 3.15.3 → 3.15.4

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.
@@ -8,11 +8,12 @@ const { getBug, VALID_SEVERITIES } = require('../models/bugModel');
8
8
 
9
9
  const { addRecord, getRecordByFilter } = require('../services/airtableService');
10
10
 
11
- async function logBugReportToAirtable(reporter, whatsapp_id, description, severity, messageIds = [], server) {
11
+ async function logBugReportToAirtable(reportedBug) {
12
+ const { reporter, whatsapp_id, description, severity, messages, server, bugType, project } = reportedBug;
12
13
  try {
13
14
  let conversation = null;
14
- if (messageIds?.length) {
15
- const msgs = await Message.find({ _id: { $in: messageIds } }).sort({ createdAt: 1 });
15
+ if (messages?.length) {
16
+ const msgs = await Message.find({ _id: { $in: messages } }).sort({ createdAt: 1 });
16
17
  conversation = msgs.map(msg => {
17
18
  const timestamp = new Date(msg.timestamp).toISOString().slice(0, 16).replace('T', ' ');
18
19
  const role = msg.from_me ? 'Assistant' : 'Patient';
@@ -28,13 +29,15 @@ async function logBugReportToAirtable(reporter, whatsapp_id, description, severi
28
29
  logger.warn('Could not find patient in estado_general:', { error: err.message });
29
30
  }
30
31
 
31
- await addRecord(Logging_ID, 'bug_reports', {
32
- reporter, description, severity,
32
+ const bugRecord = await addRecord(Logging_ID, 'bug_reports', {
33
+ reporter, description, severity, bugType,
34
+ ...(project && {...project}),
33
35
  ...(patientId && { patient_id: [patientId] }),
34
36
  ...(conversation && { conversation }),
35
37
  server
36
38
  });
37
39
  logger.debug('Bug report logged to Airtable successfully');
40
+ reportedBug.recordId = bugRecord.id;
38
41
  } catch (error) {
39
42
  logger.error('Error logging bug report to Airtable:', { error: error.message });
40
43
  }
@@ -42,7 +45,7 @@ async function logBugReportToAirtable(reporter, whatsapp_id, description, severi
42
45
 
43
46
  const reportBugController = async (req, res) => {
44
47
  try {
45
- const { reporter, whatsapp_id, description, severity, messages } = req.body;
48
+ const { reporter, whatsapp_id, description, severity, messages, bugType, project } = req.body;
46
49
 
47
50
  if (!reporter) return res.status(400).json({ success: false, error: 'Reporter username is required' });
48
51
  if (!whatsapp_id) return res.status(400).json({ success: false, error: 'WhatsApp ID is required' });
@@ -52,12 +55,23 @@ const reportBugController = async (req, res) => {
52
55
 
53
56
  const server = runtimeConfig.get('SERVICE_NAME');
54
57
 
55
- const Bug = getBug();
56
- const bug = await Bug.create({ reporter, whatsapp_id, description, severity, messages: messages || [] , server});
58
+ const reportedBug = {
59
+ reporter, whatsapp_id, description, severity,
60
+ messages: messages || [],
61
+ server,
62
+ recordId: null,
63
+ bugType: bugType || 'other',
64
+ ...(project && { project })
65
+ };
57
66
 
58
- logBugReportToAirtable(reporter, whatsapp_id, description, severity, messages, server).catch(err =>
59
- logger.error('Background bug report logging failed:', { error: err.message })
60
- );
67
+ try {
68
+ await logBugReportToAirtable(reportedBug);
69
+ } catch (error) {
70
+ logger.error('Error logging bug report to Airtable:', { error: error.message });
71
+ }
72
+
73
+ const Bug = getBug();
74
+ const bug = await Bug.create(reportedBug);
61
75
 
62
76
  res.status(201).json({ success: true, message: 'Bug report submitted successfully', bug });
63
77
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "3.15.3",
3
+ "version": "3.15.4",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",