@peopl-health/nexus 2.2.3 → 2.2.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.
@@ -18,6 +18,55 @@ const checkTemplateSupport = () => {
18
18
  };
19
19
  const { handleApiError } = require('../utils/errorHandler');
20
20
 
21
+ // Checks if a label is valid (non-null, non-undefined, non-empty string)
22
+ const isValidLabel = (label) => {
23
+ return label !== null &&
24
+ label !== undefined &&
25
+ typeof label === 'string' &&
26
+ label.trim() !== '';
27
+ };
28
+
29
+ // Generates a label for a layout item based on available fields
30
+ const generateLabel = (item, index) => {
31
+ if (item.name && typeof item.name === 'string' && item.name.trim() !== '') {
32
+ return item.name.trim();
33
+ }
34
+ if (item.type && typeof item.type === 'string') {
35
+ return `${item.type}_${index + 1}`;
36
+ }
37
+ return `element_${index + 1}`;
38
+ };
39
+
40
+ // Ensures all layout elements have a valid label
41
+ const ensureLabels = (pages) => {
42
+ if (!Array.isArray(pages)) {
43
+ return pages;
44
+ }
45
+
46
+ return pages.map((page) => {
47
+ if (!page || typeof page !== 'object' || !page.layout || !Array.isArray(page.layout)) {
48
+ return page;
49
+ }
50
+
51
+ const processedLayout = page.layout.map((item, index) => {
52
+ if (!item || typeof item !== 'object') {
53
+ return item;
54
+ }
55
+ if (isValidLabel(item.label)) {
56
+ return { ...item, label: item.label.trim() };
57
+ }
58
+ const newLabel = generateLabel(item, index);
59
+
60
+ if (!isValidLabel(newLabel)) {
61
+ return { ...item, label: `element_${index + 1}` };
62
+ }
63
+
64
+ return { ...item, label: newLabel };
65
+ });
66
+
67
+ return { ...page, layout: processedLayout };
68
+ });
69
+ };
21
70
 
22
71
  const createFlow = async (req, res) => {
23
72
  try {
@@ -35,6 +84,9 @@ const createFlow = async (req, res) => {
35
84
  });
36
85
  }
37
86
 
87
+ // Ensure all layout elements have labels (Twilio requirement)
88
+ const processedPages = ensureLabels(pages);
89
+
38
90
  // Generate unique identifiers for anti-rejection
39
91
  const timestamp = Date.now().toString();
40
92
  const uniqueId = require('uuid').v4().substring(0, 6);
@@ -51,7 +103,7 @@ const createFlow = async (req, res) => {
51
103
  body: body,
52
104
  button_text: buttonText,
53
105
  subtitle: subtitle || null,
54
- pages: pages,
106
+ pages: processedPages,
55
107
  type: flowType
56
108
  }
57
109
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",